Skip to content
GuidesJuly 19, 2026

Run the Claude Agent SDK on any model

The Claude Agent SDK reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, the same two variables Claude Code uses. Point them at AnyRouter and every catalog model is available to query() behind the Anthropic /messages dialect — in TypeScript or Python.

Two variables, any model

The Claude Agent SDK runs on the same client as Claude Code, so it reads the same connection variables — ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Point them at AnyRouter with an sk-ar-v1 key and query() reaches every model in the catalog behind the Anthropic /messages dialect. Model ids are provider/model strings, so switching models is one option value.

npm install @anthropic-ai/claude-agent-sdk
import { query } from "@anthropic-ai/claude-agent-sdk"

for await (const message of query({
  prompt: "List the files here and summarize the project.",
  options: {
    // any catalog id: "openai/gpt-5.5", "z-ai/glm-5.2", "anthropic/claude-opus-4-8"
    model: "z-ai/glm-5.2",
    env: {
      ...process.env,
      ANTHROPIC_BASE_URL: process.env.ANTHROPIC_BASE_URL ?? "https://anyrouter.dev/api",
      ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? "sk-ar-v1-placeholder",
    },
  },
})) {
  if (message.type === "result") console.log(message.result)
}

Claude Code works the same way

The Agent SDK and the Claude Code CLI share a client, so the same two variables point the CLI at AnyRouter too — no plugin, no fork. For the terminal walkthrough, see /blog/claude-code-through-one-gateway.

Get an sk-ar-v1 key and run the Agent SDK on any model in the catalog.

Create a key

Route your first request in 2 minutes

Start free with your own keys, or top up and pay per token. Get $4/mo in credits and free models on Go — $2/mo, or free when you donate a provider key.

Start free