🎁 New Sign up free, 10 calls on us. Up to $1, no card needed.

OpenAI Codex CLI

OpenAI's official terminal coding agent. Because it speaks the standard OpenAI API, the same two environment variables unlock every OpenAI-compatible tool in the ecosystem — once Codex works, Aider / Continue / LangChain / the raw openai CLI all work too.

Before you start

Create an API key at Console → API Keys. Copy it immediately — it is only shown once.

Step 1 — Set environment variables

# ~/.zshrc (or equivalent)
export OPENAI_BASE_URL="https://synthorai.io/v1"
export OPENAI_API_KEY="sk-..."   # your Synthorai key

The OpenAI-compatible base URL must end in /v1. Unlike the Anthropic SDK, the OpenAI SDK does not auto-append it. A common mistake is pasting https://synthorai.io; requests will then hit /chat/completions (404) instead of /v1/chat/completions.

Step 2 — Send your first request

# Open a new shell so env vars take effect, then:
codex exec -m gpt-5.4-mini "refactor this function for readability" < src/foo.py

# Or for long reasoning-heavy tasks:
codex exec -m gpt-5.3-codex "implement unit tests for bar()"

The same configuration works for the openai CLI, Python/Node SDKs, Aider, and any other OpenAI-compatible tool — they all read OPENAI_BASE_URL and OPENAI_API_KEY.

Recommended models

ParameterTypeDescription
gpt-5.3-codexcodingTuned for code generation. Default pick for Codex CLI.
gpt-5.4reasoningFlagship reasoning. Use for architecture-level refactors.
gpt-5.4-minifastFast, cheap, still very capable. Good default for short tasks.
gpt-5.4-nanocheapestCheapest OpenAI option. Use for small edits and classification.

Troubleshooting

"404 Not Found" on /chat/completions — your OPENAI_BASE_URL is missing the /v1 suffix. Fix: export OPENAI_BASE_URL="https://synthorai.io/v1".

"Still hitting api.openai.com" — new env vars only apply to new shells. Open a fresh terminal, or source your profile.

"Model not found"curl $OPENAI_BASE_URL/models -H "Authorization: Bearer $OPENAI_API_KEY" to see the exact list available to your workspace.

Per-project override — if you don't want these vars globally, put them in a project .envrc (with direnv) or a per-shell function.

See how the four tiers stack up on price in the model price comparison.