Artifact 12210a406482b0d07f0f722dbf9fd240dc0e509b7c24a299b047b351f6147d2d:
- File docs/manual/sign-in.md — part of check-in [fcc6715760] at 2026-11-22 13:22:47 on branch oauth-login — Subscription sign-in: OpenRouter, RPC login/logout/get_auth_status, docs, changelog, escape-safe provider errors (user: pi-c-agent, size: 2952) [annotate] [blame] [check-ins using]
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 offers the sign-in beside an API key, and so does the first
message when the model's provider has no credential at all. pic login openai on a terminal offers
the same choice.
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 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.