OpenAI Codex Relay Tutorial: Custom Base URL for GPT Configuration
OpenAI Codex (Codex CLI) terminal coding agent tutorial: How to install, configure custom Base URLs and keys via environment variables or config.toml, and use 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 site's OpenAI-compatible gateway, you can use GPT-series models with your sk- key.
2. Install Codex CLI
npm install -g @openai/codex
After installation, type codex in your terminal. You can switch models using codex --model gpt-5.5 or via the model selection in the interactive mode.
3. Configure 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.5
② config.toml (Recommended for long-term use)
# ~/.codex/config.toml
[model_providers.myrelay]
name = "Pro API Relay"
base_url = "https://www.relay-api.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "chat"
[model]
model_provider = "myrelay"
model = "gpt-5.5"
After saving, run codex --model gpt-5.5 to start.
4. API Endpoint Reference
| Model Group | Site Gateway (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
| Symptom | Resolution |
|---|---|
| 401 / 403 | Key is invalid, disabled, or has insufficient balance; verify the sk- key and top up your account. |
| 404 / Model Unavailable | Model name does not match the platform slug, or the model is not enabled; double-check the model ID. |
| Unknown model | The model ID must be exact (including case); check the model list in the dashboard. |
Security Tip: Do not commit keys to public repositories; use .env or environment variables. Generation tasks can consume significant tokens, so keep an eye on your balance.
Base URL Note: Our site accepts both /v1beta/models/... and /v1beta/v1beta/models/... (as well as /v1/... and /v1/v1/...), so whether your client appends /v1 or /v1beta will not affect the call. You can use either the root domain or the full address containing /v1beta. Please find and copy the correct model IDs from the "Model ID" section at the top right of the "Tokens" page in your dashboard.
