Artifact 7c9b84d8422685c0fced7326146391dc00f786ad4bdea9417651485cf3f8f961:
- File
docs/manual/sign-in.md
— part of check-in
[bcb82b941e]
at
2026-11-23 11:55:36
on branch keysource
— Keep the credential store's key in the Keychain or a key file, not behind a passphrase
A new store gets a random 32-byte master key kept in the login Keychain (macOS, /usr/bin/security run as a child with the command on stdin) or the keyring (secret-tool), else ~/.pic/master.key at 0600. The source is recorded in picu_credential_key.source; a passphrase store keeps working as before. pic auth rekey keychain|file|passphrase reseals every sealed row in one transaction, and a typed passphrase is followed once by the offer to stop asking. --passphrase-fd and PIC_PASSPHRASE_COMMAND (setting passphraseCommand) give a passphrase with no terminal. pic remote opens a keychain or file store with no prompt. Every OS service stays in platform.c behind secret_key, secret_keep and secret_drop. (user: dmestas, size: 3574) [annotate] [blame] [check-ins using] [more...]
Subscription sign-in
A provider that lets other programs use its subscription can be signed in to instead of given an API key. pic has two: OpenAI's Sign in with ChatGPT, which lets a ChatGPT plan pay for pic's requests to the OpenAI API, and OpenRouter's, which signs in and hands back an ordinary API key (stored as one).
pic auth login openai # opens the browser; sign in to ChatGPT and approve pic
pic auth login openai --no-browser # prints the address; paste back where the browser ends up
pic auth status # what is stored, how it signs in, when it was last used
pic auth logout openai # remove the sign-in
In the terminal interface, /login lists the providers and what each uses now; choosing one with a
sign-in offers it beside an API key, and so does the first message when the model's provider has no
credential at all. The sign-in runs in place: the address to open, a field for pasting the address
the browser ends on, and Esc or Ctrl-C to cancel it. pic login openai on a terminal offers the
same choice; Ctrl-C ends pic auth login.
How it works
pic opens the provider's sign-in page in the browser (open on macOS, xdg-open elsewhere) and
waits for the browser to come back to a one-time address on this machine (127.0.0.1, port 1455 for
OpenAI, a free port for OpenRouter). Only a redirect that carries the sign-in's own random state
(for OpenRouter, its random path) is taken, once; anything else is refused. If the browser runs on
another machine, it cannot reach that address: copy the address it ends on and paste it at pic's
prompt. A sign-in that is not finished within five minutes is given up.
The sign-in's tokens are sealed in ~/.pic/pic.sqlite exactly as an API key is (see
credentials), so a store with a passphrase asks for it first. pic never prints or
logs a token. The access token is refreshed shortly before it expires, and again if a request is
refused with it; one pic process refreshes at a time, so several running at once share the new
token. A refresh that fails (the sign-in was revoked, say) names pic auth login to sign in again.
A sign-in is used before the provider's variable (OPENAI_API_KEY): see the lookup
order. A sign-in's token is sent only
to its provider's own API (https://api.openai.com/): if models.json points the provider
elsewhere, pic refuses the request and says so rather than send the token there. When you paste an
address, paste all of it; for OpenRouter a bare code is refused, since the address is what ties it
to this sign-in. A ChatGPT plan's usage limits apply to requests made this way, and some request
settings the API takes with a key (a 24-hour prompt cache) are left out.
Which providers
Pi signs in to more providers. pic offers only those whose terms let a third-party program use the subscription; the others reuse another product's client id, or their providers forbid it:
| Provider | In pic | Why |
|---|---|---|
| OpenAI (ChatGPT) | yes | Sign in with ChatGPT is OpenAI's program for open-source agents |
| OpenRouter | yes | OpenRouter documents its PKCE sign-in for third-party apps |
| Anthropic (Claude Pro/Max) | no | Anthropic's terms keep subscription sign-in to its own apps |
| OpenAI Codex, GitHub Copilot, xAI, Meta, Kimi | no | each reuses its first-party tool's client id; no published permission |
The device-code flow (sign in on another device with a short code) is built in for a provider that offers it; none of these does yet.