Skip to content
BENIBIX Learn

apiKeyHelper

AI⌨️ Claude CodeConfiguration

Also known as apiKeyHelper setting, CLAUDE_CODE_API_KEY_HELPER_TTL_MS

A command that hands Claude Code a fresh API key.

Think of it like

It is like a key cutter by the door. It makes a fresh key when the old one stops working.

Example

Jack's company hands out keys that last one hour. His apiKeyHelper fetches a fresh one, so his sessions never stop on an old key.

Why it matters

It lets keys that change often work without you pasting a new one.

Definition

apiKeyHelper is a settings key that names a shell command, which hands Claude Code its API key. The command prints the key that Claude Code sends to the model, in the X-Api-Key and Authorization headers. Claude Code keeps the key five minutes by default, then runs it again. CLAUDE_CODE_API_KEY_HELPER_TTL_MS changes that time. A 401 or 403 reply makes it run again too.

Example code

json
{
  "apiKeyHelper": "~/bin/get-claude-key.sh"
}
Fetch the key from your own script.

Common mistake

Printing other text from the script. Its whole output is sent as the key, so print the key alone.

Key takeaways

  1. 1
    Runs your command. Output is the key.
  2. 2
    Cached five minutes. Then again.
  3. 3
    Reruns on 401. Or 403.