Skip to content
All use cases

OpenAI SDKSDKs

Keep the OpenAI SDK, change two fields

Override baseURL and apiKey. Model ids are owner/model strings across 406+ models.

Set it up

OpenAI SDK
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://anyrouter.dev/api/v1",
  apiKey: process.env.ANYROUTER_API_KEY,
})

const res = await client.chat.completions.create({
  model: "anyrouter/free",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
})
console.log(res.choices[0]?.message.content)
  1. 1.Keep openai installed.
  2. 2.Set baseURL to https://anyrouter.dev/api/v1 and apiKey to your sk-ar key.
  3. 3.Use model "anyrouter/free" or "anyrouter/auto" for the first call.
Why use this

The official openai package looks vendor-locked. It is not — it only needs a compatible base URL.

Endpoints and key
OpenAI-compatible
https://anyrouter.dev/api/v1
Anthropic-compatible
https://anyrouter.dev/api
Key
ANYROUTER_API_KEY (sk-ar-…)
Watch the walkthrough