Skip to main content
The @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
Client credentials authentication is intended for backend / server-side applications only. Never expose your clientSecret in frontend code. For browser apps, use bearer tokens, PKCE, or a proxy.
Create a single CortiClient instance and reuse it throughout your application. The SDK handles token refresh automatically — there is no need to re-initialize for each request.

Authentication

The SDK supports five authentication methods to cover different deployment scenarios:
Client Credentials is the recommended authentication method. Your backend should handle all data access checks and never expose the service-account token or client secret to the browser. The other flows (Authorization Code, PKCE, ROPC) are primarily intended for Embedded Assistant use cases where end-user login is required.
Each method is covered in detail in the Authentication Guide.

Usage examples

Create an interaction

JavaScript
See the full request specification in the API Reference.

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
See the full Proxy Guide for implementation details and examples.

Error handling

The SDK throws typed exceptions you can catch and inspect:

TypeScript types

All request and response types are exported as TypeScript interfaces under the Corti namespace:

Advanced configuration

Retries

The SDK automatically retries on 408, 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 an AbortSignal:

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 own fetch 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:
Supported types:
  • Stream types: fs.ReadStream, stream.Readable, ReadableStream
  • Buffered types: Buffer, Blob, File, ArrayBuffer, ArrayBufferView, Uint8Array
You can also attach metadata:

Logging

The SDK supports configurable logging:

Runtime compatibility

The SDK works in the following runtimes:
  • Node.js 18+
  • Vercel
  • Cloudflare Workers
  • Deno v1.25+
  • Bun 1.0+
  • React Native

Resources


For support or questions, contact us