Skip to main content
OpenAI’s Codex CLI respects the standard 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

Setup

1

Set the required environment variables

Before running Codex, export your A2Agent key and base URL in your current shell session:
export OPENAI_API_KEY="YOUR_A2AGENT_KEY"
export OPENAI_BASE_URL="https://api.a2agent.me/v1"
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:
codex "add error handling to this function"
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:
codex --model deepseek-v4-pro "refactor this function to be more readable"
Recommended models for coding tasks:
ModelBest for
deepseek-v4-proComplex refactoring and architecture
glm-5.1General-purpose coding assistance
kimi-k2.7-codeCode generation and debugging
minimax-m2.5Long-context code analysis

Persist the configuration

To avoid re-exporting the variables every session, add them to your shell profile:
~/.bashrc or ~/.zshrc
export OPENAI_API_KEY="YOUR_A2AGENT_KEY"
export OPENAI_BASE_URL="https://api.a2agent.me/v1"
After saving, reload your profile:
source ~/.bashrc   # or source ~/.zshrc
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.