OpenAI Codex Integration Tutorial: Custom Base URL Configuration for GPT
Tutorial on integrating OpenAI Codex (Codex CLI) terminal coding agent: installation, configuring custom Base URLs and keys via environment variables or config.toml, and using GPT models.
1. What is Codex?
OpenAI Codex (Codex CLI) is OpenAI's official terminal coding agent that supports custom API endpoints. By pointing it to our gateway's OpenAI-compatible entry point, you can use GPT series models with your sk- key.
2. Installing Codex CLI
npm install -g @openai/codex
After installation, enter codex in your terminal; switch models using codex --model gpt-5.4 or through the model selection menu during interaction.
3. Configuring Codex
① Environment Variables (Fastest)
export OPENAI_BASE_URL="https://www.relay-api.com/v1"
export OPENAI_API_KEY="sk-your-key"
codex --model gpt-5.4
② config.toml (Recommended for long-term use)
# ~/.codex/config.toml
[model_providers.myrelay]
name = "Azztimes Relay"
base_url = "https://www.relay-api.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "chat"
[model]
model_provider = "myrelay"
model = "gpt-5.4"
Save the file and run codex --model gpt-5.4 to get started.
4. API Endpoint Reference
| Model Group | Base URL | Protocol |
|---|---|---|
| Claude / Anthropic | https://www.relay-api.com | Anthropic Messages |
| GPT / OpenAI | https://www.relay-api.com/v1 | OpenAI Chat Completions |
| Gemini | https://www.relay-api.com/v1beta | Google generateContent |
5. Troubleshooting
| Issue | Solution |
|---|---|
| 401 / 403 | Invalid key, disabled, or insufficient balance; verify the sk- key and top up if necessary. |
| 404 / Model unavailable | The model name does not match the platform slug, or the model is not enabled; check the model ID. |
| Unknown model | Ensure the model ID is precise (including case sensitivity); verify it via the Model Plaza. |
Security Note: Do not commit your API key to public repositories. Use .env files or environment variables. Generation tasks can consume significant tokens, so keep an eye on your balance.
