OpenAI SDK (JS) with idapt
Found this helpful? Share it:
Found this helpful? Share it:
Set up OpenAI SDK (JS) against idapt's compatible APIs with the steps below. This article and the AI Gateway quickstarts lander render the same shared steps, so they never drift.
OpenAI SDK (JS) with idapt
The canonical three-line diff: baseURL, key, model id.
npm i openaiimport OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://idapt.app/api/openai/v1",
apiKey: process.env.IDAPT_API_KEY,
});
const reply = await client.chat.completions.create({
model: "deepseek/deepseek-v4-flash",
messages: [{ role: "user", content: "Three facts about ravens." }],
});const stream = await client.chat.completions.create({
model: "deepseek/deepseek-v4-flash",
messages: [{ role: "user", content: "Stream a haiku." }],
stream: true,
});
for await (const part of stream) {
process.stdout.write(part.choices[0]?.delta?.content ?? "");
}Related articles
API keys and scopes
Create a key, choose its scopes, pin it to an API version, rotate it, and cap what it can spend.
Rate limits and errors
Every error shape the API returns, what each rate limit is, and how to handle a wall in code.
Cap what an API key spends
Give every Gateway API key a lifetime, monthly, or daily USD cap, and what a capped-out key returns.
OpenAI-compatible API
Use idapt's 200+ models from any app that speaks the OpenAI API format.
OpenAI SDK (Python) with idapt
Point the official OpenAI Python SDK at idapt's compatible API with base_url and run any catalog model unchanged.
Vercel AI SDK with idapt
Use the Vercel AI SDK with idapt's OpenAI-compatible API: provider setup, streaming, and tool calls with one base-URL swap.
curl with idapt
curl examples for idapt's three compatible APIs: OpenAI chat completions, Anthropic messages, and OpenRouter completions with one key.
Was this helpful?