Connect Codex to ModelGo: Setup & Troubleshooting

Codex is OpenAI's command-line coding assistant. A custom model_provider sends its Responses API requests to ModelGo. Before you start, create an API key in the ModelGo console and pick a logical model name your key can call from the Model Catalog.

1. Install

bash
npm install -g @openai/codex
codex --version

If the first launch offers an update, you can choose Skip for now.

Skip the Codex upgrade prompt

2. Configure ModelGo

Edit ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml):

toml
model_provider = "modelgo"
model = "your-model-id"

[model_providers.modelgo]
name = "ModelGo"
base_url = "https://api.modelgo.ai/v1"
env_key = "MODELGO_API_KEY"
wire_api = "responses"

Put the API key in an environment variable, not in config.toml (Windows PowerShell: [Environment]::SetEnvironmentVariable("MODELGO_API_KEY", "mgk_your_api_key", "User")):

bash
echo 'export MODELGO_API_KEY="mgk_your_api_key"' >> ~/.zshrc
source ~/.zshrc

3. Start and verify

Run codex in a project directory, trust the directory when prompted, and send a simple request. A normal reply means the setup works.

Codex project welcome screen
Start a conversation in Codex

To check the key and the models it can call:

bash
curl https://api.modelgo.ai/v1/models \
  -H "Authorization: Bearer $MODELGO_API_KEY"

Troubleshooting

  • Provider not found: the file must be ~/.codex/config.toml, and model_provider must match [model_providers.modelgo].
  • 401: make sure MODELGO_API_KEY is set in the current terminal, with no extra spaces or line breaks.
  • 403 / model unavailable: model must be a logical model name your API key can call.
  • 404: base_url must be https://api.modelgo.ai/v1, not the full /v1/responses path.
  • Chat wire API deprecation warning: set wire_api = "responses" and upgrade with npm install -g @openai/codex@latest.
  • 400 invalid_encrypted_content: the conversation carries encrypted context from another upstream account; start a new conversation.

Related docs