SDK API Reference
SDK API Reference
Complete reference for all SDK methods.
UserSDK Class
Constructor
new UserSDK(config: UserSDKConfig)Parameters:
config.apiKey(string, required) - ZIRI API key (must start withziri-)config.proxyUrl(string | URL, optional) - ZIRI server URL (defaults toZIRI_PROXY_URLenv var orhttp://localhost:3100)config.timeoutMs(number, optional) - Request timeout in milliseconds (default:30000)config.fetch(function, optional) - Custom fetch implementation (defaults to globalfetch)
Throws: Error if API key format is invalid
Methods
chatCompletions
Make a chat completion request.
chatCompletions(params: {
provider: string
model: string
messages: Array<{ role: string; content: string }>
ipAddress?: string
context?: Record<string, any>
[key: string]: any
}): Promise<any>Parameters:
provider(string, required) - Provider name (e.g., “openai”)model(string, required) - Model name (e.g., “gpt-4o-mini”)messages(array, required) - Conversation messagesipAddress(string, optional) - Client IP addresscontext(object, optional) - Additional context- Other parameters passed through to provider
embeddings
Generate text embeddings.
embeddings(params: {
provider: string
model: string
input: string | string[] | Array<string | number[]>
[key: string]: any
}): Promise<any>Parameters:
provider(string, required)model(string, required)input(string | string[] | number[][], required)- Other parameters passed through to provider
images
Generate images.
images(params: {
provider: string
model: string
prompt: string
n?: number
size?: string
quality?: string
response_format?: 'url' | 'b64_json'
[key: string]: any
}): Promise<any>Parameters:
provider(string, required)model(string, required)prompt(string, required)n,size,quality,response_formatoptional
getUserId
Get the user ID extracted from the API key.
getUserId(): stringError Handling
All methods throw errors on failure:
try {
const response = await sdk.chatCompletions({ ... })
} catch (error) {
// error.message contains the error message
}Common error messages:
Request failed: 403 Authorization denied- Policy denied the requestRequest failed: 429 Rate limit exceeded- Rate limit hitRequest failed: 400 Invalid API key format- API key invalid
Type Definitions
interface UserSDKConfig {
apiKey: string;
proxyUrl?: string | URL;
timeoutMs?: number;
fetch?: typeof fetch;
}