Skip to main content
OpenAI’s Codex CLI respects the standard OPENAI_BASE_URL environment variable, which lets you route every request it makes to A2Agent’s OpenAI-compatible endpoint. The result is the full Codex CLI workflow backed by models like DeepSeek, Kimi, GLM, and MiniMax, with model availability, usage limits, and billing managed through your A2Agent account.

Prerequisites

Setup

1

Set the required environment variables

Before running Codex, export your A2Agent key and base URL in your current shell session:
OPENAI_API_KEY here is your A2Agent API key, not an OpenAI key. A2Agent accepts requests in the OpenAI API format and routes them to the model you select.
2

Run Codex and verify the connection

With those variables set, run Codex as you normally would — it will automatically route all requests through A2Agent:
If Codex returns a response, your setup is working correctly.
3

(Optional) Specify a model

Pass the --model flag to select a particular A2Agent model for the task at hand:

Persist the configuration

To avoid re-exporting the variables every session, add them to your shell profile:
~/.bashrc or ~/.zshrc
After saving, reload your profile:
From that point on, every new terminal session will automatically use A2Agent when you run Codex.

Troubleshooting

Codex is reaching A2Agent but your credentials are being rejected. Double-check that OPENAI_API_KEY is set to your full A2Agent key with no extra spaces, quotes, or newline characters.
Confirm that OPENAI_BASE_URL is set to exactly https://api.a2agent.me/v1 — including the /v1 path and no trailing slash. Run echo $OPENAI_BASE_URL to verify the value in your current shell.
The model name you passed with --model must match an A2Agent model ID exactly — for example, deepseek-v4-pro, kimi-k2.7-code, glm-5.1, or minimax-m2.5. Check the A2Agent model list for all available IDs.
Run source ~/.bashrc (or source ~/.zshrc) in your current terminal after editing the profile, or open a new terminal session for the changes to take effect.