Skip to content
All use cases
Agent SDK

Run the Claude Agent SDK on any model

query() already reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Point both at AnyRouter — no SDK fork.

01

The problem

What this is for

The Agent SDK is built for Anthropic's /messages API. Teams still want GPT, GLM, Llama, or a failover preset without rewriting the loop.

02

What to do

Three steps, then copy

  1. 1.Install @anthropic-ai/claude-agent-sdk.
  2. 2.Set ANTHROPIC_BASE_URL to https://anyrouter.dev/api and ANTHROPIC_API_KEY to your sk-ar key.
  3. 3.Pass model: "anyrouter/auto" (or any catalog id) in query() options.
query()
ts
import { query } from "@anthropic-ai/claude-agent-sdk"

for await (const message of query({
  prompt: "List the files here and summarize the project.",
  options: {
    model: "anyrouter/auto",
    env: {
      ...process.env,
      ANTHROPIC_BASE_URL: "https://anyrouter.dev/api",
      ANTHROPIC_API_KEY: process.env.ANYROUTER_API_KEY ?? "",
    },
  },
})) {
  if (message.type === "result") console.log(message.result)
}

Ready to try it

The guide has the full walkthrough. Sign up if you still need a key.