OPENAI_BASE_URL environment variable, which means you can redirect every request it makes to A2Agent’s OpenAI-compatible endpoint. The result is full Codex CLI functionality backed by models like DeepSeek, Kimi, GLM, and MiniMax — at significantly lower cost.
Prerequisites
- Codex CLI installed — follow the official installation guide if needed
- An A2Agent API key — sign up at a2agent.me/register to get one
Setup
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.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.
(Optional) Specify a model
Pass the Recommended models for coding tasks:
--model flag to select a particular A2Agent model for the task at hand:| Model | Best for |
|---|---|
deepseek-v4-pro | Complex refactoring and architecture |
glm-5.1 | General-purpose coding assistance |
kimi-k2.7-code | Code generation and debugging |
minimax-m2.5 | Long-context code analysis |
Persist the configuration
To avoid re-exporting the variables every session, add them to your shell profile:~/.bashrc or ~/.zshrc
Troubleshooting
401 Unauthorized
401 Unauthorized
Connection refused or could not resolve host
Connection refused or could not resolve host
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.Model not found
Model not found
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.Environment variables not recognised after editing shell profile
Environment variables not recognised after editing shell profile
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.