# apiKeyHelper

> A command that hands Claude Code a fresh API key.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** apiKeyHelper setting, CLAUDE_CODE_API_KEY_HELPER_TTL_MS

## Think of it like

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

## 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

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.

## Example code

```json
{
  "apiKeyHelper": "~/bin/get-claude-key.sh"
}
```

Fetch the key from your own script.

## Why it matters

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

## Common mistake

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

## Three principles

- **Runs your command.** Output is the key.
- **Cached five minutes.** Then again.
- **Reruns on 401.** Or 403.

## Related terms

- [ANTHROPIC_API_KEY](https://learn.benibix.com/term/ai/anthropic-api-key-variable)
- [LLM Gateway](https://learn.benibix.com/term/development/llm-gateway)
- [env Setting](https://learn.benibix.com/term/ai/env-setting)

---

Source: https://learn.benibix.com/term/ai/api-key-helper-setting
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
