JavaScript SDK
The official JavaScript/TypeScript SDK for INK provides a type-safe way to integrate AI content generation into your applications.
Installation
npm install @inkai/sdk
Or with yarn:
yarn add @inkai/sdk
Quick Start
import { InkAI } from '@inkai/sdk'
const ink = new InkAI({
apiKey: process.env.INK_API_KEY
})
const response = await ink.generate({
prompt: 'Write a product description for a smart watch',
template: 'marketing-copy'
})
console.log(response.content)
Configuration
Options
interface InkAIConfig {
apiKey: string
baseUrl?: string
timeout?: number
retries?: number
debug?: boolean
}
Environment Variables
INK_API_KEY=your_api_key
INK_BASE_URL=https://api.inkai.ph/v1
INK_TIMEOUT=30000
Methods
generate()
Generate content from a prompt:
const response = await ink.generate({
prompt: string,
template?: string,
options?: {
tone?: 'professional' | 'casual' | 'formal',
length?: 'short' | 'medium' | 'detailed',
language?: string
}
})
refine()
Refine existing content:
const response = await ink.refine({
content: string,
instructions: string,
preserveStyle?: boolean
})
templates.list()
Get available templates:
const templates = await ink.templates.list()
Streaming
For long-form content, use streaming:
const stream = await ink.generate({
prompt: 'Write a detailed market analysis...',
stream: true
})
for await (const chunk of stream) {
process.stdout.write(chunk.content)
}
Error Handling
import { InkAI, InkError } from '@inkai/sdk'
try {
const response = await ink.generate({ prompt: '...' })
} catch (error) {
if (error instanceof InkError) {
console.log('Code:', error.code)
console.log('Message:', error.message)
console.log('Status:', error.status)
}
}
TypeScript Support
Full TypeScript support with exported types:
import type {
GenerateRequest,
GenerateResponse,
Template,
InkError
} from '@inkai/sdk'
Next Steps
- Review Examples
- Check Rate Limits
- Explore Integrations