Gemini API supports text, image, audio, video, and other multimodal inputs, and its pricing is relatively friendly. But access to Google services from mainland China, quota limits, and payment methods remain common barriers.

A Gemini API relay consolidates this access and billing into a gateway. This article explains how to choose one, how to connect, and how to test.

Note: Gemini and Google are trademarks of their respective owners. This article is for technical discussion only; prices and interfaces are subject to the official provider or the site.

1. What a Gemini API relay is

your app → relay gateway → Google Gemini

You still call Gemini models; only the base URL and key change to the gateway's. The gateway handles authentication, billing, logging, and channel switching.

2. Who it suits

  • Teams whose access to Google from mainland China is unstable.
  • Applications that need multimodal input such as images, video, or audio.
  • Teams that need unified billing, members, and quotas.
  • Teams using Gemini, Claude, GPT, and DeepSeek at the same time.
  • Teams that need to switch models quickly for A/B tests.

3. Selection criteria

Criterion What to confirm
Model coverage Whether Pro, Flash, and other versions are available
Multimodal Whether image, video, and audio input are supported
Protocol Whether OpenAI compatibility is complete and streaming/tool calling work
Reliability Error rate, P95, rate limits
Billing How input, output, and multimodal input are priced
Quotas Key, member, and project limits
Compliance Data retention, contracts, invoices

Multimodal support deserves special attention. A gateway may handle text perfectly while supporting only a subset of image or video formats, or imposing stricter size limits than the official API.

Also check how image and video inputs are counted toward tokens. A gateway that accepts a file but bills it differently from the official API can change your unit economics, especially for document-heavy or media-heavy applications.

4. Configuration

Base URL:

https://ai.zhongshangqihang.com/v1

curl:

export GEMINI_API_KEY="sk-你的密钥"

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": "只回复 OK"}]
  }'

Model names are subject to model pricing.

5. How to use multimodal input

Different gateways support multimodal input in different ways. Two common approaches:

  1. URL input: pass an image or video URL in the messages array.
  2. Base64 input: encode the file and include it in the request.

Before use, confirm which fields the gateway supports and what size limits apply. Do not copy the official SDK format blindly. Test with a small image first, then move to production.

6. Test checklist

  1. Text requests.
  2. Streaming output.
  3. Image input.
  4. Long context.
  5. 5 and 10 concurrent requests.
  6. 429/5xx handling.
  7. Bill reconciliation.

Test several file sizes, not just one thumbnail. A gateway may accept a small image and reject a larger scan or a short video, and those limits are easier to discover before launch than in production.

7. Common errors

Symptom Cause Fix
Connection timeout Cannot reach Google Use a gateway reachable from mainland China
401 Key and URL do not match Check the key and base URL
404 Wrong path Use only up to /v1
429 Quota or rate limit Lower concurrency, retry, or raise the quota
Multimodal error Unsupported field or size Check the gateway documentation and test with a small file

8. Official direct access vs a relay

Dimension Official direct Relay gateway
Access Affected by network conditions Reachable from mainland China
Payment Official methods Top-up on the site
Models Gemini only Multiple models
Billing Official console Unified console
Multimodal Full official capabilities Depends on gateway support

If you only need Gemini and official access works well, direct access is a reasonable choice. If access from mainland China is unstable or you need multiple models, a relay is a better fit.

A common pattern is hybrid routing: send latency-sensitive text calls through one channel and large multimodal jobs through another, while keeping the same application interface. The gateway should make that switch a configuration change rather than a code change.

Next steps

If you need domestic access or a single entry point for multiple models, sign up for the ZSQH AI Gateway and test both text and multimodal requests with a small key. Models and prices are subject to model pricing.

Related reading: