Skip to content
All use cases
OpenAI SDK

Keep the OpenAI SDK, change two fields

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

01

The problem

What this is for

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

02

What to do

Three steps, then copy

  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.
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.