Connect Claude Code to memtrunk
Connect Claude Code through your personal token address, or with a named API key. Set the variables, verify the connection and fix 401, 404 and 429 errors.
Last updated
Claude Code connects through your personal address. The address holds your proxy token, so Claude Code needs no API key. If the console shows no personal address, use a named API key. The console setup guide writes the same values.
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 Claude Code 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 Claude Code tab. The tab has three steps:
- Subscription connected or Subscription available.
- Connect Claude Code. This step shows your personal address.
- Send your first prompt, or Send a test prompt after the first request.
Find your personal address in step 2. It is also on the Proxy connection card on the Connection tab of your Profile page. The guide creates no key for Claude Code by default.
Set the variables#
| Variable | Value |
|---|---|
ANTHROPIC_BASE_URL | https://memtrunk.your-host.dev/<your-proxy-token> |
ANTHROPIC_AUTH_TOKEN | placeholder |
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY | 1 |
The address is the host followed by your proxy token as a path. memtrunk ignores the value of ANTHROPIC_AUTH_TOKEN on this address.
The console hides the token until you select Show. Copy puts the real address in the text it copies. Treat the whole address like a password. Anyone who has it can send requests as you. If the address leaks, rotate the token on the Proxy connection card. The old address then returns 404.
The console guide includes CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY. It says the flag turns on model discovery in Claude Code v2.1.129 and later. The console guide says the model list comes from the memtrunk GET /v1/models route.
Choose where to set them#
One terminal session#
The values last until you close the terminal. In macOS or Linux, run:
export ANTHROPIC_BASE_URL="https://memtrunk.your-host.dev/<your-proxy-token>"
export ANTHROPIC_AUTH_TOKEN="placeholder"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"In Windows PowerShell, run:
$env:ANTHROPIC_BASE_URL = 'https://memtrunk.your-host.dev/<your-proxy-token>'
$env:ANTHROPIC_AUTH_TOKEN = 'placeholder'
$env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY = '1'Your user settings file#
Add an env block to ~/.claude/settings.json. On Windows the file is %USERPROFILE%\.claude\settings.json. This setting covers every project that you open with Claude Code in a terminal.
{
"env": {
"ANTHROPIC_BASE_URL": "https://memtrunk.your-host.dev/<your-proxy-token>",
"ANTHROPIC_AUTH_TOKEN": "placeholder",
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
}
}One project#
Add the same env block to .claude/settings.local.json inside the project. Add that file to .gitignore so your token URL is not committed. Do not put the token URL in .claude/settings.json. Git shares that file with everyone who clones the repository.
Your shell profile#
The console guide also offers a shell profile. It appends the export lines to ~/.zshrc. Use ~/.bashrc if your shell is bash. Only sessions that start from a terminal read the profile. On Windows, the guide saves the variables as user environment variables.
Verify the connection#
- Start Claude Code from a shell or a settings file that holds the values.
- Run
claude -p "Reply with OK if you can hear me". - 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. The Usage page can show the request instead, if the console offers that page to you.
Token URL requests appear in your usage under your account. They carry no API key.
The console guide suggests the /status command inside Claude Code. Run /status to see which credential is active.
Use a named API key instead#
A named key has its own name, its own limit and a credential that you can revoke. Use one for scripts and SDKs. The guide shows these steps in the collapsed section Use a named API key instead. It also shows them when the console shows no personal address. Create the key on the API keys page.
| Variable | Value |
|---|---|
ANTHROPIC_BASE_URL | <your-memtrunk-address> |
ANTHROPIC_AUTH_TOKEN | <your-memtrunk-key> |
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY | 1 |
With a named key, set ANTHROPIC_BASE_URL to the address with no path. Use no trailing slash. Set ANTHROPIC_AUTH_TOKEN to the key. The gateway accepts a key in an Authorization: Bearer header or an x-api-key header.
An API key and a proxy token are two different credentials. In this form, put the API key in ANTHROPIC_AUTH_TOKEN. Put the proxy token only in the address path of the personal address.
Use the same places as above. In macOS or Linux, run:
export ANTHROPIC_BASE_URL="<your-memtrunk-address>"
export ANTHROPIC_AUTH_TOKEN="<your-memtrunk-key>"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"Do not put the key in .claude/settings.json. Add .claude/settings.local.json to .gitignore if you store the key there.
Troubleshooting#
| Symptom | Cause and fix |
|---|---|
| 404 on the personal address | The 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 header | Many requests with an unknown token came from one IP address. Wait for the Retry-After time and try again. A valid token from the same address is not blocked. A token created or rotated less than 10 seconds ago can still get 429. |
429 Monthly spend limit reached | A monthly USD limit applies. The reply has a Retry-After header. Ask your admin. |
401 API key required | The request carries no key. In the key form, set ANTHROPIC_AUTH_TOKEN in the shell or file that Claude Code reads. |
401 Invalid API key | The key is wrong, disabled or expired. Create a key on the API keys page. |
401 Invalid API key. This value looks like a proxy token. Put the proxy token in the URL path, not in the key. | The key field holds a proxy token. Move the token into the address path. |
401 with authentication_error | memtrunk found no provider account or provider key for the request. Ask your admin. |
| The model picker lists no memtrunk models | The console guide says the flag turns on model discovery in Claude Code v2.1.129 and later. Check the version and check that the flag is 1. |
| Claude Code still uses your claude.ai login | The console guide says a set ANTHROPIC_AUTH_TOKEN stops the fallback to that login. Run /status to see which credential is active. |
Remove memtrunk from Claude Code#
Delete the three variables from the place where you set them. Then restart any open Claude Code session. Claude Code then returns to your own login.
Next steps#
- Read authentication headers for the accepted key headers.
- Read client variables for all client settings.
- Read spend limits for what a token URL changes.
- Read usage and cost to follow what Claude Code spends.