All use cases
OpenAI SDK
Keep the OpenAI SDK, change two fields
Override baseURL and apiKey. Model ids are owner/model strings across 271+ models.
What this is for
The official openai package looks vendor-locked. It is not — it only needs a compatible base URL.
Steps, then copy
- 1.Keep openai installed.
- 2.Set baseURL to https://anyrouter.dev/api/v1 and apiKey to your sk-ar key.
- 3.Use model "anyrouter/free" or "anyrouter/auto" for the first call.
OpenAI SDK
ts
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)Ready to try it
The guide has the full walkthrough. Sign up if you still need a key.
Next playbooks
- One AI SDK provider for the whole catalogInstall @anyr/ai-sdk-provider. generateText and streamText take a catalog id — including anyrouter/free.
- One API in front of every provider dialectOpenAI /chat/completions, Anthropic /messages, and a Responses API — same key, same catalog.
- Start on anyrouter/free or anyrouter/autoTwo built-in virtual models: free failover on every plan (anyrouter/free) and stable paid failover (anyrouter/auto). Do not pick a flaky SKU for your first request.