Home / Docs / Codex CLI setup

Connect Codex CLI to MonkeyAI without replacing your existing config.

Test the API key first. Then use a named Codex profile, keep the key in $CODEX_HOME/.env, and select a model returned by your account’s live model list.

0.146.0CLI tested
profileexisting config preserved
/v1/responsesrequest path observed
.envload/no-load tested

What was actually tested

On 2026-08-02, Codex CLI 0.146.0 loaded monkeyai.config.toml, read a fake key from $CODEX_HOME/.env, and sent the request to https://monkeytheme.com/v1/responses. MonkeyAI returned 401 INVALID_API_KEY, as expected for the fake key. Removing .env changed the error to Missing environment variable: MONKEYAI_API_KEY.

This proves the profile, environment-file loading and request route. It does not pretend that a fake key completed a model response. The installer validates your real key with GET /v1/models before writing configuration.

Recommended installer path

curl -fsSL https://monkeytheme.com/install/codex.sh -o /tmp/monkeyai-codex.sh
bash -n /tmp/monkeyai-codex.sh
bash /tmp/monkeyai-codex.sh

The script hides key input, checks codex --version with a 15-second timeout, tests your key and Base URL, shows currently visible GPT/Codex models, and writes a separate monkeyai profile. It does not overwrite ~/.codex/config.toml.

Manual configuration

Create $CODEX_HOME/monkeyai.config.toml (normally ~/.codex/monkeyai.config.toml):

model = ""
model_provider = "monkeyai"

[model_providers.monkeyai]
name = "MonkeyAI"
base_url = "https://monkeytheme.com/v1"
env_key = "MONKEYAI_API_KEY"
wire_api = "responses"
requires_openai_auth = false

Set MONKEYAI_API_KEY in $CODEX_HOME/.env, keep the file at mode 600, and replace <CURRENT_VISIBLE_MODEL> with a model returned by your own /v1/models request.

Run the first Codex request

codex --profile monkeyai exec --skip-git-repo-check "Reply with OK only"

--skip-git-repo-check lets this smoke test run outside a repository. For real coding work, open the project directory first and remove that flag.

Common errors

ErrorMeaningFix
codex --version hangsOld or conflicting Codex installationsRun which -a codex, then reinstall with npm install -g @openai/codex@latest.
Missing MONKEYAI_API_KEYCodex did not find the variable in the current environment or $CODEX_HOME/.envCheck CODEX_HOME, the filename and the exact variable name.
401 / invalid API keyThe request reached MonkeyAI but the key was rejectedCreate or copy a current key from the MonkeyAI dashboard, then rerun /v1/models.
404Wrong Base URL or pathUse https://monkeytheme.com/v1; Codex uses the Responses endpoint.
model not foundThe configured model is not visible to this accountChoose a GPT/Codex model from the current /v1/models response.
Provider config ignoredProvider keys were placed in project-local .codex/config.tomlPut the provider in the user-level profile under $CODEX_HOME.

FAQ

Does Codex load ~/.codex/.env?

Codex CLI 0.146.0 loaded MONKEYAI_API_KEY from $CODEX_HOME/.env in a controlled test. Removing that file produced a missing environment variable error.

Why use a profile instead of config.toml?

A profile keeps the MonkeyAI provider separate and avoids replacing an existing Codex setup. Run it with --profile monkeyai.

Which Base URL and protocol should I use?

Use https://monkeytheme.com/v1 and the Responses protocol. The tested request path was /v1/responses.

How do I choose a model?

Select a GPT or Codex model returned by the current account’s /v1/models response. Do not copy a stale model name from an old tutorial.

Related guides

API key errors

Separate 401, 404 and model errors before changing Codex.

Open troubleshooting

Codex deep dive

Review the longer third-party API guide after the first request works.

Open guide

Current models

Use the live page instead of a copied model list.

Open pricing