Check out the newest way to compare different models for a task/agent harness: AutoEvals
Model providers

Gateway

Google Gemini

Route direct Gemini API calls through the Inference platform using native Gemini endpoints.

Route direct Gemini API calls through Inference Gateway to get request observability, latency tracking, and persisted request and response payloads. This guide covers Google's Gemini API at generativelanguage.googleapis.com, not Vertex AI.

Use the native Gemini paths when you want Google's generateContent and streamGenerateContent request format:

Gemini API operationInference platform path
Non-streaming generation/v1beta/models/{model}:generateContent
Streaming generation/v1beta/models/{model}:streamGenerateContent

The gateway defaults these paths to the gemini provider. You can still set x-inference-provider: gemini explicitly to make routing obvious.

Looking for Gemini through Google Cloud Vertex AI instead? Use the Vertex AI guide.

Setup

Get your API keys

You need two keys:

Set environment variables

export INFERENCE_API_KEY=<your-project-api-key>
export GEMINI_API_KEY=<your-gemini-api-key>
export GEMINI_MODEL=gemini-3-flash-preview

Use the Google Gen AI SDK

The Google Gen AI SDK can point at Inference Gateway with httpOptions.baseUrl. The SDK sends your Gemini key as x-goog-api-key; Inference platform forwards that header downstream and uses Authorization for your Inference platform project key.

Use cURL for raw Gemini paths

Raw HTTP callers can pass the Gemini key as x-inference-provider-api-key. Inference platform converts that to x-goog-api-key when forwarding to Gemini.

Headers

HeaderRequiredDescription
AuthorizationYesBearer <your-project-api-key> authenticates the request to the Inference platform and links telemetry to your project.
x-inference-providerNoSet to gemini to make routing explicit. Native Gemini paths default to Gemini when omitted.
x-inference-provider-api-keyYes for cURLYour Gemini API key. Inference platform forwards it to Gemini as x-goog-api-key.
x-inference-environmentNoTags requests with an environment, such as production or staging.
x-inference-task-idNoGroups requests under a logical task for filtering and analytics.

Supported paths

Inference platform currently supports the direct Gemini generation paths:

  • /v1beta/models/{model}:generateContent
  • /v1beta/models/{model}:streamGenerateContent
  • /v1/models/{model}:generateContent
  • /v1/models/{model}:streamGenerateContent

Other Gemini API paths should be called directly until they are explicitly supported by the gateway.

OpenAI-compatible endpoint

If you would rather use the OpenAI request format (for example, to reuse an existing OpenAI SDK setup), Gemini exposes an OpenAI-compatible surface at https://generativelanguage.googleapis.com/v1beta/openai. Inference platform can route to it by combining the OpenAI-format path with a provider URL override:

HeaderValue
x-inference-providergemini
x-inference-provider-urlhttps://generativelanguage.googleapis.com/v1beta/openai
x-inference-provider-api-keyYour Gemini API key. Inference platform forwards it as Authorization: Bearer <key> because the OpenAI-compat endpoint requires bearer auth.
cURL
curl "https://api.inference.net/v1/chat/completions" \
  -H "Authorization: Bearer ${INFERENCE_API_KEY}" \
  -H "Content-Type: application/json" \
  -H "x-inference-provider: gemini" \
  -H "x-inference-provider-url: https://generativelanguage.googleapis.com/v1beta/openai" \
  -H "x-inference-provider-api-key: ${GEMINI_API_KEY}" \
  -H "x-inference-environment: production" \
  -H "x-inference-task-id: gemini-openai-compat" \
  -d '{
    "model": "'"${GEMINI_MODEL}"'",
    "messages": [{ "role": "user", "content": "Reply with exactly OK." }],
    "max_completion_tokens": 32,
    "temperature": 0
  }'

The native :generateContent paths above remain the recommended surface — they expose Gemini features (system instructions, thinking traces, response schemas, image inputs) that the OpenAI-compat shim does not pass through.

On this page