CheapAI
Blog

Codex 401 with a custom API key: check the host before buying credits

Diagnose invalid_api_key with the request URL, a catalog check and three provider settings. Keep the key out of terminal output and support tickets.

You add credit, paste a key, type “hello” and see 401 Incorrect API key. Start with the URL in the error. If it says api.openai.com/v1/responses, Codex sent the CheapAI key to OpenAI. Adding CheapAI credit cannot change that route.

Check the key outside Codex

Run the command below from the terminal used to launch the client. It reads CHEAPAI_API_KEY from the environment and prints only the HTTP status for the model list. A 200 confirms catalog access. For a 401, check that the variable is set in this session and that the key is active in your dashboard. Keep the key out of support tickets.

curl -sS -o /dev/null -w '%{http_code}\n' \
  -H "Authorization: Bearer ${CHEAPAI_API_KEY:?}" \
  https://cheapai.io/v1/models

Inspect the selected profile

Match three values in the active provider configuration: base_url should be https://cheapai.io/v1, env_key should name CHEAPAI_API_KEY and wire_api should be responses. Restart with that profile. An app opened from a desktop launcher may inherit a different environment from your shell. Check the instance showing the error.

Interpret the next result

After the catalog returns 200, send one short Codex request and inspect its destination. A model_not_found response on the CheapAI host calls for a model ID check. If 401 persists on the correct host, share the UTC time, sanitized URL and request ID with support.

Codex CLI · HTTP 401 / 404

Worked examples