# 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.

- Date: July 19, 2026
- Category: guides
- HTML: https://anyrouter.dev/blog/claude-agent-sdk-any-model

## 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.

### TypeScript

```bash
npm install @anthropic-ai/claude-agent-sdk
```

```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: {
    // 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)
}
```

### Python

```bash
pip install claude-agent-sdk
```

```python
import asyncio, os
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage

os.environ.setdefault("ANTHROPIC_BASE_URL", "https://anyrouter.dev/api")
os.environ.setdefault("ANTHROPIC_API_KEY", "sk-ar-v1-placeholder")

async def main():
    options = ClaudeAgentOptions(
        # any catalog id: "openai/gpt-5.5", "z-ai/glm-5.2", "anthropic/claude-opus-4-8"
        model="z-ai/glm-5.2",
    )
    async for message in query(prompt="List the files here and summarize the project.", options=options):
        if isinstance(message, ResultMessage):
            print(message.result)

asyncio.run(main())
```

## 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](https://dash.anyrouter.dev/keys)
