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.
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.
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.
Next playbooks
- Run Claude Code through AnyRouterInstall 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.
- One AI SDK provider for the whole catalogInstall @anyr/ai-sdk-provider. generateText and streamText take a catalog id — including anyrouter/free.
- Keep the OpenAI SDK, change two fieldsOverride baseURL and apiKey. Model ids are owner/model strings across 271+ models.