Prerequisite: Complete the Quickstart to create an access key on app.ngrok.ai before continuing.
https://gateway.ngrok.ai/v1 and use your access key.
Installation
Basic usage
Point the SDK at your AI Gateway endpoint and pass your access key asapi_key. See Access keys vs provider keys for how credentials flow through the gateway.
Try using this prompt on your agent to verify your gateway connection: 'State your exact model name and provider.'
Streaming
The AI Gateway supports streaming responses:Try using this prompt on your agent to test streaming — tokens should appear one by one: 'Write a haiku about APIs'
Using different providers
Route to different providers using model prefixes:Model failover
List fallback models in the request:Embeddings
Generate embeddings through the gateway:Function calling
Tool/function calling works exactly as documented by OpenAI:Try using this prompt on your agent to test tool calling — your get_weather function should be invoked: 'What is the current weather in Paris?'
Async usage
Use async clients for better performance:Error handling
The gateway handles many errors automatically through failover. For errors that reach your app:Supported endpoints
The AI Gateway supports these OpenAI API endpoints:| Endpoint | Description |
|---|---|
/v1/chat/completions | Chat completions |
/v1/completions | Legacy completions |
/v1/embeddings | Text embeddings |
/v1/responses | Responses |