Gemini is Google's family of multimodal models, supporting text, image, audio, and video inputs. Many developers get stuck in three places the first time they use the Gemini API: where to create a key, how free quotas work, and how to call the API reliably from China.

This article from ZSQH AI Gateway explains how to obtain and configure a Gemini API Key, make calls, and handle common errors.

This article uses common versions as of October 2026. The Google AI Studio interface and quotas may change; refer to the official console for specifics.

1. What the Gemini API can do

Common uses:

  • Long-document summarization, translation, and rewriting.
  • Image and video understanding and content moderation.
  • Multimodal Q&A, OCR, and table extraction.
  • Code generation and code explanation.
  • Reasoning nodes in agent workflows.

Common Gemini models come in Pro, Flash, and other tiers. Pro is more capable; Flash is faster and cheaper. For specific model names, context lengths, and prices, refer to the model pricing page.

2. Two ways to get a Gemini API Key

Route A: Official key from Google AI Studio

  1. Open Google AI Studio.
  2. Sign in with a Google account.
  3. Go to the API Key page and create a key.
  4. Copy the key and store it in a password manager.
  5. Link a billing account in the project if you need higher quotas.

An official key suits scenarios where you can access Google reliably, need a direct official connection, and have modest usage.

Route B: Get a key through ZSQH Gateway

  1. Open the ZSQH AI Gateway, register, and sign in.
  2. Go to the "API Keys" page and create a new key.
  3. Set a spending limit and expiration time.
  4. Top up your wallet.
  5. Copy the key.

The gateway suits teams with unstable access from China, teams that need unified billing, and teams that use multiple model providers at once.

3. What to put in the Base URL

Official Gemini API

The native Gemini API Base URL is:

https://generativelanguage.googleapis.com

Google also provides an OpenAI-compatible endpoint:

https://generativelanguage.googleapis.com/v1beta/openai/

ZSQH Gateway

When using the OpenAI-compatible interface, set the Base URL to:

https://ai.zhongshangqihang.com/v1

Do not mix them: use the official key with the official endpoint and the gateway key with the gateway endpoint. Mixing them usually returns 401 or 404.

4. curl test

export GEMINI_API_KEY="sk-your-key"

curl "https://ai.zhongshangqihang.com/v1/chat/completions" \
  -H "Authorization: Bearer $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash",
    "messages": [
      {"role": "user", "content": "Explain what a multimodal model is in three sentences"}
    ]
  }'

Model names are subject to what the model pricing page currently shows. If you get model not found, check the model name first rather than suspecting the key.

5. Calling from Python

pip install openai
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["GEMINI_API_KEY"],
    base_url="https://ai.zhongshangqihang.com/v1",
)

response = client.chat.completions.create(
    model="gemini-2.5-flash",
    messages=[
        {"role": "user", "content": "Summarize the key points of this text: " + "..."}
    ],
)

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

If you use Google's official SDK, install google-genai according to the official documentation and use the official endpoint. Do not mix the two approaches.

6. Quotas and rate limits

Gemini quotas are usually calculated by model, project, region, and time window. Common limits include:

  • Requests per minute (RPM).
  • Tokens per minute (TPM).
  • Requests per day (RPD).
  • Different limits for free and paid tiers.

Actual quotas are subject to the Google official console or the gateway console. For production, we recommend:

  1. Set a spending limit on each key.
  2. Use exponential backoff for 429 responses.
  3. Keep a backup model for critical workloads.
  4. Monitor error rate and time to first token.

7. Common access problems in China

Symptom Likely cause What to do
Connection timeout The network cannot reach Google Use an available gateway or proxy
401 Wrong key or mixed Base URL Check that the key and endpoint match
404 Extra or missing /v1 in the path Check the official and gateway endpoints separately
429 Quota or rate limit exceeded Reduce concurrency, retry, or raise the quota
Model unavailable Region or account not enabled Switch models or channels
Truncated output Output or context limit Adjust parameters or split the input

8. How to estimate cost

Gemini cost is usually driven by input tokens, output tokens, and multimodal inputs such as images and video. Estimation steps:

  1. Measure the average input and output tokens per request.
  2. Look up the current model's unit price (subject to model pricing).
  3. Multiply by daily request volume to get daily cost.
  4. Add the extra consumption from retries, caching, and multimodal input.

Do not look only at the "per million tokens" price. Long context and multimodal input are often the biggest cost drivers.

9. Security recommendations

  • Do not put keys in front-end code.
  • One key per person; split keys by project within a team.
  • Set spending limits and expiration times.
  • Rotate keys regularly.
  • Use environment variables or a secrets manager in production.

FAQ

Is the Gemini API Key free to use?

There is usually a free tier, but it has quota and regional restrictions. For long-term or commercial use, use the paid tier; refer to the official policy for specifics.

Can one key call Claude?

Through a gateway, one key can call multiple enabled models, and you specify the model in the request parameters. An official Gemini key can only call Google models.

Why is the same model sometimes slow?

It can be affected by upstream load, regional network conditions, context length, and concurrency. For production, add timeouts, retries, and a backup channel.

Next steps

If you need stable access from China or a single entry point for multiple models, register for the ZSQH AI Gateway, create a test key, verify it with curl, and then connect your application. Models and prices are subject to model pricing.

Related reading: