The OpenAI API is the foundation interface for many AI applications, but developers in mainland China face network, payment, quota, and compliance issues when connecting directly. An OpenAI API relay routes access and billing through a gateway layer.

This article explains what a relay is, how to choose one, how to migrate, and the common risks.

Note: OpenAI and ChatGPT 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 an OpenAI API relay is

your app → relay gateway → OpenAI

Your code still uses the OpenAI SDK. You only change the base URL, the key, and the model name. The gateway handles authentication, billing, logging, and routing.

Because the interface remains OpenAI-compatible, most applications can switch without a rewrite. That is also why the choice of provider matters: the gateway becomes part of your production path.

2. What it solves

  • Unstable access from mainland China.
  • Inconvenient payment methods.
  • A need for unified billing and quotas across a team.
  • A need to use Claude, Gemini, and DeepSeek alongside OpenAI.
  • A need for usage logs and error troubleshooting.

3. Selection criteria

Criterion What to confirm
Model coverage Whether the GPT series is complete and versions are current
Compatibility Chat Completions/Responses, streaming, tool calling
Reliability Error rate, P95, rate limits, retries
Billing How input, output, and cached tokens are priced
Quotas Key, member, and project limits
Logs Tokens, latency, and errors for every call
Compliance Data retention, contracts, invoices

4. Migration steps

1. Change the base URL

https://ai.zhongshangqihang.com/v1

2. Switch the key

Create a key in the ZSQH AI Gateway and set a spending limit.

3. Update the model name

Copy the current model name from model pricing. Old model names may already be deprecated.

4. Roll out gradually

Move 5%–10% of traffic first, observe for 3–7 days, and then increase the share.

5. Python example

from openai import OpenAI

client = OpenAI(
    api_key="sk-你的密钥",
    base_url="https://ai.zhongshangqihang.com/v1",
)

resp = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "只回复 OK"}],
)
print(resp.choices[0].message.content)

Keep the key on the server side. Do not embed it in a mobile app or a browser bundle.

6. Test checklist

  1. Standard and streaming requests.
  2. Tool calling and structured output.
  3. Long context.
  4. 5, 10, and 20 concurrent requests.
  5. 401/404/429/5xx error codes.
  6. Bill reconciliation against a fixed set of requests.

Run the same test set against the old and new paths so you can compare quality, latency, and cost directly.

7. Risks and pitfalls

  • A "low-price relay" that supports only some models may become unavailable at any time.
  • Expired model names or unsupported parameters can cause production failures.
  • A leaked key can drain the balance quickly, so spending limits are mandatory.
  • Before enterprise use, confirm data terms, invoicing, and compliance.
  • Do not put all traffic on a single channel; keep a backup.

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 OpenAI only Multiple models
Billing Official console Unified console
Risk Account and payment barriers Choosing the wrong provider

FAQ

Do I need to change code to use a relay?

If you use the OpenAI SDK, usually only the base URL, key, and model name change.

Does a relay affect model quality?

It usually does not change the upstream model, but channel versions, parameters, and rate limits may differ. Compare with a fixed test set before migrating.

Can I build one myself?

Yes. Open-source gateways such as New API and One API can be self-hosted, but you need servers, upstream channels, and operations. See One API and New API guide.

Next steps

If you need stable access from mainland China or a single entry point for multiple models, sign up for the ZSQH AI Gateway and test with a small key. Models and prices are subject to model pricing.

Related reading: