When using Codex in China, the most common blockers aren't installation. They're two things: you can't connect (the login page won't open, requests time out) and you can't pay (a ChatGPT subscription and the OpenAI API both require an overseas payment method). This article covers only how to fix those two problems.
For installation steps, see Codex Installation Guide, and for how to set your API Key, see How to Configure a Codex API Key.
First, figure out where you're stuck
| Symptom | Problem type | Which section to read |
|---|---|---|
| Run codex and the login page won't open or just keeps spinning | Network | Network issue |
| It starts, but tasks fail with timeouts, connection resets, or TLS errors | Network | Network issue |
| You have no ChatGPT subscription and can't add a credit card for the OpenAI API | Payment | Payment issue |
| You get 401, 404, or model not found | Configuration, not network | How to Configure a Codex API Key |
A 401 or 404 means the request already reached the server. The problem is the Key or the address, and switching networks won't fix it.
Network issues: why you can't connect
Codex sends requests to OpenAI's official services by default. Signing in with a ChatGPT account also requires opening OpenAI's login page. Most of these addresses can't be reached directly from China, so the usual symptoms are:
- The login page won't open in the browser, or the terminal keeps waiting for the callback after you finish signing in;
- After you submit a task, there's no response for a long time and it eventually times out;
- It works occasionally, then drops again later.
Option 1: Route Codex through a network that can reach OpenAI
If you already have a network setup that reliably reaches OpenAI, make sure that the terminal where you launch Codex is also using it. Being able to open OpenAI in a browser doesn't mean Codex in the terminal goes through the same route. Proxy setup for terminals varies by tool. On a work computer, follow your company's network policy first and don't try to bypass it.
Option 2: Use an API service that's directly reachable from China
If you'd rather not fiddle with networking, you can send Codex's model requests to an API service that's directly reachable in China. Taking AICodeWith as an example, it offers two routes:
- Overseas direct route: relayed through Cloudflare Tunnel, it connects from most regions in China without a proxy, and the platform recommends it first;
- Domestic route: relayed through Alibaba Cloud ESA, it needs no proxy at all. The path is longer and latency may be higher, so treat it as a backup.
Both routes use the same API Key, and quota and usage records are synced. When switching, change only the domain part of the API address and leave the path after it unchanged. For details, see the AICodeWith route selection docs.
Payment issues: what to do without an overseas credit card
Codex has two official ways to pay:
- ChatGPT subscription (Plus, Pro, Business, and so on), where you sign in to Codex with a ChatGPT account;
- OpenAI API pay-as-you-go, where you sign in with an API Key from the OpenAI Platform.
Both require a payment method that works overseas. Domestic bank cards, Alipay, and WeChat can't pay directly.
Users in China can switch to an API platform that accepts payment in RMB. Taking AICodeWith as an example:
- It supports top-ups via Alipay and WeChat, with no overseas credit card needed;
- Billing is based on actual usage, and quota can be shared across the multiple models the platform supports;
- Under the terms of service, top-up quota is valid for 12 months from the last top-up.
For specific pricing, refer to the pricing page; for supported models, see the model list.
Note: a Key from a third-party platform can only be configured according to that platform's integration docs. It can't be used to sign in on OpenAI's website, and ChatGPT subscription quota can't be used as API balance.
Next step: connect Codex to AICodeWith
Once network and payment are sorted, follow the integration guide to finish setup and verify it with a small task:
View the guide to connect Codex to AICodeWith →
If you don't have an account yet, first sign up for AICodeWith →, then follow the API Key creation docs to generate a Key.
FAQ
My browser can open ChatGPT. Why can't Codex connect?
Your browser and terminal have separate network settings. Make sure the terminal where you launch Codex also goes through a network that can reach OpenAI, or switch to an API service that's directly reachable from China.
Do I still need a ChatGPT subscription after switching to a third-party API?
No. With a third-party API, you're billed against that platform's quota, which has nothing to do with a ChatGPT subscription.
What if the overseas direct route won't connect?
Switch to the domestic route first: replace the domain in the API address with the domestic route's domain and keep the path the same. If neither works, contact the platform's technical support.
Is a 401 a network problem?
No. A 401 means the request reached the server but authentication failed, so check your Key. See How to Fix Codex 401 Unauthorized.



