DEV Community

Wenhao Ma
Wenhao Ma

Posted on

Codex CLI custom provider: fixing "unexpected status 404 Not Found" and "wire_api = chat is no longer supported"

Recent Codex CLI versions speak one wire protocol: the Responses API (wire_api = "chat" has been removed). If you point it at a third-party gateway and the first prompt fails, it is almost always one of three things: the base_url is missing /v1, an old wire_api = "chat" line is still in your config, or the profile you defined is no longer being read. This post walks through all three with a working config. I use HZAPI (HZ AI) as the example gateway because I maintain it, but the config shape is the same for any gateway that serves POST /v1/responses.

Every key below is a placeholder (sk-xxxx). Put your real key in an environment variable, never in a repo.

The error messages, matched to causes

What Codex prints Cause Fix
unexpected status 404 Not Found: ... url: https://api.hzapi.vip/responses base_url has no /v1; Codex appends /responses to whatever you wrote base_url = "https://api.hzapi.vip/v1"
unexpected status 404 Not Found: ... url: https://.../v1/responses/responses You pasted the full endpoint into base_url End base_url at /v1
`wire_api = "chat"` is no longer supported Old blog-post config; Codex stops at config load and sends no request Set wire_api = "responses" or delete the line
unexpected status 401 Unauthorized The key reached the gateway but was not accepted: truncated, wrong group, or a key from another site Re-copy the key; check requires_openai_auth (below)
Missing environment variable: HZAPI_API_KEY env_key names a variable that is empty in the shell that started Codex export HZAPI_API_KEY=... in that shell
Profile settings seem ignored Newer Codex versions read profiles from a separate file (below) Move the settings to ~/.codex/<name>.config.toml

The url: at the end of a 404 is the most useful part of the message. It shows exactly what Codex called. Compare it with the URL you expect.

Why /v1 matters here

Codex builds the request URL itself: it takes base_url, trims a trailing slash and appends responses. So:

base_url you wrote URL Codex calls Result
https://api.hzapi.vip https://api.hzapi.vip/responses 404
https://api.hzapi.vip/v1 https://api.hzapi.vip/v1/responses correct
https://api.hzapi.vip/v1/responses .../v1/responses/responses 404

This is the opposite of Claude Code, which wants the root address without /v1. HZ AI's official guide has a table of which client takes which address: guide, section 02.

Step 1: test the endpoint without Codex

Separate "gateway problem" from "Codex config problem" with one curl:

export HZAPI_API_KEY="sk-xxxx"

# free: lists the models this key can use
curl -sS https://api.hzapi.vip/v1/models -H "Authorization: Bearer $HZAPI_API_KEY"

# the call Codex will make (this one is a real, billed request)
curl -sS -w '\n%{http_code}\n' https://api.hzapi.vip/v1/responses \
  -H "Authorization: Bearer $HZAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-6.2-astra","input":"Reply with: ok"}'
Enter fullscreen mode Exit fullscreen mode
  • A JSON answer means the gateway speaks Responses and the key works.
  • 404 means that path does not exist on that host. Check the host and /v1.
  • 401 means the key is wrong or not accepted.
  • A model error means the model is not in your key's group. On HZAPI a key is bound to one group, so take the model ID from the /v1/models call above, not from a blog post. gpt-6.2-astra is the example from HZ AI's own guide.

Step 2: write the provider block

~/.codex/config.toml (on Windows %USERPROFILE%\.codex\config.toml):

model = "gpt-6.2-astra"          # an ID from your /v1/models call
model_provider = "hzapi"

[model_providers.hzapi]
name = "HZ AI"
base_url = "https://api.hzapi.vip/v1"
env_key = "HZAPI_API_KEY"
wire_api = "responses"            # the only supported value; you can also omit the line
requires_openai_auth = false
Enter fullscreen mode Exit fullscreen mode

Two details that cause silent mistakes:

  1. TOML table scope. Everything after a [model_providers.hzapi] header belongs to that table. model = ... and model_provider = ... must sit above the first [...] header, or Codex reads them as provider fields and ignores them.
  2. Two credential paths. With requires_openai_auth = true, Codex uses the OpenAI-style login and ignores env_key. For a gateway key you want false plus env_key. HZ AI's guide uses the same pair.

Then:

export HZAPI_API_KEY="sk-xxxx"
codex
Enter fullscreen mode Exit fullscreen mode

Step 3: use it as a profile without touching your normal login

HZ AI's guide shows a [profiles.hzapi] table inside config.toml. OpenAI's Codex docs say that from Codex 0.134.0 --profile no longer reads [profiles.<name>] from config.toml; instead it loads ~/.codex/<name>.config.toml as a layer on top. If your profile "does nothing" on a recent version, this is why.

Keep the provider block in config.toml (as above, without the model / model_provider lines) and put only the differences in a profile file:

# ~/.codex/hzapi.config.toml
model = "gpt-6.2-astra"
model_provider = "hzapi"
Enter fullscreen mode Exit fullscreen mode
codex --profile hzapi
codex exec --profile hzapi "explain this repo's build"
Enter fullscreen mode Exit fullscreen mode

Your default (official login) setup keeps working when you run plain codex. Check codex --version and read the docs for your version: Advanced configuration.

If it fails mid-answer instead of at the start

stream disconnected before completion is a different problem: the connection closed before the final response.completed event. That is almost always a proxy, VPN or client timeout in between, not your config. See my write-up on streams that stop mid-response.

Checklist

  1. curl .../v1/models returns your model list.
  2. curl .../v1/responses returns JSON.
  3. base_url ends at /v1, wire_api is responses or absent.
  4. model and model_provider are above every [table] header.
  5. HZAPI_API_KEY is exported in the shell that starts Codex.
  6. On new Codex versions, profiles live in ~/.codex/<name>.config.toml.

When asking anyone for help, share the last 4 characters of the key, the model name and the time of the failure. Never the full key.


Disclosure: I maintain HZAPI. The example repo with Python, Node and curl samples is Sakcyb/hzapi-examples (MIT). Billing on HZAPI is usage-based; live rates are on its model plaza, so I don't quote any here.

Top comments (0)