Node SDK
@anthropic-ai/sdk is the recommended client. OpenAI's official package also works with a baseURL override.
Install
bash
npm i @anthropic-ai/sdk
# or
npm i openai
# pnpm / yarn / bun all work too:
# pnpm add @anthropic-ai/sdk
# bun add @anthropic-ai/sdkTypeScript
ts
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.API_AI_KEY!,
baseURL: "https://api-ai.app",
});
const msg = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Say hi." }],
});
if (msg.content[0].type === "text") {
console.log(msg.content[0].text);
}Streaming via async iterator
ts
const stream = client.messages.stream({
model: "claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "stream me a poem" }],
});
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}Edge runtimes
Works in Vercel Edge and Cloudflare Workers out of the box. The SDK uses the native fetch available in both runtimes.
ts
// Cloudflare Worker
export default {
async fetch(req: Request, env: Env) {
const client = new Anthropic({ apiKey: env.API_AI_KEY, baseURL: "https://api-ai.app" });
const msg = await client.messages.create({
model: "claude-haiku-4-5",
max_tokens: 256,
messages: [{ role: "user", content: "ping" }],
});
return Response.json(msg);
},
};Never ship the key to the browser
Even in a Worker, route requests through your own backend if user data is involved — the API-AI key authorizes spend, not just access.
Last updated: October 2, 2026Found a bug? admin@minedom-france.fr