TypeScript SDK
Install and configure the official TypeScript client.
On this page
The official caedral npm package is a TypeScript/JavaScript client for the API gateway. Authenticate with apiKey (cd_live_…). Chat completions may include an optional notre field (mode off|auto, telemetry). Notre Runtime is included on every plan and applied on eligible POST /v1/chat/completions when the platform runs Notre — it does not run on embeddings, rerank, voice, or images. Install with npm install caedral — repository: github.com/trycaedral/caedral (directory sdk).
Installation
npm install caedralInitialization
import { Caedral } from "caedral"; const caedral = new Caedral({ apiKey: process.env.CAEDRAL_API_KEY!, // cd_live_...// baseURL: "http://localhost:5001", // local gateway});| Option | Default | Description |
|---|---|---|
| apiKey | — | Required. Your cd_live_... API key |
| baseURL | https://api.caedral.com | API gateway base URL |
| maxRetries | 3 | Retries for idempotent GET requests only |
| timeout | 120000 | Request timeout in milliseconds |
| fetch | global fetch | Custom fetch implementation |
caedral.chat.completions.create(params)
Create a chat completion. Pass stream: true to receive AsyncIterable<ChatCompletionChunk>.
const completion = await caedral.chat.completions.create({ model: "anthropic/claude-sonnet-4.5", messages: [ { role: "system", content: "You are a helpful assistant." }, { role: "user", content: "Explain quantum computing briefly." }, ], temperature: 0.7, max_tokens: 500,}); console.log(completion.choices[0]?.message.content);console.log(completion.usage?.total_tokens);Streaming
const stream = await caedral.chat.completions.create({ model: "anthropic/claude-haiku-4.5", messages: [{ role: "user", content: "Write a haiku about code." }], stream: true,}); for await (const chunk of stream) { const text = chunk.choices[0]?.delta?.content; if (text) process.stdout.write(text);}caedral.models.list()
const { data: models } = await caedral.models.list();for (const model of models) { console.log(model.id, model.name, model.is_free ? "free tier" : "paid");}caedral.usage.get()
const usage = await caedral.usage.get();console.log("Account status:", usage.accountStatus);console.log("External pool used:", usage.pools.external.percentUsed, "%");caedral.embeddings.create(params)
const result = await caedral.embeddings.create({ model: "caedral-embed", input: ["Caedral routes frontier models through one API"],});console.log(result.data[0]?.embedding.length);caedral.images.generate(params)
const result = await caedral.images.generate({ model: "caedral-vision", prompt: "A minimalist logo for an AI company", n: 1,});console.log(result.data[0]?.url);caedral.audio.generate(params)
const result = await caedral.audio.generate({ model: "caedral-voice", input: "Welcome to Caedral.", voice: "alloy",});console.log(result.choices?.[0]?.message);caedral.rerank.create(params)
const result = await caedral.rerank.create({ model: "caedral-rerank", query: "How does billing work?", documents: ["Subscription pools power the API.", "Usage draws from included monthly quota."], top_n: 2,});console.log(result.results);Exported types
import type { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, EmbeddingCreateParams, ImageGenerateParams, AudioGenerateParams, RerankCreateParams, ModelListResponse, UsageSummary,} from "caedral";Errors
The SDK throws CaedralAPIError with type, statusCode, and message matching the gateway error envelope. Network failures throw CaedralNetworkError.