Skip to content

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:

text
~/.codex/config.toml

Windows typically located at:

text
%USERPROFILE%\.codex\config.toml

If the file doesn't exist, create it manually.

Configure CoreRouter Provider ​

toml
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"
FieldDescription
modelModel ID from CoreRouter console that supports Responses / Coding Agent
model_providerCurrent Provider name in use
base_urlCoreRouter OpenAI-compatible endpoint
env_keyEnvironment variable name to read API Key from
wire_apiSet to responses to make Codex use Responses API

Set API Key ​

macOS / Linux:

bash
export COREROUTER_API_KEY="sk-xxxxxxxxxxxxxxxx"

Permanent effect:

bash
echo 'export COREROUTER_API_KEY="sk-xxxxxxxxxxxxxxxx"' >> ~/.zshrc
source ~/.zshrc

Windows PowerShell:

powershell
$env:COREROUTER_API_KEY="sk-xxxxxxxxxxxxxxxx"

User-level permanent configuration:

powershell
[System.Environment]::SetEnvironmentVariable('COREROUTER_API_KEY', 'sk-xxxxxxxxxxxxxxxx', 'User')

Verify Responses API ​

bash
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:

text
Please analyze the current project's directory structure and tell me what main technologies this project uses.
text
Please create a hello.ts file, implement a hello function, then run related tests and tell me the test results.

Call Chain ​

text
VS Code
   -> Codex
   -> OpenAI Responses API
   -> CoreRouter
   -> New API compatibility layer
   -> Model channel
   -> AI Model

Common 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_key in config.toml match?
  • 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_key to read API Keys from environment variables.
  • Don't commit ~/.codex/config.toml to project repositories.
  • Create a separate API Key for Codex and set a quota limit.

Released under the MIT License.