Skip to content
pi-c Artifact [fe78878c6a]
Login

Artifact [fe78878c6a]

Artifact fe78878c6ae3dd34494ec0aede1221670b70b8fb6d05730d35bfd3f84d1c8d5d:


Credentials

The web_search tool's key is stored the same way, as pic login brave-search, or read from BRAVE_API_KEY (web search).

API keys come from pic's credential store or from the environment (ANTHROPIC_API_KEY, OPENAI_API_KEY, OPENROUTER_API_KEY, ...), as in Pi.

pic login anthropic          # the key, typed with echo off (or piped on stdin), sealed into ~/.pic/pic.sqlite
pic keys                     # stored keys: names and dates, never values
pic logout anthropic         # remove it

A key's leading and trailing spaces and line breaks are dropped before it is stored; one with a space or line break in the middle is refused, and so is a value that is plainly a file path or a web address. A saved key is checked with its provider at once, free of charge (nothing of a conversation is sent): a refusal is said in words with the command that forgets the key, and the key stays saved. offline turns the check off. Typing a whole API key as a message at the prompt holds it: Enter again sends it.

/login [PROVIDER] and /logout [PROVIDER] do the same in the terminal interface. A provider with a subscription sign-in can use that instead of a key: see subscription sign-in.

The lookup order

As in Pi, a stored credential owns its provider. A request uses the first of these that exists:

  1. the key chosen for the provider, with --key for one run or pic auth use (or /auth) from now on; see several keys;
  2. the credential stored with pic login or pic auth login (an API key or a sign-in), else the provider's oldest key stored with --as;
  3. the apiKey written in models.json;
  4. the provider's environment variable.

If none exists the request fails with an error naming pic login. A stored credential that cannot be used (a damaged row, a sign-in whose refresh failed) is an error; pic does not quietly fall back to the variable. So an exported variable that is out of credit or stale never hides a key you stored; pic logout PROVIDER returns the provider to its variable. When a stored key is refused while its variable is set, the error says the variable was not the one used.

pic auth status lists every key, marks the one in use, and says of a variable a stored key hides not used: a stored key wins; the provider list in /login says the same.

The store

Each stored key is sealed with ChaCha20-Poly1305 (the provider's name bound as associated data), so no plaintext key reaches the database, its WAL, a backup or a log. The sealing key is kept apart from the database, in one of three places:

Where When Asks you
your login Keychain (macOS), or your keyring (Linux with secret-tool) the default for a new store nothing
~/.pic/master.key, readable only by you when there is no keychain, or it refuses (locked, over ssh) nothing
a passphrase when you choose it: pic auth rekey passphrase the passphrase, once per process

pic fetches the key the first time a stored key is needed and keeps it only for the life of the process; the terminal interface hands it to its request processes through an inherited pipe, never argv, the environment's values or a file. A key file is excluded from Time Machine, and pic refuses one that others can read.

What this protects against: a copied pic.sqlite, a backup of it or an exported journal reveals no key on its own. What it does not: anyone or anything that can act as you while you are logged in (malware, someone at your unlocked session) can read the Keychain item or the key file and open the store, as they can with the keys other tools keep. A passphrase also guards against that, at the cost of typing it; FileVault or disk encryption covers a stolen disk.

Moving the key

pic auth rekey keychain, pic auth rekey file or pic auth rekey passphrase moves the key: every stored key, sign-in and remote control key is sealed again under a new key in one step, and the old place is cleared only once that has succeeded. A store with a passphrase keeps working as before. When you type its passphrase at a prompt, pic asks once whether to stop asking:

Stop asking for this passphrase? pic can keep the key in your Keychain. [y/N]

y moves the key there; anything else keeps the passphrase and is remembered, so it is not asked again. pic auth rekey passphrase goes back at any time.

A passphrase can also come without a terminal: --passphrase-fd N reads it from descriptor N, and the command in PIC_PASSPHRASE_COMMAND (or the setting passphraseCommand) prints it, for example op read op://Private/pic/password.

With no terminal

Where nothing can ask for the passphrase (cron, CI, a git hook, ssh -T), a request whose key is sealed fails at once with one line naming the ways out, and nothing is saved for it:

export ANTHROPIC_API_KEY=...         # in the shell that has the key
pic auth use anthropic env           # from now on, requests to anthropic use the variable

Once chosen, the variable is used wherever it is set, with no passphrase; where it is not set, requests fail and say so. pic auth use anthropic default goes back to the stored key. RPC mode never asks on a terminal either: see RPC mode.

A forgotten passphrase

The passphrase cannot be recovered, and nothing sealed under it can be opened without it. pic auth reset forgets it with everything sealed under it: the stored keys and sign-ins and the phones paired for remote control. Settings, sessions and trusted folders stay. It asks first; with no terminal to ask on it needs --yes. The next pic login sets a new passphrase, and phones pair again with pic remote pair.

How the key is derived and where it is kept is in the architecture notes.