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.Install @anthropic-ai/claude-agent-sdk.
- 2.Set ANTHROPIC_BASE_URL to https://anyrouter.dev/api and ANTHROPIC_API_KEY to your sk-ar key.
- 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.
Related
Next playbooks
Run Claude Code through AnyRouter
Install the anyr CLI, then anyr claude — it injects the base URL, key, and model. Env vars are the fallback if you already run claude yourself.
OpenOne AI SDK provider for the whole catalog
Install @anyr/ai-sdk-provider. generateText and streamText take a catalog id — including anyrouter/free.
OpenKeep the OpenAI SDK, change two fields
Override baseURL and apiKey. Model ids are owner/model strings across 209+ models.
Open