Artifact 83d5ec5a5b15e9e8b98b5ee542d7e5c5f412c274188c3ce737b65ea1cc2fe87b:
- File docs/manual/named-keys.md — part of check-in [8126e0f29c] at 2026-11-22 20:36:15 on branch keys-b — Named keys after review: --key follows the provider the model resolves to and an unknown key is an error; a choice in the terminal replaces its --key; a quoted key is scrubbed anywhere; provider names with ':' or past 63 bytes are refused; import asks --force for another variable; set_credential is per process; merge trunk (the RPC command registry) (user: pi-c-agent, size: 4329) [annotate] [blame] [check-ins using] [more...]
Several keys and their health
A provider can have more than one key: a second Anthropic key on another account, a key kept for a team. Each has a name; one is the provider's active key, and pic remembers what the last reply said of each.
pic auth login anthropic --api-key --as second # another key, named second
pic auth use anthropic second # requests use it from now on
pic -p 'hello' --key default # the provider's own key, for this run only
pic auth import ANTHROPIC_API_KEY_2 --as spare # seal a variable's value once; it can go
pic auth logout anthropic:spare # remove one key
pic auth status # every key, the active one marked *
--key names a key of the provider the model belongs to (a bare claude- model id is
Anthropic's); a key that provider does not have is an error, never a quiet fall back to another.
The key pic login has always stored is the provider's own, named default. env is the
provider's environment variable and file the key written in models.json, so either can be
chosen by name too. With nothing chosen, a request uses the provider's own key, else its oldest
named one, else the models file's, else the variable: the lookup order.
What pic remembers
Every reply tells pic something about the key that sent it. pic keeps the last word per key, never the key itself:
$ pic auth status
anthropic default API key out of credit since 14:02 (HTTP 402)
anthropic second* API key ok, checked 2 min ago
anthropic env ANTHROPIC_API_KEY not used: a stored key wins
- refused: the provider turned the key down (401, 403). It may be revoked or mistyped.
- out of credit: the account has no credit or quota left (Anthropic's billing error, OpenAI's quota error, OpenRouter's 402). Waiting does not help.
- limited until a time: a rate limit that says to wait a minute or more.
- A short rate limit or an overloaded server is retried, as before, and changes nothing.
None of these is retried blindly, and pic never moves to another key on its own: a swap costs money and starts the prompt cache again, so you decide. Anthropic and OpenAI give an API key no balance to ask for, so pic learns that a key is out of credit from its first failure, then remembers it.
A variable's state is kept under its name and a salted hash of its value: a new value starts with no state.
In the terminal interface
/key (Alt+K) lists every provider's keys with their state; Enter makes one its provider's active
key, from the next request. The footer names the key (ยท key second) when the provider has more
than one or uses its variable, and warns in red when one is known to be bad (! out of credit,
! limited until 15:45).
When a reply is refused for its key, the request stops where it is and asks:
The key "default" is out of credit. Nothing was lost.
s retry with "second" (re-sends 84k tokens uncached, about $0.31)
m another model
esc stop
smakes the other key active and asks again; another key may not share the prompt cache, so the price shown is the conversation sent again uncached.mstops the request and opens the model picker; send a message to go on.w, for a limit, waits until it lifts and goes on.l, for a refused key, opens the login for it; then Enter retries.- Esc stops the request; its message stays in the conversation. Enter tries the same key again.
A choice applies from the next reply request, never to one already sent. Print mode and RPC mode
never ask: the request fails with the same plain sentence, such as
The key "default" for anthropic is out of credit (HTTP 402: ...).
A choice in /key or at the prompt also replaces what --key chose for that provider when the
terminal interface was started.
RPC clients can list keys with get_credentials and choose one for their own process with
set_credential (RPC commands).
A provider's error that quotes a key, whole or in part (its first eight or last four characters), is
shown and kept with that part replaced by [key]. Provider names may not contain :, which
separates a provider from a key's name.