Troubleshooting

Codex gateway API acceptance and troubleshooting

Spend 20 minutes checking the Codex custom model provider's configuration priorities, API Keys, Responses paths, streaming events, tool calls, context compression, and 401, 404, 429, 5xx.

Updated on 2026-07-15Checked 2026-07-15Estimated reading time: 14 minutesAvailable for Codex CLI custom model providers and Responses API compatible APIs
Configuration fields were checked against public documentation. Models, prices, and capabilities can change; verify current values in the console and live API responses.

Let me conclude first: Codex displays a custom model and can answer one sentence, but it does not mean that the gateway API is suitable for the code agent. At least confirm that the current process actually loads the target Provider, and verify the Responses path, continuous streaming events, tool calls, file writeback, context compression, and session recovery respectively.

This article starts from V2EX Codex node and openai/codex Categorize the public help in GitHub Issues, and then use the official OpenAI configuration, certification, and Responses API documents to correct the solution steps. Forum views and replies only reflect community attention.Not equivalent to search volume, probability of failure, or proof of product capability

Eight types of recurring problems in the community

question common phenomenon Levels to check
Configuration does not take effect After writing Provider, the original address is still requested. Configuration file location, priority, Profile,CODEX_HOME
Authentication method confusion ChatGPT logged in but 3rd party request 401 Login status, Provider's env_key, current terminal environment
Protocol or path mismatch 404、/v1/v1/responses, HTML error page Base URL, Responses entry, redirection
Normal conversation succeeds but tool fails 400. Tool parameters are lost and stuck after execution. Responses tool events, tool result return, event sequence
Streaming response interrupted stream disconnected, still stuck after trying again SSE, proxy buffering, idle timeout,response.completed
Context compression failed /compact Or automatically compress and report parameters, models, and timeout errors Compressed requests, field compatibility, routing models and long connections
Session exception after switching accounts The history list is different and old sessions cannot be continued. Login identity, provider, client surface and local state
Token and cost cannot be explained Usage spikes, caching or billing difficulties to reconcile Context, tool loops, retries, usage and console logging

These are problem classifications and do not necessarily mean that a service is faulty. In particular, an output style change, a 5xx, or a compression failure alone do not prove that the model was replaced.

First distinguish between surface, authentication, configuration and protocol

1. Codex is not the same operating environment

Available features, certification requirements, and configuration acceptance scope for Codex CLI, IDE, desktop apps, cloud tasks, and automation may vary. Prioritize acceptance of this article Custom model provider for Codex CLI. After the CLI is run through, the provider, model, and tool capabilities must still be individually confirmed on the target surface, and the CLI results cannot be directly extrapolated to the app or cloud tasks.

2. ChatGPT login does not mean that the third-party Provider has been authenticated

codex login status Used to view the current login method of Codex; custom Provider can be used to env_key Read your own credentials from environment variables. The two belong to different levels. If ChatGPT is logged in, it cannot prove that the third-party API Key has been loaded; if a third-party Key is set, functions that rely on the ChatGPT workspace will not be automatically obtained.

3. Provider cannot be placed in the project configuration and expected to be overwritten.

The official configuration priorities from high to low include: CLI parameters, trusted project configuration, Profile, user configuration, system configuration and built-in default values. But for security reasons, project-level .codex/config.toml cannot be rewritten model_providermodel_providers and provider authentication and other redirection configurations.

Custom Provider should be placed at user level ~/.codex/config.toml. The current official Profile method uses independent ~/.codex/名称.config.toml file and pass --profile 名称 Select. Inline from old tutorial [profiles.名称] The writing may no longer be read by the current version.

4. This article accepts the Responses path

Current official custom Provider example usage wire_api = "responses". When Base URL is https://www.aifast.club/v1 , the regular final request address should be https://www.aifast.club/v1/responses, instead of /v1/v1/responses. Relay services must correctly handle Responses requests, streaming events, and tool results and cannot be successfully replaced with one-shot text from Chat Completions.

