Codex

Codex lets you add a model provider of its own in config.toml, and that is all the Model API needs: Codex speaks the OpenAI Responses API, and the Model API answers it at POST /v1/responses. Nothing to install besides Codex itself. The model is auto, which picks a model of the catalogue for the conversation.

Requirements: Codex CLI (codex --version shows the version), a Model API key and money on the organization balance.

1. Create a key

In the developer console, open API keys, keep Model API key in the Access field and create the key. The secret is shown once. Put it into your shell profile (~/.zshrc, ~/.bashrc) so Codex can read it:

bash
export SAMRESHUUU_API_KEY="sk-org-your_api_key"

2. Add the provider

Codex reads ~/.codex/config.toml, or config.toml in the folder named by CODEX_HOME. Add the lines below. Keep the root keys (model, model_provider, model_reasoning_effort) above any [table] header of the file: in TOML a key after a header belongs to that table.

toml
model = "auto" model_provider = "samreshuuu" model_reasoning_effort = "high" [model_providers.samreshuuu] name = "Samreshuuu" base_url = "https://api.samreshuuu.ru/v1" env_key = "SAMRESHUUU_API_KEY" wire_api = "responses"
SettingWhat it does
modelThe model sessions start on: auto or an id from the Models page.
model_providerMakes the provider below the one Codex calls.
model_reasoning_effortThe reasoning level Codex asks for: minimal, low, medium, high, xhigh or max. Codex sends none of its own for a model it does not know.
base_urlThe Model API's address. Keep /v1 at the end: Codex appends /responses itself.
env_keyThe environment variable Codex reads the key from.
wire_apiresponses, the only protocol Codex speaks.

Restart your Codex sessions. For one session, codex --model <id> names another model.

3. Check the connection

Run in a project folder:

bash
codex exec "Reply with pong"

The answer comes back, and the call shows up in the call log of the console with the model auto picked and its cost. At the start of a session Codex warns that it has no metadata for auto and falls back to its defaults: that is expected.

How Codex works through the API

  • Codex keeps no state on the server: every request carries the whole conversation with store: false, as the Responses API expects.
  • For a model it does not know Codex gives the model its shell tool and its default system prompt, and edits files with apply_patch through that shell. Tool calls and their results travel as Responses items.
  • The model's reasoning comes back as a reasoning item; Codex sends it back in the next request, and the model gets it again, on another host too.
  • Codex names the conversation in prompt_cache_key, which keeps its calls in one cache.
  • Codex counts the price of a thread on its own side and does not read usage.cost. What the balance was charged is in the call log of the console.

Undo the setup

Remove the model, model_provider and model_reasoning_effort lines and the [model_providers.samreshuuu] table from config.toml. Codex then goes back to your usual provider.

Troubleshooting

What you seeWhat to check
401 or a missing environment variableSAMRESHUUU_API_KEY is not set in the shell that started Codex, or the key was revoked.
Codex refuses the config fileA root key such as model stands below a [table] header, or wire_api is not responses.
model_not_foundThe model id is not in the catalogue: take one from GET /v1/models or use auto.
402The balance does not cover the call's hold, or the key's spend limit is reached.
HTTPtypeCodemessageRetry
401authentication_errorinvalid_api_keyThe API key is unknown, disabled, revoked or expired. Switch a disabled key back on in the developer console; create a new one in place of a revoked or expired key.no
404not_found_errormodel_not_foundThe model does not exist. GET /v1/models lists the models this API sells.no
400invalid_request_errorno_auto_modelNo model meets the request for auto.no
402billing_errorinsufficient_balanceThe organization balance does not cover this request (max_tokens is held in full until the answer is settled). Top up the balance or lower max_tokens.no
402billing_errorkey_limit_exceededThis API key has reached its spending limit. Raise the limit or use another key.no

If an error persists, write to support with the x-request-id of the answer.

Frequently asked questions

Why does Codex warn that model metadata for auto is not found?

Codex keeps a built-in list of OpenAI models and does not know auto, so it runs on its default settings: its own system prompt, the shell tool, file edits through apply_patch in that shell. The warning is expected and the session works.

Can Codex use wire_api = "chat"?

No. Current Codex speaks only the Responses API and refuses a config with wire_api = "chat". The Model API serves Responses at POST /v1/responses.

Where do I see what a session cost?

In the call log of the developer console (https://console.samreshuuu.ru). Codex counts the price of a thread on its own side and does not read the cost from the answer.

Was this page helpful?