Artifact bec145e076cdfa981e3ad47ee2f5377fb33d1e1ff47ad757592820f531e701c3:
- File docs/design/named-keys.md — part of check-in [d7a1186cd2] at 2026-11-22 22:53:27 on branch keys-probes — Free key checks: a probe on the provider adapter, pic auth status --check/--refresh, background checks in the terminal interface (user: dmestas, size: 3726) [annotate] [blame] [check-ins using] [more...]
Named keys and remembered health
Status: adopted 2026-11-22 (option B of the keys proposal); landings 2 to 4 built: failure classes, remembered health, named keys, the swap prompt, and free checks through a probe on the provider adapter.
Tier: core records (cred.c, http.c, provider_http.c, the journal's credential column);
bundled decides (keyhealth.c) and checks (keyprobe.c, and each adapter's probe). Clock: vendor
(error wording, rate-limit headers, balance endpoints). Record: picu_credential_health per
credential name (state, reason, status, until, checked, remaining and its unit, probed),
pic_generation.credential per request. Default: the bundled reading of refusals, registered by
the composition root; checks only on pic auth status --check, /key and terminal start.
The decisions
- Stored beats the variable, and pic says so (landed before this note).
- A refusal is read into a class and remembered per key: refused (401, 403), out of credit (402,
Anthropic's
billing_errorand "credit balance is too low" as 400 or 402, OpenAI'sinsufficient_quota, OpenRouter's 402), limited until a time (a 429 whoseretry-after, or Anthropic's or OpenAI's reset headers, say a minute or more), transient (5xx, 529, a short 429: retried as before), other. The first three are never retried blindly. - Extra keys are rows
provider:labelinpicu_credential, sealed under their own names; the provider's existing row stays its default with no reseal. The active label is the settingactiveKey:PROVIDER;--keyoverrides it for one process. - Ask, never fail over. With
--hold-key-failures(the terminal interface's children) a refusal of the first three classes fails the attempt and leaves the request unfinished; the interface asks. The choice is a setting written before the next request, and the next request asks the turn again as attempt N+1, so it fits "a generation started, no reply: failed, the turn is asked again" (durability). Each attempt still counts toward the turn's three.
The seam
Core reaches the vendor wording only through pic_cred_failure_ops (cred.h: classify and message),
registered by main.c beside the sign-in flows; with nothing registered core classifies by status
alone. The rows are data in keyhealth.c, so wording that drifts is a table edit. The probe for
free checks is not on that interface after all: what to ask is the wire API's, so it is the
adapter's probe (pic_provider_probe, provider_http.h) and keyprobe.c runs it.
Free checks (landing 4)
- Free checks only on demand, and never a request that spends tokens. OpenRouter's
GET /keygives what the key may still spend, DeepSeek'sGET /user/balancethe balance; Anthropic, OpenAI, Google and the rest get their models list, which says valid or refused (and carries rate-limit headers, recorded in the row's reason). A check sends the key only to the base URL the provider's requests use, never a conversation, and reads a refusal as a request's is read. It runs onpic auth status --check, on opening/key, and once at terminal start for the active key (background child, two seconds,--refresh); never in print, JSON or RPC mode; never more than once per key in ten minutes unless--check. A models list does not undo a recorded out-of-credit or limit, since it cannot see credit. A locked store's keys are skipped by a background check: it never asks for the passphrase.
Not verified
Whether rate-limit headers come on error replies of every provider; whether two keys of one Anthropic workspace share a prompt cache (the prompt always shows the uncached price).