Skip to main content
The MetrixLLM gateway provides a drop-in proxy for Google’s Generative Language API. Use the Gemini REST API or SDKs by changing only the Base URL and API key.

Base URL

Authentication

All requests require a MetrixLLM API key. The gateway accepts both formats:
Do not use your Google AI API key. The gateway authenticates requests using MetrixLLM keys (sk-metrix-* prefix). The gateway then uses its own provider keys (or your BYOK keys) to call Google.

Internal Authentication

For backend-to-gateway communication, the gateway supports internal authentication: Internal auth skips the standard API key validation. Used by the MetrixLLM backend for playground, replay, and batch operations.

Endpoints

The {model} parameter is extracted from the URL path. Supported models include gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash, and others configured in your workspace.

Request Headers

Every request supports these headers: Session Tracing Use these headers to group related requests into sessions and trace spans: Custom Properties Attach up to 10 custom metadata properties per request: Example: metrix-property-team: engineering, metrix-property-environment: production Worker-to-Gateway These headers are set by the Cloudflare Edge Worker when routing through the Durable Object balance system: IP Detection

Generate Content

URL Format

Examples:
  • /gemini/v1beta/models/gemini-2.5-pro:generateContent
  • /gemini/v1beta/models/gemini-2.5-flash:generateContent
  • /gemini/v1beta/models/gemini-2.0-flash:generateContent

Request Body

Send standard Gemini generateContent requests. The gateway accepts all standard Gemini fields plus MetrixLLM-specific extensions.

Content Format

Each content object represents a turn in the conversation:
Use "model" for assistant turns and "user" for user turns.

System Instruction

Examples

Response Body

Response Headers

Every successful response includes these headers: On cache HIT responses, only Content-Type and X-Metrix-Cache-Status: HIT are returned. On rate limited responses (429 Too Many Requests):

Generation Configuration

Configure generation parameters in the generationConfig object:

Example


Thinking (Extended Thinking)

Enable extended thinking for deeper reasoning. The gateway converts between Gemini’s thinkingConfig and other provider formats automatically.
When using the gateway’s generic proxy (/v1/chat/completions), you can use a simplified thinking field: "low" (2048 tokens), "medium" (10240 tokens), or "high" (20480 tokens). The gateway converts these to the appropriate provider-specific format.

Tool Use

Define tools using Gemini’s native format with functionDeclarations.

Tool Configuration

Control tool selection with toolConfig:
Enable web search to give the model access to real-time information.

Native Web Search Example

Include google_search in your tools array:

Prompt Management

Use prompt_id to reference a stored prompt template via the generic proxy endpoint. The gateway fetches the template, renders {{variable}} placeholders with values from inputs, and sends the rendered messages to the provider.

Error Responses

Errors return a JSON body. The HTTP status code indicates the error type.

Error Response Format


Retry and Fallback

The gateway automatically retries failed requests and falls back to alternative providers:
  • Retry: Retries on 429, 500, 502, 503, 504 status codes with exponential backoff
  • Fallback: If the primary provider fails, the gateway tries the next configured provider in the chain
  • Circuit Breaker: Providers with repeated failures are temporarily skipped (circuit opens for 60 seconds)
  • Cerebras Fallback: If all configured providers fail on system errors, the gateway falls back to Cerebras (if enabled)
These features are transparent to your application — you receive a single successful response.

Mode Override

Control provider key selection with the mode field:

Using with Google SDKs

You can use the Google AI Python SDK with the gateway by setting the base URL: