Codex · Relay

Codex Relay: Access the Codex API from China

Codex CLI, the VS Code extension, and the desktop app all support custom model providers. Point base_url at AICodeWith, put your Key in auth.json, and you can use Codex directly from networks in China. It is billed per token from your prepaid balance, with no ChatGPT plan required.

Last checked

How Codex Relay Works

By default, Codex uses a ChatGPT account login or an OpenAI API Key. It also lets you declare a model_provider in config.toml: Codex sends requests to that provider's base_url and authenticates with the Key in auth.json. The relay provides a compatible interface, so Codex itself does not need to be modified.

This approach is billed by API usage and does not go through any paid ChatGPT plan.

Setup Steps (CLI, VS Code, Desktop)

  1. 1. Install Codex

    Install @openai/codex from the command line with npm; for the VS Code extension and desktop app, see the download page.

    Terminal
    npm install -g @openai/codex
  2. 2. Get a Key

    Create a Key on the API Keys page in the AICodeWith console.

  3. 3. Write auth.json

    Put the Key in ~/.codex/auth.json (on Windows: %USERPROFILE%\.codex\auth.json).

    ~/.codex/auth.json
    {
      "OPENAI_API_KEY": "你的_API_KEY"
    }
  4. 4. Write config.toml and restart

    Write config.toml using the example in the next section, then restart the terminal, VS Code, or the desktop app. All three read the same ~/.codex directory.

Codex Download (CLI / Desktop / VS Code)auth.json Reference

config.toml Example

~/.codex/config.toml
model_provider = "codex"
model = "gpt-5.6-sol"

[model_providers.codex]
name = "codex"
base_url = "https://api.aicodewith.ai/chatgpt/v1"
wire_api = "responses"
requires_openai_auth = true
supports_websockets = false

model can be changed to any other Codex-compatible model listed on the models page. Save the file and reopen Codex for the change to take effect.

Full config.toml Reference

Pricing and Billing

Input and output tokens are deducted from your prepaid balance based on actual usage, and per-request usage is visible in the console. The balance is valid for 12 months and is not reset monthly. Real-time prices per model are listed on the models page.

OpenAI Models and PricingTop Up and Plans

How to Choose a Relay Provider

  • Whether the relay supports the responses API Codex requires (wire_api = "responses"); relays that do not support it will return an error right away.
  • Whether billing is transparent: can you see per-request token usage, and can you set a spend limit on each Key?
  • Whether it stays stable during peak hours and whether you can switch between multiple channels.
  • Whether there is a clear refund policy. AICodeWith: unused balance can be refunded within 90 days, minus a 10% processing fee. See the refund policy for details.

Common Errors

ErrorCommon CauseResolution
401 UnauthorizedThe Key in auth.json is incorrect or has extra spaces, or an old OPENAI_API_KEY is still present in environment variablesRe-copy the Key, check environment variables, then restart Codex
429 Too Many RequestsConcurrency or the request rate is too high, or your balance/spend limit is insufficientReduce concurrency, retry later, and check the balance and the Key's spend limit
Connection timeoutbase_url is incorrect or a local proxy is interferingCheck base_url, temporarily disable the proxy, and try again

Codex 401 TroubleshootingCodex 429 Troubleshooting

FAQ

How do I use a Codex relay?

Create a Key in the console, put it in ~/.codex/auth.json, set the base_url for model_provider in ~/.codex/config.toml to AICodeWith, and restart Codex.

Can I use a Key other than a ChatGPT account key?

Yes. Codex supports custom model providers; you can use a relay API Key instead, no ChatGPT account or paid plan required.

What models are supported?

It supports the GPT-series models that Codex can use. For the exact list and real-time prices, see the OpenAI models page; switch via the model field in config.toml.

What should I do if I get 401 / 429?

401 usually means the Key is wrong or an old environment variable remains; re-copy the Key and restart. 429 means too much concurrency or an insufficient balance/limit; reduce concurrency and check your balance.

How do I purchase credit?

After registering, top up or buy a prepaid plan on the top-up page using local payment methods in China. You are billed based on usage, and the balance is valid for 12 months without monthly reset.

Ready to try it?

Billing is per token from a prepaid balance. Rate and concurrency limits apply, and you can set daily, monthly or total spend caps on each API key.

Related

AICodeWith is an independent third-party API service and is not affiliated with Anthropic or OpenAI. Claude, Claude Code, Codex and similar names belong to their respective owners. Prices are subject to real-time data on the models page; rate and concurrency limits apply; refunds are subject to a 10% processing fee. See the refund policy for details.