@corti/sdk package is the official JavaScript SDK for the Corti API. It provides full coverage of every REST endpoint and WebSocket connection, with built-in authentication, automatic token refresh, type safety, and error handling.
Package: @corti/sdk on npm | Source: GitHub | Examples: corti-examples
Prerequisites
- Node.js 18 or later
- npm, yarn, or pnpm
- A Corti API client from the Corti Console
Installation
Initialization
The simplest way to get started is with client credentials (server-side):JavaScript
Authentication
The SDK supports five authentication methods to cover different deployment scenarios:| Method | Environment | Use case |
|---|---|---|
| Client Credentials (recommended) | Backend only | Server-to-server integrations |
| Bearer Token | Frontend & Backend | When you already have a token from another source |
| Authorization Code | Frontend & Backend | Interactive user login (confidential clients) |
| PKCE | Frontend & Backend | Interactive user login (public clients, SPAs) |
| ROPC | Backend only | Username/password for trusted apps |
Usage examples
Create an interaction
JavaScript
Real-time transcription (WebSocket)
JavaScript
Text generation
JavaScript
Proxy support
When you need to route SDK traffic through your own backend (for security or access control), the SDK supports:baseUrl— redirect all REST and WebSocket traffic to your proxy- Custom environment URLs — fine-grained control over REST, WebSocket, auth, and agent endpoints
CortiWebSocketProxyClient— lightweight WebSocket-only proxy client- Scoped tokens — limit token access to specific endpoints
Error handling
The SDK throws typed exceptions you can catch and inspect:| Exception | When it’s thrown |
|---|---|
CortiError | API returned a non-2xx HTTP response (4xx / 5xx) |
CortiSDKError | SDK infrastructure error (e.g. localStorage unavailable) |
ParseError | Input validation failed (e.g. missing PKCE verifier, invalid JWT) |
JsonError | Response body could not be parsed as JSON |
TypeScript types
All request and response types are exported as TypeScript interfaces under theCorti namespace:
Advanced configuration
Retries
The SDK automatically retries on408, 429, and 5xx status codes with exponential backoff. The default retry limit is 2. Override per request:
Timeouts
The SDK defaults to a 60-second timeout. Override per request:Abort requests
Cancel any request using anAbortSignal:
Raw responses
Access the underlying HTTP response alongside parsed data using.withRawResponse():
Pagination
List endpoints are paginated. The SDK provides an async iterator so you can loop over items automatically:Custom fetch client
Supply your ownfetch implementation if you’re running in an unsupported environment or need custom behavior:
Additional headers
Add headers to every request via the constructor, or per request as a request option:Additional query parameters
Add extra query string parameters per request:File uploads
The SDK accepts a variety of types when uploading files:- Stream types:
fs.ReadStream,stream.Readable,ReadableStream - Buffered types:
Buffer,Blob,File,ArrayBuffer,ArrayBufferView,Uint8Array
Logging
The SDK supports configurable logging:| Property | Description | Default |
|---|---|---|
level | Debug, Info, Warn, or Error | Info |
logger | Logger implementation (implements logging.ILogger) | ConsoleLogger |
silent | Whether to silence all logging | true |
Runtime compatibility
The SDK works in the following runtimes:- Node.js 18+
- Vercel
- Cloudflare Workers
- Deno v1.25+
- Bun 1.0+
- React Native
Resources
- npm package — latest version, changelog, and install info
- GitHub source — SDK source code
- Examples repository — working code for authentication, streaming, text generation, and more
- Authentication Guide — all five auth flows with code examples
- Proxy Guide — secure frontend integration patterns
- API Reference — full endpoint specifications
For support or questions, contact us