OpenAI Codex CLI
Run OpenAI's Codex CLI on DeutschlandGPT models through the Platform API, and keep resuming sessions you started with OpenAI
OpenAI's Codex CLI is a coding agent for the terminal. It reads and edits files in your project and runs commands on your machine. The model behind it can run at DeutschlandGPT: you point Codex at the Platform API and sign it in with an API key.
Codex uses your Platform API credit, not your chat licence. Every request is charged to your workspace like any other API request and shows up in the Dashboard under the key you used.
We tested the steps below with Codex CLI 0.166.0. Codex changes quickly; if a later version behaves differently, check its release notes for changes to openai_base_url, codex login and profiles.
Before you start
- An API key. Create one under API Keys as described in the Quickstart. A separate key for Codex, for example
codex, keeps its usage easy to tell apart, and a spending limit on it caps what the agent can spend. - Credit. On a prepaid workspace, requests only run while there is credit.
- A model with tool calling. Codex does all its work through tool calls. Models lists the exact model IDs your key can use.
Set up Codex
Codex has a built-in provider called openai. Point that provider at DeutschlandGPT instead of defining a provider of your own. This is what lets you keep resuming sessions you started with OpenAI (see below).
-
Add the base URL to the top of
~/.codex/config.toml, outside any[section]:TOMLopenai_base_url = "https://api.deutschlandgpt.de/v2" model = "<model-id>"A self-hosted instance uses
https://<your-domain>/platform-api/api/v2. -
Store your API key in Codex. The command reads the key from standard input:
BASHecho "<your API key>" | codex login --with-api-keyIn PowerShell:
"<your API key>" | codex login --with-api-key. -
Start Codex as usual with
codex.
- Only the stored login counts. For the built-in
openaiprovider, Codex sends the key saved bycodex login. The environment variableOPENAI_API_KEYis not used for it. - Signed in with an OpenAI API key before?
codex login --with-api-keyreplaces that login. As long as the old key is stored, Codex sends it to DeutschlandGPT and every request fails with401. - Models from other makers work too. With a model ID Codex doesn't know, for example a Claude or Mistral model, Codex prints
Model metadata for … not found. Defaulting to fallback metadata. The request still goes to the model you set. - The first request of a session can take a few seconds longer. Codex first tries a WebSocket connection, which the Platform API doesn't offer, and then switches to HTTPS on its own.
Older sessions
You can resume sessions you started with OpenAI and continue them on a DeutschlandGPT model, with their full history.
codex resume # pick from the list
codex resume <session-id> # or resume one directly
Codex stores each session with the name of the provider it ran on, not the URL. A session you started with OpenAI is stored as openai. Codex only resumes a session, and only lists it, under that same provider name. Because the setup above keeps the provider openai and changes only its address, all sessions started with OpenAI are listed and can be continued here. New sessions are stored as openai too, so you can later switch the address back to OpenAI and continue them there.
If an old session ran on a model ID that DeutschlandGPT doesn't offer, choose a model when you resume, for example codex resume <session-id> -m <model-id>, or switch with /model inside the session.
Don't define your own provider for DeutschlandGPT (a [model_providers.…] section with its own
name). Codex then refuses to resume sessions started with OpenAI, and its resume list shows none
of them.
Using a profile instead
To switch between OpenAI and DeutschlandGPT, put the two lines from config.toml into a profile instead. Codex 0.166 keeps each profile in a file of its own, for example ~/.codex/deutschlandgpt.config.toml:
openai_base_url = "https://api.deutschlandgpt.de/v2"
model = "<model-id>"
Start Codex with codex --profile deutschlandgpt or codex resume --profile deutschlandgpt. Without --profile, Codex talks to OpenAI again. A [profiles.<name>] section inside config.toml is no longer accepted together with --profile; Codex stops with an error that says where to move it.
Codex keeps only one stored login, so the key from codex login is used on both sides. Run codex login again when you switch.
Troubleshooting
This chat uses openai, but your current provider is …(modelProviderMismatch): Codex runs on a provider you defined yourself. Remove that provider from the configuration and useopenai_base_urlas described above.- The resume list is empty: the same cause. The list only shows sessions of the provider Codex currently uses.
401withMalformed api key: Codex still sends an older OpenAI login. Runcodex login --with-api-keywith your DeutschlandGPT key.401withSession expired or invalid: Codex sends no key at all. Store one withcodex login --with-api-key;OPENAI_API_KEYalone is not enough.404withModel … not found: use a model ID exactly as Models lists it, inconfig.tomlor with-m.402: the workspace has no credit left, or a monthly or per-key limit is reached. See Billing.