Codex Integration
Codex uses the OpenAI Responses API. When integrating with CoreRouter via custom model provider, configure the Provider in the user-level config.toml and provide the API Key via environment variables.
Codex requires the current Model ID to support
/v1/responses. If it only supports/v1/chat/completions, regular chat may work, but Codex cannot complete Agent workflows.
Prerequisites
- VS Code and Codex installed.
- API Key created in CoreRouter console.
- Model ID confirmed to support Responses API.
- Model suitable for Coding Agent selected; don't directly reuse models that only support regular chat.
Configuration File Location
Default configuration file:
~/.codex/config.tomlWindows typically located at:
%USERPROFILE%\.codex\config.tomlIf the file doesn't exist, create it manually.
Configure CoreRouter Provider
model = "responses-model-id"
model_provider = "corerouter"
[model_providers.corerouter]
name = "CoreRouter"
base_url = "https://api.corerouter.cloud/v1"
env_key = "COREROUTER_API_KEY"
wire_api = "responses"| Field | Description |
|---|---|
model | Model ID from CoreRouter console that supports Responses / Coding Agent |
model_provider | Current Provider name in use |
base_url | CoreRouter OpenAI-compatible endpoint |
env_key | Environment variable name to read API Key from |
wire_api | Set to responses to make Codex use Responses API |
Set API Key
macOS / Linux:
export COREROUTER_API_KEY="sk-xxxxxxxxxxxxxxxx"Permanent effect:
echo 'export COREROUTER_API_KEY="sk-xxxxxxxxxxxxxxxx"' >> ~/.zshrc
source ~/.zshrcWindows PowerShell:
$env:COREROUTER_API_KEY="sk-xxxxxxxxxxxxxxxx"User-level permanent configuration:
[System.Environment]::SetEnvironmentVariable('COREROUTER_API_KEY', 'sk-xxxxxxxxxxxxxxxx', 'User')Verify Responses API
curl https://api.corerouter.cloud/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $COREROUTER_API_KEY" \
-d '{
"model": "responses-model-id",
"input": "Hello"
}'If successful JSON is returned, the Responses API for this Model ID is basically available.
See Responses API Integration for more raw API examples.
Test Codex
After configuration, restart VS Code, open Codex, and test in order:
Please analyze the current project's directory structure and tell me what main technologies this project uses.Please create a hello.ts file, implement a hello function, then run related tests and tell me the test results.Call Chain
VS Code
-> Codex
-> OpenAI Responses API
-> CoreRouter
-> New API compatibility layer
-> Model channel
-> AI ModelCommon Issues
Regular API Works, But Codex Doesn't
Codex uses /v1/responses, not /v1/chat/completions. Verify the Responses API separately with the same Model ID.
How Should Base URL Be Filled?
Codex Provider's base_url should be https://api.corerouter.cloud/v1. If filled to /v1/responses, Codex will continue to append paths and cause request failure.
API Key Invalid Error
Check:
- Is the environment variable name
COREROUTER_API_KEY? - Does
env_keyinconfig.tomlmatch? - Does the API Key come from the CoreRouter console?
Model Not Found Error
Change model to the Model ID displayed in the console; don't use display names.
Agent Capabilities Unstable
Select models that support Responses, Tool Calling, Streaming, and Coding Agent. If the model only supports regular conversation, Codex may not complete file modifications, command execution, or multi-step tasks.
Security Recommendations
- Don't write API Keys into
config.toml. - Use
env_keyto read API Keys from environment variables. - Don't commit
~/.codex/config.tomlto project repositories. - Create a separate API Key for Codex and set a quota limit.
