Skip to content

DocsCoding agents

Codex CLI

Run OpenAI's Codex CLI on your Osarai instance through a custom model provider that speaks the Responses API.

Codex CLI is OpenAI's coding agent for the terminal. It talks to custom providers over the Responses API only, which Osarai serves at https://osarai.xyz/v1/responses.

Codex CLI answering on an Osarai instance through a custom provider
Codex CLI running on an Osarai instance.

Install

Terminal
npm install -g @openai/codex

Configure

Add a provider to Codex's configuration file and make it the default:

~/.codex/config.toml
model = "gpt-oss-20b"
model_provider = "osarai"
model_context_window = 131072
model_auto_compact_token_limit = 110000
model_reasoning_effort = "medium"

[model_providers.osarai]
name = "Osarai"
base_url = "https://osarai.xyz/v1"
env_key = "OSARAI_API_KEY"
wire_api = "responses"
KeyWhy
modelYour instance's model id
model_providerSelects the [model_providers.osarai] block below
model_context_windowThe real context window: Codex has no metadata for open models
model_auto_compact_token_limitCompact the conversation before it reaches the window
model_reasoning_effortlow, medium or high, sent as reasoning.effort
base_urlIncludes /v1
env_keyThe environment variable that holds your key; Codex sends it as Authorization: Bearer
wire_apiMust be responses: newer Codex releases no longer accept chat

Run

Terminal
export OSARAI_API_KEY="qck_your_key_here"
cd your-project
codex

The header shows model: gpt-oss-20b and provider: osarai. To run one prompt and exit:

Terminal
codex exec "Explain what src/math.ts does" < /dev/null

codex exec reads extra input from standard input when it is not a terminal; < /dev/null stops it waiting in scripts and CI.

Switching models

A profile is a second file next to config.toml, named <profile>.config.toml. Its keys override the main file, so the provider carries over:

~/.codex/qwen.config.toml
model = "qwen3.8-27b"
model_context_window = 131072
Terminal
codex --profile qwen

Troubleshooting

SymptomFix
Model metadata for … not foundExpected for open models; model_context_window tells Codex the window
401 UnauthorizedOSARAI_API_KEY is not set in the shell that started Codex, or env_key names another variable
wire_api = "chat" is no longer supportedSet wire_api = "responses"
404 on /v1/v1/responsesbase_url ends with /v1 once, not twice
503 … not ready yetThe instance is still starting; wait for Ready on the instance page
codex exec never exitsAdd < /dev/null so it does not wait for standard input
--profile … cannot be used while config.toml contains legacy … [profiles.…]Move the [profiles.name] table into ~/.codex/name.config.toml