OpenAI Codex Relay Tutorial: Custom Base URL for GPT Configuration

  • 发布时间
  • 语言en

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 GroupSite Gateway (Base URL)Protocol
Claude / Anthropichttps://www.relay-api.comAnthropic Messages
GPT / OpenAIhttps://www.relay-api.com/v1OpenAI Chat Completions
Geminihttps://www.relay-api.com/v1betaGoogle generateContent

5. Troubleshooting

SymptomResolution
401 / 403Key is invalid, disabled, or has insufficient balance; verify the sk- key and top up your account.
404 / Model UnavailableModel name does not match the platform slug, or the model is not enabled; double-check the model ID.
Unknown modelThe 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.