ngrok's AI gateway now supports Anthropic's SDK natively.
When we launched early access, the gateway only spoke OpenAI's API format. That works if you're on the OpenAI SDK, but early users building with Anthropic's SDK told us switching wasn't an option, especially when they rely on Claude-specific features like prompt caching, extended thinking, or beta headers.
So we fixed it.
When using the Anthropic SDK, change your base URL to your gateway endpoint:
import anthropic
client = anthropic.Anthropic(
base_url="https://your-gateway.ngrok.app",
api_key="your-api-key"
)
message = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)The gateway automatically detects Anthropic SDK requests and forwards them unchanged. When Anthropic ships new features, you can use them immediately. The same approach works in TypeScript; see our Anthropic SDK docs for examples.
Everything else you'd expect from the gateway still works: automatic failover
across API keys, model selection with ngrok/auto, streaming, tool use, and
Traffic Policy.
Anthropic SDK requests can only route to providers that support the Claude Messages API. In our catalog, that's currently just Anthropic. If you need cross-provider failover, you can either use both SDKs in your codebase or stick with the OpenAI SDK alone.
If you're already on the AI Gateway, change the base URL and you're set. New to ngrok.ai? Check out our quickstart guide.
Questions or feedback? Find us on Discord.