Connect Gemini API to the OpenAI SDK.

Set Google’s OpenAI-compatible base URL, list account-available Gemini model IDs, and keep the Google key separate from ChinaGenAI’s site key.

Google documents an OpenAI-compatible interface for the Gemini API. It lets OpenAI SDK clients use a Gemini API key and Google's API base URL. This is a direct Google API connection; it is separate from ChinaGenAI's own endpoint and site key.

Use Google's endpoint and your Gemini key

API base URL
https://generativelanguage.googleapis.com/v1beta/openai/

Keep the /v1beta/openai/ path. The client appends the Chat Completions route.

API key
Your Google AI Studio Gemini API key

Use a local environment variable or the client's secret store; do not commit it to a project file.

Model ID
Use a model returned by your account's model list

Google's current compatibility example uses gemini-3.8-flash. Confirm the exact ID and access in your account.

API route
POST /chat/completions

Most SDK clients add this route when you provide the base URL.

Check the model IDs before configuring an app

Model names and account access can change. Use Google's OpenAI-compatible /models endpoint and copy the exact returned ID into the app. This Python example lists IDs without generating a completion:

List available Gemini model IDs
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["GEMINI_API_KEY"],
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
)

for model in client.models.list():
    print(model.id)

Configure an OpenAI-compatible client

  1. Choose the client's custom OpenAI-compatible provider setting.
  2. Enter Google's base URL above, then select the Gemini API key from a local secret field or environment variable.
  3. Paste a model ID returned by the model list. If the client asks for a complete URL instead of a base URL, follow that client's field instructions and check that it targets /chat/completions.
  4. Send a short request only when you are ready to make a Gemini API call. Check the Google account's current quota and billing first.

For a minimal OpenAI SDK request, Google's documentation currently shows the following model ID. Replace it if your model list or account exposes a different compatible ID:

OpenAI SDK Chat Completions request
from openai import OpenAI

client = OpenAI(
    api_key="GEMINI_API_KEY",
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
)

response = client.chat.completions.create(
    model="gemini-3.8-flash",
    messages=[{"role": "user", "content": "Reply with one short sentence."}],
)
print(response.choices[0].message.content)

Know what compatibility means

Google labels OpenAI library support as beta. Compatibility makes the Chat Completions request shape familiar; it does not guarantee that every OpenAI parameter, Gemini feature or third-party client is supported. Google recommends its own SDK when you need Gemini-specific capabilities such as the File API or Google Search grounding.

  • 401: check that the key is a Gemini API key for the intended Google project.
  • 404 or model error: list models again and copy the exact model ID available to that account.
  • 429: check the project's current quota, rate limits and billing state before retrying.

Keep the two API routes separate

This guide uses Google's Gemini API base URL and a Google API key. If you instead want ChinaGenAI's provider-agnostic site route, use the current access state and values on the ChinaGenAI connection page; do not enter a Google key there or substitute Google's endpoint for the site endpoint.

Official Google references

Google's compatibility and partner documentation checked 21 October 2026. These instructions follow the published docs; no Google account, Gemini API key or live inference request was used.

Free API access and limits

Check the site free API access and limits before trying to obtain a site key. Read the current status and request limits before using a site key. It is not a source of official provider keys.

ChinaGenAI is not affiliated with the providers named here. This release contains setup guidance and explicitly labeled fictional examples, not claimed live model benchmarks.