Skip to main content
Prerequisite: Complete the Quickstart to get an access key. All requests go to https://gateway.ngrok.ai.
The AI Gateway is compatible with Anthropic’s official SDKs. Set the base URL to 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.'

Open in Cursor
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'

Open in Cursor

Model failover

Specify fallback models in the request body. See Configure fallback models.
When using Anthropic SDKs with the gateway, model selection is limited to providers that support the Anthropic Claude API. Currently in the ngrok model catalog Anthropic is the only provider that supports this format.

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:

Next steps