This article uses the HTTPS/SSE path of Responses as the basic acceptance. If the Provider explicitly configures and supports WebSocket, the WebSocket handshake, event integrity, and HTTPS fallback should also be independently verified; passing one transport method does not automatically prove that the other one also passed. Other local or specific Provider paths may be different and current Codex and service provider documentation should prevail.

Complete eight acceptance checks in 20 minutes

Create a temporary repository without customer code and use a separate low-limit key. Do not test a third-party provider for the first time in a production repository.

1. Record version, certification and diagnostic information

codex --version
codex login status
codex doctor

codex doctor Inspect installation, configuration, authentication, runtime, Git, and thread details. Before sharing diagnostics, redact API keys, user paths, repository names, internal domains, tokens, and session content.

2. Confirm that the Key takes effect on the same terminal

test -n "$AIFAST_API_KEY" && echo "AIFAST_API_KEY Already set" || echo "AIFAST_API_KEY not set"

Don't execute echo "$AIFAST_API_KEY", and do not send screenshots of complete environment variables to the forum or customer service group.

3. Use independent Profile to switch Provider

Provider is defined in ~/.codex/config.toml

[model_providers.aifast]
name = "AIQuick stop"
base_url = "https://www.aifast.club/v1"
env_key = "AIFAST_API_KEY"
wire_api = "responses"

aifast is a custom Provider ID. Do not name your custom Provider as Codex reserved openaiollama or lmstudio, and don't try to use [model_providers.openai] Override the built-in Provider.

create ~/.codex/aifast.config.toml, write only the selections that need to be overwritten:

model = "YOUR_REAL_MODEL_ID"
model_provider = "aifast"

Model ID, Responses support status, and open scope are dynamic information. Before use, you should refer to the console, service provider documentation and actual API. Do not use the example name directly as an available model.

Start and check:

codex --strict-config --profile aifast

--strict-config It will directly report an error when the current version cannot recognize the configuration field, which is suitable for first-time acceptance; it can be used after the configuration is passed. codex --profile aifast Start normally.

Run after entering /status, confirm the active model, permissions, and working directory./status The final requesting host cannot be proven alone; Provider selection should also be combined with codex doctor Check the desensitization results, startup configuration and server request logs. If the result is different from Profile, check whether there are higher priority CLI parameters, project configuration or different CODEX_HOME

4. First isolate and verify the Responses endpoint

Under the premise that the target model currently explicitly supports the Responses API, first bypass the Codex client and send the minimum request:

curl --fail-with-body --silent --show-error \
  https://www.aifast.club/v1/responses \
  -H "Authorization: Bearer $AIFAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_REAL_MODEL_ID",
    "input": "Reply only RESPONSES_OK"
  }'

If this step succeeds but the Codex still fails, check the Codex configuration and Agent events first. If this step also fails, deal with the API, model permissions or protocol support according to the status code first, and do not continue to adjust the Codex prompt words. If the service provider's current document stipulates different dedicated Responses addresses, the service provider's document shall prevail.

5. Minimal read-only tasks

Only read the current directory README,Do not modify files。Return file title、Number of first-level titles and three abstracts。

Passing criteria: The content is consistent with the file; no modifications have been made; the request log shows the target Provider, target model, and expected Responses path.

6. Real Tools and File Writeback

Enter in the temporary branch:

New codex-gateway-check.txt,Just write one line CODEX_GATEWAY_OK;Read file confirmation,then show git diff。Do not modify other files。

Passing criteria: Tool calling, file writing, reading and result reporting are all completed;git diff Only expected files. Plain text answers are not a substitute for toolchain acceptance.

7. Streaming events and session recovery

Have Codex perform a small task that results in multiple paragraphs of instructions and at least one tool call. The content should continue to appear, the tool should still be able to progress to the next round after it is completed, and eventually end normally. Then exit the current session and use the normal recovery entry to continue a read-only issue.

If the stream comes after the tool call,response.completed Previous interruption may result in incomplete tool results, retry exceptions, or thread failure to recover. At this time, save the status code, request ID, last event type and occurrence time, and do not immediately repeat the command with side effects in the original session.

8. Graded test context compression

