Anthropic Agent SDK
Using OpenRouter with the Anthropic Agent SDK
The Anthropic Agent SDK 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:
TypeScript Example
Install the SDK:
Create an agent that uses OpenRouter:
Python Example
Install the SDK:
Create an agent that uses OpenRouter:
Tip: The Agent SDK inherits all the same model override capabilities as Claude Code. You can use ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, and other environment variables to route your agent to different models on OpenRouter. See the Claude Code integration guide for more details.