Gemini with the OpenAI SDK: compare the native, compatible and gateway paths

Google exposes an OpenAI-compatible interface for Gemini, and gateways can expose their own compatible routes. The SDK can be shared while base URLs, keys, model IDs, supported fields and billing remain specific to the service.

Published 2026-09-23 · Updated 2026-09-29 · KeepRouter Editorial · 6 minute read

Protocol decision matrix for Responses API and Chat Completions integrations
Verify the operation and required fields for each Gemini access path.

Using an OpenAI SDK with Gemini can reduce the amount of client code you maintain. It does not choose the service that handles the request. Google's own compatibility endpoint and KeepRouter's compatible route have different addresses, credentials, catalogs and billing records. Select the path first, then evaluate the exact features your application needs.

A useful starting workload is a support assistant that reads text, occasionally receives an image, and calls one internal lookup tool. That workload exercises more than a plain greeting while remaining small enough to inspect. The Gemini catalog entry on KeepRouter is one place to check a current route; the model ID in a gateway catalog should not be assumed to match an upstream model namespace or feature set.

Identify which of the three paths you need

PathWhy a developer might choose itWhat must remain service-specific
Google native Gemini APIA feature depends on Google's native request objectsSDK, credentials, model availability and native features
Google OpenAI-compatible endpointExisting OpenAI client code covers the required operationGoogle key, Google base URL and documented compatibility fields
KeepRouter compatible routeOne account and client configuration serves evaluated catalog routesKeepRouter key, public model ID, active endpoint and customer price

Google's OpenAI compatibility documentation lists supported operations and provider-specific extensions. Read the section for the operation you use. Support for a text request does not settle support for an image payload, a particular reasoning option, or a complete tool continuation. Keep these decisions in one small request matrix instead of describing the entire integration as universally compatible.

Configure the client without mixing credentials

This example points only to KeepRouter. Set KEEPROUTER_MODEL to the exact Gemini ID selected from its current catalog. The environment variable prevents the article from silently pinning a retired or unavailable choice. Keep SDK versions recorded in your project lockfile. The key must allow the selected model, and a paid model requires sufficient credit. Funding an account does not expand a free-only key's allowlist.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://keeprouter.com/v1",
    api_key=os.environ["KEEPROUTER_KEY"],
    timeout=30.0,
    max_retries=0,
)
response = client.chat.completions.create(
    model=os.environ["KEEPROUTER_MODEL"],
    messages=[{"role": "user", "content": "Return a short title for a test support ticket."}],
)
print(response.id, response.model)
print(response.usage.model_dump() if response.usage else "usage missing")

For Google's own compatible service, its documentation supplies https://generativelanguage.googleapis.com/v1beta/openai/ and a Google credential. Keep that configuration separate from the gateway profile. Avoid constructing a hybrid configuration with one service's key and another service's URL. When diagnosing authentication, show the destination host and whether a key is set, never the key itself.

The code above is a minimal request template, not a published benchmark. Add an output limit supported by the exact route before running a larger workload. The OpenAI SDK guide and API reference explain the KeepRouter client-facing contract.

Test the fields that change behavior

Build a fixture for each required behavior rather than adding every optional field in the first request.

FixtureSuccess conditionCommon mistaken assumption
TextApplication receives an accepted answerAny 200 response satisfies the task
Image plus questionCorrectly identifies a known image factText support proves vision support
Function callTool arguments parse, result is returned, final answer arrivesA tool definition alone proves continuation
Structured outputOutput passes the application's schema validatorJSON-looking text is schema enforcement
StreamingTerminal state and usage are handledConcatenating text captures every event
Provider extensionThe route documents and honors the fieldAny extra_body key passes through unchanged

Google documents extensions for capabilities that do not have a direct OpenAI field. Treat them as Google-specific contracts. Before carrying one through a gateway, check whether the gateway translates, forwards or rejects it on the selected route. If no contract is published, keep that feature on the native path or perform a bounded compatibility experiment and label the result narrowly.

Keep tool history and multimodal inputs intact

A lookup tool test should include the whole round trip: model chooses the tool, your application validates arguments, the tool returns a harmless result, and the model completes the answer. Record the IDs and message order your SDK sends. If an application strips unfamiliar fields from model messages, it can lose information required by a later turn even when the first answer looked correct.

For image input, use a small image you control and confirm the route's accepted input representation. A remote image URL also depends on fetchability, redirects and expiry; a model error may actually be a transport problem. Keep failures of image retrieval separate from failures of visual interpretation. Video, audio and generated media need their own documented operations and should not be inferred from a model's marketing family name.

Compare cost at the workload level

Use one completed support task as the comparison unit. Record input, cached input, output, retries and any modality-specific units. If the task sends one question and a picture, a character count of the question cannot estimate the complete input cost. For KeepRouter, select the exact catalog model and enter reported usage in the API cost calculator. Calculate a direct-provider bill separately using its own rates; retain additional billing categories outside the tool when they are not represented there.

Run the same small fixture set on the candidate paths before choosing one for production. Keep quality acceptance separate from latency and price. If only one path supports a necessary feature, it is the eligible path regardless of which unrelated text rate is lower. A mixed application can keep a native feature-specific route while using a compatible route for ordinary text tasks.

Record the decision so upgrades stay manageable

Save the SDK version, endpoint family, public model ID, required fields, passing fixtures and date of verification. Use the API migration checklist when any of these changes. The goal is a record another developer can rerun, not a permanent claim that every Gemini model behaves like every OpenAI model.

Use one tool conversation to find a compatibility gap

Choose an inert lookup tool with a small JSON schema. Validate the first tool arguments, return a synthetic tool result with the matching call identifier, and verify the final answer uses it. Compare against Google’s function-calling documentation, while using the destination endpoint’s request shape. This checks a concrete agent interaction without moving real customer data or assuming that native and compatible tool histories are interchangeable.

Current Gemini models on KeepRouter

Nine Gemini chat IDs passed bounded text checks on September 29, 2026. Start with the Gemini model and pricing guide for exact IDs, an OpenAI SDK example and the specific models tested for streaming, JSON and a complete tool conversation. Compare the current model-page rates using your own task and acceptance criteria.

Frequently asked questions

Is Google OpenAI compatibility the same endpoint as KeepRouter?

No. Each service has its own URL, key, catalog and bill. Configure them separately.

Does extra_body guarantee a Gemini feature passes through?

No. Confirm how the selected service handles that extension and test the exact request.

Should I use the native API for every Gemini request?

Use it when the feature requires a native contract. A compatible route can be suitable for separately verified operations.

How should I price an image-and-text request?

Use the reported usage and the chosen service billing units; text character count alone does not cover image input.

Sources reviewed

Article last reviewed 2026-09-29

  1. [1] Google Gemini OpenAI compatibility
  2. [2] Google Gemini function calling
  3. [3] KeepRouter OpenAPI
  4. [4] Google Cloud OpenAI compatibility

Related guides

← All posts · Models & pricing · Get an API key