First read 1 file, then expand to 5 related files, and finally test the module level task. Run in test session /compact, recording success and the final path, model, status code, and error text in the request log.

Compression may expose fields, model routing and long connection issues that are not triggered by ordinary short requests. There have been additional compression requests or model mappings in community posts, but these implementations will change with versions and service providers; you should refer to your own real-time logs and not copy the fixed model names in the posts.

Locate 401, 404, 429, 5xx and compression errors according to the phenomenon

phenomenon Priority check Don't do anything first
Profile is not effective Profile file name,--profile, configure priority,CODEX_HOME Write Provider repeatedly in the project configuration
Provider ID conflict Whether misused openaiollamalmstudio Wait to keep the ID Try overriding the built-in Provider
Still requesting official address codex doctor, startup configuration, final request host, higher priority parameters Just rely on /status Infer Provider
401 env_key, environment variables, Key status, authentication header, startup terminal Send the complete key to others
403 Model permissions, Key permissions, source restrictions, service policies The default is judged to be a client bug.
404 Final URL, whether it is repeated /v1, whether it truly supports Responses Try your luck by changing models repeatedly
400 / unknown parameter Whether the service supports this field, client and gateway versions, error text Masking protocol incompatibility with retries
429 Balance, quota, concurrency, backoff and Retry-After Unlimited concurrent retries
502 / 504 Upstream status, proxy timeout, request body size, streaming buffer Judgment of stability based on only one failure
Stuck after calling tool Tool events, result return, event sequence, end event Only increase the total timeout
/compact failed Final request, compressed fields, routing model, idle timeout Hardcoded mapping by forum old model
Failed to restore session Whether the last flow has ended completely, whether the tool results have been placed on disk, and the client version Edit local state database directly

When an error is encountered, use the smallest read-only task to reproduce it first. 401, 404, and confirmed 400 configuration errors should generally not be retried automatically; 429, partial 5xx, and brief outages are appropriate for a limited number of retries with backoff. Utility calls with side effects must first confirm idempotence.

How to deal with configuration failure and account switching

Checking in the following order is usually faster than deleting the configuration or reinstalling:

  1. run codex --version, confirm that the current call is not another old installation.
  2. run codex doctor, confirm the actual CODEX_HOME and configuration location.
  3. Check if the Provider is in the user configuration, not the project .codex/config.toml
  4. Check that custom Provider IDs are not using built-in reserved names.
  5. Use codex --strict-config --profile aifast Check for unknown fields and old configurations.
  6. Clear the unnecessary ones for this startup --model or -c Override parameters.
  7. Start Codex from the same terminal where you set up the Key.
  8. use /status Check the model and permissions, and then confirm the final host from the request log.

The official ChatGPT login and custom providers can serve different workflows, but don't assume that the models, cloud functions, automations, and session lists under the two identities are exactly the same. Complete the current task and save it before switching git diff, open a new session for verification, and do not directly modify Codex’s SQLite, JSONL or authentication files based on forum remedies.

Save the evidence and choose Next

Test date:____________________
Codex version:__________________
use surface:CLI / IDE / App / Others
Activities Profile:_______________
Activities Provider:______________
request model / response model:________
Base URL(Desensitization):____________
final request URL(Desensitization):_________
Transmission method:SSE / WebSocket / Others

[ ] /status Consistent with target configuration
[ ] /v1/responses Minimum request passed
[ ] Minimal read-only task passed
[ ] Responses Streaming events pass
[ ] Tool call and file writeback pass
[ ] Session resume passed
[ ] /compact Passed placement test
[ ] usage Verifiable with bill

HTTP status code:_________________
Request ID:_____________________
last event type:_______________
Minimal recurrence and error text:_________
Retest time and results:______________

Select the entrance based on the current stage:

"OpenAI Compatible" does not automatically derive full compatibility with Codex-required Responses, streaming tool events, compression, and session recovery. Each competency should leave verifiable evidence.

Source checked

Reference and Check Sources

Next step

Check the model and price first, then create an independent test Key

The model ID, open status and price will change; it will be added to production after passing small-scale verification.

Model PricingCreate Account View API documentation