Prerequisite: Complete the quickstart to create an access key.
See Google provider setup to configure Google routing or bring your own Google key.
https://gateway.ngrok.ai, use API version v1beta, and authenticate with your ngrok access key.
Google models also work through OpenAI-compatible Chat Completions.
See the OpenAI SDK guide to use your existing OpenAI client with a Google model name.
The OpenAI Responses API (
/v1/responses) doesn’t reach Google models.Installation
Basic usage
SetNGROK_AI_GATEWAY_KEY to your ngrok access key, then send a GenerateContent request:
Streaming
Use the SDK’s streaming method to print text as it arrives:Interactions
Sendmodel and input to create a stateless interaction.
Set store=false explicitly:
store=true and sends every valid request to Google with store=false, even if you omit store or set it to null.
Both ngrok.ai inference and bring your own key (BYOK) requests have these restrictions:
- Stored conversation chaining (
previous_interaction_id) and background execution (background=true) are unsupported. - Interaction retrieval, deletion, cancellation, and stream resumption are unsupported.
- Agents, environments, webhooks, and triggers are unsupported.
Managed Interactions through ngrok.ai inference supports text input and text or structured JSON output only.
Use the Standard tier: omit
service_tier or set it to standard.
The gemini-3.1-pro-preview and gemini-3.1-pro-preview-customtools models require BYOK for Interactions because they use context-band pricing.
With BYOK, supported input and output formats and service tiers depend on Google and the selected model.Authentication
Use your ngrok access key to authenticate requests to the gateway. The gateway checks credentials in this order:Authorization: Bearer <NGROK_AI_GATEWAY_KEY>X-Api-Key: <NGROK_AI_GATEWAY_KEY>X-Goog-Api-Key: <NGROK_AI_GATEWAY_KEY>, which the Google SDK sets fromapi_keyin Python orapiKeyin TypeScript.
key fills an empty X-Goog-Api-Key header.
It doesn’t override a header credential.
Prefer headers to keep credentials out of URLs.
Your access key identifies your gateway configuration.
A Google provider key is a separate credential stored in the gateway.
For BYOK, attach the stored Google key to your configuration; continue to send your ngrok access key from the client.
The gateway replaces client credentials with the selected Google provider credential before forwarding the request.
Supported endpoints
The gateway supports these native Gemini endpoints:Generate content requests
Point a Gemini client athttps://gateway.ngrok.ai and send your access key as described in Authentication.
Use POST /v1beta/models/{model}:generateContent for a JSON response.
For streaming, use POST /v1beta/models/{model}:streamGenerateContent?alt=sse.
The alt=sse query parameter is required.
Ngrok-AIG-Request-Id on every response, Ngrok-AIG-Attempts once the upstream attempt loop runs, and Ngrok-AIG-Model on success.
See Response headers.
Interactions requests
SendPOST /v1beta/interactions with model and input in the request body.
The REST base URL is https://gateway.ngrok.ai/v1beta/.
Omit stream or set it to false for a JSON response.
Set stream=true for server-sent events (SSE).
Responses use Google’s native Interactions format and include the gateway response headers.