OpenAI and Anthropic SDKs
Point the official OpenAI or Anthropic SDK at AudioLab by changing its base URL and key.
OpenAI SDK
Set the base URL to https://api.tryaudiolab.ai/v1 and use a workspace key with llm.write access. Chat Completions, Responses, embeddings, and speech work through the SDK's own methods. AudioLab routing fields go in the request body, and the extra response fields usage.cost and routing are kept:
import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.AUDIOLAB_API_KEY, baseURL: "https://api.tryaudiolab.ai/v1" });
const completion = await client.chat.completions.create({
model: "openai/gpt-5.5",
messages: [{ role: "user", content: "Say hello." }],
max_tokens: 64,
models: ["openai/gpt-5.4-nano"],
provider: { sort: "price" },
});
console.log(completion.choices[0].message.content);
console.log(completion.usage.cost, completion.routing.model);
const stream = await client.chat.completions.create({
model: "openai/gpt-5.5",
messages: [{ role: "user", content: "Say hello." }],
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");In TypeScript, routing fields are not in the OpenAI SDK's types; pass them from JavaScript or cast the request. Read the x-audiolab-routing header with .withResponse() (Node.js) or .with_raw_response (Python).
Anthropic SDK
Set the base URL to https://api.tryaudiolab.ai, without /v1, because the SDK adds /v1/messages itself. The SDK sends the key as x-api-key, which AudioLab accepts:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: process.env.AUDIOLAB_API_KEY, baseURL: "https://api.tryaudiolab.ai" });
const message = await client.messages.create({
model: "openai/gpt-5.5",
max_tokens: 64,
messages: [{ role: "user", content: "Say hello." }],
});
console.log(message.content[0].text, message.usage.cost);
const stream = client.messages.stream({
model: "openai/gpt-5.5",
max_tokens: 64,
messages: [{ role: "user", content: "Say hello." }],
});
stream.on("text", (text) => process.stdout.write(text));
await stream.finalMessage();Any model works through Messages, not only Anthropic models. client.messages.countTokens() (count_tokens() in Python) is also supported.
What Differs
Both SDKs raise their own error classes. The AudioLab error code is in error.code for OpenAI and in the error body for Anthropic; see Errors and Debugging. Each protocol supports a subset of its provider's features, listed in Choose a Client Protocol. For typed routing fields, audio, and media endpoints, use the AudioLab SDKs.