OpenAI Codex Integration Tutorial: Custom Base URL Configuration for GPT

  • 发布时间
  • 语言en

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 GroupBase URLProtocol
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

IssueSolution
401 / 403Invalid key, disabled, or insufficient balance; verify the sk- key and top up if necessary.
404 / Model unavailableThe model name does not match the platform slug, or the model is not enabled; check the model ID.
Unknown modelEnsure 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.