Quick Start

Gemini API domestic access tutorial: OpenAI Compatible call and verification

Use AIFast to access Gemini from networks in China, query live model IDs, run curl and Python calls, and verify multimodal and streaming behavior.

Updated on 2026-09-16Verified 2026-09-09Estimated reading time: 9 minutesApplicable to calling Gemini series models through the OpenAI Compatible API
Configuration fields were checked against public documentation. Models, prices, and capabilities can change; verify current values in the console and live API responses.

Bottom line: If the project already uses the OpenAI SDK, you can first call the currently open Gemini model through the OpenAI Compatible entrance of AIFast. The correct order is query /v1/models, copy the real model ID, complete the minimum text request, and then independently verify the image input, streaming output and structuring capabilities.

Direct answer

The shortest Gemini OpenAI-compatible setup is: confirm the Base URL, use the same key to request /v1/models, copy the real Gemini model ID, and complete a short text request. A successful text request proves only that the basic protocol works; it does not prove that images, SSE, tool calls, or native Gemini parameters are compatible.

If you are searching for a Gemini OpenAI-compatible API or how to list Gemini API models, start by using the same key to request /v1/models, then copy the real model ID from data[].id and send a short non-streaming request. A successful model list does not prove that image input, SSE, or tool calls are compatible; verify those capabilities separately.

Can Gemini API use the OpenAI SDK directly?

Yes, but only if the target service explicitly provides the OpenAI Compatible API and the current Gemini model supports the fields you need. The compatible address configuration field for OpenAI SDK is base_url. To query and copy the real model ID, please request /v1/models. Don’t hand over the proprietary parameters of Google’s native Gemini SDK directly to the OpenAI protocol. After the text call is successful, the image input, SSE, tool call and structured output still need to be verified separately.

If you are unsure whether the client automatically appends /v1, please check the final path first, and then record the protocol and streaming capabilities of the current model:

Before you start

Configuration items Recommended value
Base URL https://www.aifast.hk/v1
API Key an independent API key created in the AIFast console
Model /v1/models Gemini model ID returned

Google officially provides OpenAI Compatibility access, but the fields supported by different gateways and models may still be different. Don’t assume that just because a text conversation is successful, all the file, cache, real-time, or multimodal capabilities of the native Gemini API are available.

Step 1: Get the real model ID

export AIFAST_API_KEY="your_API_Key"

curl --fail-with-body --silent --show-error \
  https://www.aifast.hk/v1/models \
  -H "Authorization: Bearer $AIFAST_API_KEY"

returned from data Copy the Gemini model IDs available for the current account in the array. The model name, version, open status and price may all be updated, so it is not recommended to write fixed models in tutorials or business code for a long time.

Step Two: Complete the Minimal Text Request

export MODEL_ID="real copied from model list_ID"

curl --fail-with-body --silent --show-error \
  https://www.aifast.hk/v1/chat/completions \
  -H "Authorization: Bearer $AIFAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL_ID"'",
    "messages": [
      {"role": "user", "content": "Reply with only GEMINI_API_READY"}
    ],
    "temperature": 0
  }'

Check status code,choices, response model、usage and request ID. Save the desensitized original response, which will be more valuable when troubleshooting model routing and billing later.

Step 3: Use the Python SDK

python -m pip install --upgrade openai
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["AIFAST_API_KEY"],
    base_url="https://www.aifast.hk/v1",
)

response = client.chat.completions.create(
    model=os.environ["MODEL_ID"],
    messages=[
        {"role": "user", "content": "Organize the following meeting minutes into to-do items。"}
    ],
)

print(response.choices[0].message.content)

Put the Base URL, Key, and Model ID into the configuration center respectively. This allows you to switch configurations during model maintenance, quota changes, or business rollback without having to modify the code and re-publish it.

How to accept multi-modal capabilities

After the text request is successful, verify each item in business order:

  1. Confirm that the current model explicitly supports image input and is not inferred from the "Gemini" name.
  2. Use a non-private test image to verify the image format, size, and URL or Base64 input method.
  3. Design visual questions with unique answers, such as reading random numbers or comparing table fields.
  4. Log failure status code, error text, input token, and full task cost.
  5. Test single image, multiple image and long text combinations separately, without using one result to represent all scenarios.

If you only need to generate pictures or videos, you should check outImage generation API integrationandVideo generation API access, don't confuse chat models with generated media endpoints.

Flow cytometry and stability verification

Use stream=true and curl -N Check SSE:

curl -N --fail-with-body \
  https://www.aifast.hk/v1/chat/completions \
  -H "Authorization: Bearer $AIFAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL_ID"'",
    "messages": [{"role": "user", "content": "Explain the API acceptance process in five steps"}],
    "stream": true
  }'

Repeat the test at least for different time periods and record the success rate, P50, P95, 429 and 5xx distributions. Don’t treat the single fastest delay as a long-term commitment.

FAQ

model not found

Query again /v1/models and copy the real id. Do not use page titles, model family names, or fixed IDs from old tutorials.

Return HTML instead of JSON

Usually a misconfiguration of the Base URL, path, or reverse proxy. Check if the final URL is entered /v1/models or /v1/chat/completions, and whether it appears /v1/v1.

Image input failed

First confirm whether the model and endpoint support the input type, and then check the MIME type, image size and message structure. The success of text APIs does not prove that multimodality is necessarily compatible.

Output quality fluctuations

Fix the model, parameters and question set for multiple rounds of comparison, and save the response model, token and time. Can be usedModel API comparison templateAvoid drawing conclusions based on one subjective experience.

Next step

Run firstFree model checkingCheck the protocol and basic competencies before readingmodel quality degradation detection methodwithProduction on-line checklist. Black box detection can only provide risk signals, not certification by Google or the model manufacturer.

FAQ

How do you list models from a Gemini OpenAI-compatible API?

Use the target platform's API key to request /v1/models and copy the real id from the returned data array. A card title, Chinese alias, or vendor name cannot directly replace the model ID.

Can Gemini API use the OpenAI SDK directly?

Yes, but only when the target service provides an OpenAI-compatible endpoint and the current model supports the required fields. After a text request succeeds, verify image input, SSE, tool calls, and structured output separately.

What should you do when Gemini API returns model not found?

Use the same key to request /v1/models, copy a real model id visible to the current account, and check whether the Base URL repeats /v1. Do not use a display name or a fixed model from an old tutorial.

Does a Gemini OpenAI-compatible endpoint support every native Gemini capability?

Not necessarily. OpenAI-compatible endpoints usually define only part of the request structure. Verify files, caching, realtime, multimodal input, and tool calls at the current endpoint instead of inferring support from the model name.

Source checked

Reference and Check Sources

Next step

Test the current API before fixing, migrating, or creating a test key

Use a temporary, limited key to inspect model declarations, token fields, SSE, and tool calls. Review current models and pricing only when you need a replacement API.

Model Quality CheckModel PricingCreate Account