# Anthropic Agent SDK

> Integrate OpenRouter using the Anthropic Agent SDK. Complete guide for building AI agents with OpenRouter in Python and TypeScript.

The [Anthropic Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview) lets you build AI agents programmatically using Python or TypeScript. Since the Agent SDK uses Claude Code as its runtime, you can connect it to OpenRouter using the same environment variables.

## Configuration

Set the following environment variables before running your agent:

```bash
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY="" # Important: Must be explicitly empty
```

## TypeScript Example

Install the SDK:

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

Create an agent that uses OpenRouter:

```typescript
import { query } from "@anthropic-ai/claude-agent-sdk";

// Environment variables should be set before running:
// ANTHROPIC_BASE_URL=https://openrouter.ai/api
// ANTHROPIC_AUTH_TOKEN=your_openrouter_api_key
// ANTHROPIC_API_KEY=""

async function main() {
  for await (const message of query({
    prompt: "Find and fix the bug in auth.py",
    options: {
      allowedTools: ["Read", "Edit", "Bash"],
    },
  })) {
    if (message.type === "assistant") {
      console.log(message.message.content);
    }
  }
}

main();
```

## Python Example

Install the SDK:

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

Create an agent that uses OpenRouter:

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