Skip to content
All use cases

Agent SDKCoding agents

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.

Set it up

query()
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)
}
  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.
Why use this

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

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