Integration Guides

Connect Codex to ROIBest AI: Configuring the OpenAI-Compatible Protocol

ROIBest AI

Codex speaks the OpenAI protocol, which puts it on a different path from Claude Code. The key, the endpoint and the configuration format all differ — copying the Claude Code setup will fail at every step.

Pick the right protocol group first

ROIBest AI issues keys per protocol group:

Group

Endpoints

Used by

Anthropic-compatible

/v1/messages

Claude Code

OpenAI-compatible

/v1/responses, /v1/chat/completions

Codex, OpenAI SDK

Codex needs an OpenAI-compatible key. The wrong group returns 401, and the error message will not mention the group — this is the most common and least self-evident problem during setup.

Create the key under API Keys in the console, selecting the OpenAI-compatible group.

Configure Codex

Codex supports custom model providers, configured in ~/.codex/config.toml:

model = "gpt-5"
model_provider = "roibest"

[model_providers.roibest]
name = "ROIBest AI"
base_url = "https://ai.roibest.com/v1"
env_key = "ROIBEST_API_KEY"
wire_api = "responses"

A few fields deserve attention:

  • base_url does include /v1 — the opposite of Claude Code's ANTHROPIC_BASE_URL. Codex appends /responses directly to this value, so omitting /v1 yields a 404.
  • wire_api = "responses" selects the Responses API (/v1/responses). The gateway also serves /v1/chat/completions; if your Codex version or use case needs it, set this to "chat".
  • env_key names an environment variable — it is not the key itself. Codex reads the variable:
export ROIBEST_API_KEY="your-key"

Add it to ~/.zshrc or ~/.bashrc to make it persistent.

Treat the exact field names as version-dependent and check the Codex documentation — they have changed across releases. The shape above matches the current model_providers configuration.

Verify the endpoint before launching the client

Separating gateway problems from client configuration saves a lot of time:

curl https://ai.roibest.com/v1/responses \
  -H "Authorization: Bearer $ROIBEST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "input": "ping"
  }'

A normal response confirms the key, the group and the endpoint. Then start Codex:

codex

Confirm usage is being recorded

Open the usage records in the console. Each request logs the model, protocol group, input and output tokens, cache tokens, billing mode, cost and latency.

The point is the same as with Claude Code: this is the only way to confirm the request really went through the gateway. When the configuration does not take effect, Codex keeps working with its previous credentials and nothing looks wrong.

Troubleshooting

401 with a valid key Check that the group is OpenAI-compatible. Then confirm the variable is set in the current shell: echo $ROIBEST_API_KEY.

404 base_url is missing /v1, or has one segment too many (set to .../v1/responses). It should be exactly https://ai.roibest.com/v1.

The model name is rejected Available models depend on your account and group. Copy the current name from the console's model directory.

Keeping the official configuration alongside this one config.toml can hold several providers; switching is a one-line change to model_provider at the top. The setups do not interfere.

Summary

Codex differs from Claude Code in three places: it needs an OpenAI-compatible key, its base_url does include /v1, and it is configured in config.toml rather than through environment variables. One curl call against /v1/responses catches almost everything before you launch the client.