Artifact cf36e871d1a66cefa7b259b3f266d7ca5c5033d95783d8916c29be1aeb228084:
- File docs/manual/sign-in.md — part of check-in [5a87f014be] at 2026-11-22 14:09:24 on branch oauth-login — Login in the terminal interface in place: provider picker, masked key and passphrase entry, sign-in with cancel; review fixes: token sent only to its own API, browser opener by absolute path, no echo of the pasted address, idle callback connections dropped fast, real listen errors, OpenRouter paste bound to the redirect, rotation write retried (user: pi-c-agent, size: 3516) [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 the store's passphrase is asked for 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.
The provider's variable (OPENAI_API_KEY) still wins when it is set. 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.