Skip to content

Using Agent Router with Codex

Install Codex

bash
pnpm install -g @openai/codex
bash
npm install -g @openai/codex
bash
yarn global add @openai/codex

Configure Environment Variables

  1. Visit https://agentrouter.org/console/token to get your API Key
  2. Set the system environment variable with the name AGENT_ROUTER_TOKEN and the value you just obtained (Environment Variable Setup Tutorial)
  3. Create the ~/.codex/config.toml file and add the following configuration:
toml
model = "gpt-5"
model_provider = "openai-chat-completions"
preferred_auth_method = "apikey"


[model_providers.openai-chat-completions]
name = "OpenAI using Chat Completions"
base_url = "https://agentrouter.org/v1"
env_key = "AGENT_ROUTER_TOKEN"
wire_api = "chat"
query_params = {}
stream_idle_timeout_ms = 300000
  1. Create the ~/.codex/auth.json file and add the following code:
json
{
 "OPENAI_API_KEY":"Replace this with your API KEY"
}

Launch Directly

After configuring the environment variables, use your terminal to open the project directory you want to work with, then run the following command to start Codex:

bash
# Navigate to project directory
cd my-project

# Launch OpenAI Codex directly
codex

Using Codex in VSCode

  1. Follow the instructions above to install Codex and configure environment variables and configuration files.

  2. Open VSCode and install the Codex extension.

  3. Go to settings and click the icon in the upper right corner to switch to JSON configuration mode

  1. Add the following configuration items:
json
"chatgpt.apiBase": "https://agentrouter.org/v1",
"chatgpt.config": {
    "pepreferred_auth_method": "api_key",
    "model_provider": "openai-chat-completions"
}

  1. Click the Codex icon to start using...