Skip to main content

Connect Codex CLI to memtrunk

Connect Codex CLI through your personal token address, or with a named API key. Add the provider, select it, verify the connection and fix 404 and 429 errors.

Last updated

Codex CLI connects through your personal address. The address holds your proxy token, so Codex CLI needs no API key of its own. If the console shows no personal address, use a named API key.

Before you start#

You need a memtrunk account. The request still needs a provider account or provider key that you may use.

The console guide for Codex CLI is on the Dashboard. The guide opens by default when you own no account or the Dashboard sees no request from the last 14 days. It starts closed if an admin turned off your access to usage data. To open a closed guide, select Setup guide.

The guide shows the tool tabs after you connect at least one account of your own. A tab appears for each provider where you can see an account. You see your own accounts and accounts that your org or an admin shared. Select the Codex CLI tab. Step 2, Connect Codex CLI, shows your personal address. Your personal address is also on the Proxy connection card on the Connection tab of your Profile page.

The collapsed section Use a named API key instead can create a key that the guide names after the tool, for example Codex CLI.

Add the provider#

Add this table to ~/.codex/config.toml. On Windows the file is %USERPROFILE%\.codex\config.toml. The console scripts use the CODEX_HOME folder instead when that variable is set.

toml
[model_providers.memtrunk]
name = "memtrunk"
base_url = "https://memtrunk.your-host.dev/<your-proxy-token>/v1"
env_key = "MEMTRUNK_API_KEY"
wire_api = "responses"
SettingMeaning
base_urlYour personal address followed by /v1. Use no trailing slash.
env_keyThe name of the environment variable that holds the key.
wire_apiThe request format. The console guide sets it to responses.

The console hides the token until you select Show. Copy puts the real address in the text it copies.

Set the placeholder key#

Codex reads a key from the variable that env_key names. The guide sets the variable to the text placeholder. memtrunk ignores the value on your personal address. In macOS or Linux, run:

bash
export MEMTRUNK_API_KEY="placeholder"

In Windows PowerShell, run:

powershell
$env:MEMTRUNK_API_KEY = 'placeholder'

To keep the variable, the console guide appends the export line to ~/.zshrc. Use ~/.bashrc if your shell is bash. On Windows, the guide saves a user environment variable.

Select the provider#

You have two choices.

Make memtrunk the default#

Add this line to config.toml as the first line, above every [section]:

toml
model_provider = "memtrunk"

Choose memtrunk for one run#

Add the provider table and set the placeholder key, but skip the default line. According to the setup guide, Codex keeps using your own login until you ask for memtrunk:

bash
codex -c 'model_provider="memtrunk"'

The console guide says a project .codex/config.toml cannot choose the model provider, so a repository cannot redirect your credentials.

Request paths#

With your personal address, a Codex CLI request goes to POST /<your-proxy-token>/v1/responses. The gateway also serves POST /<your-proxy-token>/responses.

The gateway reads no key header on a personal address.

Verify the connection#

  1. Set MEMTRUNK_API_KEY in the shell where you start Codex.
  2. Run codex exec --skip-git-repo-check "Reply with OK if you can hear me".
  3. Open Request logs in the console. The request appears after a short delay. If an admin switched request logging off, the page shows no row.

According to Codex's help text, --skip-git-repo-check allows Codex to run outside a Git repository. In the setup guide's test with Codex CLI 0.159.2, a plain codex exec outside one stopped with Not inside a trusted directory and sent no request. With the flag, the run sent one request. Inside a Git repository, the plain command sent one request too.

What the setup guide tested#

The setup guide says it tested Codex CLI 0.159.2 with codex exec against a local test server. Its test command carries --skip-git-repo-check. The guide lists these as not tested: a live provider, other Codex versions, the interactive screen, the per-run command, and Windows and PowerShell. The test record also lists GNU sed in the shell-profile edit, and if the flag changes the sandbox or approval mode, as not tested. Do not read this page as proof that a live provider works through a personal address.

Troubleshooting#

SymptomCause and fix
404 on the personal addressThe token is unknown or disabled. Copy the address again from the Proxy connection card. After a rotation, use the new address.
429 with a Retry-After headerMany requests with an unknown token came from one IP address. Wait for the Retry-After time and try again. A valid token is not blocked, except within 10 seconds of creating or rotating it.
429 Monthly spend limit reachedA monthly USD limit applies. The reply has a Retry-After header. Ask your admin.
401 API key requiredWith a named key, the request carries no key. Set MEMTRUNK_API_KEY in the shell that starts Codex.
401 Invalid API keyWith a named key, the key is wrong, disabled or expired. Create a key on the API keys page.
401 Invalid API key plus a hint about a proxy tokenWith a named key, the key looks like a proxy token. The 401 reply names the mix-up. Use a memtrunk key.
401 with authentication_errormemtrunk found no provider account or provider key for the request. Ask your admin.
Codex still uses your own loginmodel_provider is not memtrunk. Add the default line, or start Codex with the -c option.
Not inside a trusted directorycodex exec ran outside a Git repository. Add --skip-git-repo-check or run it inside one.

The setup guide warns that Codex can print the full address, token included, after a failed request. The config.toml file also holds the token. Treat both like a password. If the address leaks, rotate the token on the Proxy connection card.

Use a named API key instead#

A named key has its own name, its own limit and a credential that you can revoke. Create the key on the API keys page.

With a named key, set base_url to the memtrunk address plus /v1.

toml
[model_providers.memtrunk]
name = "memtrunk"
base_url = "<your-memtrunk-address>/v1"
env_key = "MEMTRUNK_API_KEY"
wire_api = "responses"

In macOS or Linux, run:

bash
export MEMTRUNK_API_KEY="<your-memtrunk-key>"

In Windows PowerShell, run:

powershell
$env:MEMTRUNK_API_KEY = '<your-memtrunk-key>'

With a named key, a request goes to POST /v1/responses. The gateway reads the key from an Authorization: Bearer header or an x-api-key header.

Put the proxy token only in the address path of the personal address.

Remove memtrunk from Codex CLI#

Delete the [model_providers.memtrunk] table and the model_provider line from config.toml. Then remove the MEMTRUNK_API_KEY variable. Codex returns to your own login.

Next steps#