Prerequisite: Complete the Quickstart to get an access key. All requests go to
https://gateway.ngrok.ai.https://gateway.ngrok.ai and authenticate with your access key.
Anthropic models also work through OpenAI-compatible SDKs (OpenAI SDK, Vercel AI SDK, LangChain, etc.)—just use the model name directly, for example
model: "claude-opus-4-6". You don’t need the Anthropic SDK to access Anthropic models.Installation
Basic usage
Point the SDK at your AI Gateway endpoint:Try using this prompt on your agent to verify your Anthropic SDK connection: 'State your exact model name and provider.'
The Anthropic SDK sends the API key via the
x-api-key header. Access keys work with both x-api-key and Authorization: Bearer headers.Streaming
The AI Gateway supports streaming responses with the Anthropic SDK:Try using this prompt on your agent to test streaming — tokens should appear one by one: 'Write a haiku about APIs'
Model failover
Specify fallback models in the request body. See Configure fallback models.Tool use
Tool calling works as documented by Anthropic:Error handling
The gateway handles many errors automatically through failover. For errors that reach your app:Supported endpoints
The AI Gateway supports these Anthropic Claude API endpoints:| Endpoint | Description |
|---|---|
/v1/messages | Messages |
Next steps
- Choose a model: Model IDs and provider prefixes
- Configure fallback models: Try another model when the first one fails
- Choose how to reach providers: Credits, provider keys, and self-run models