Artifact 58eeee5c1940d4e8d9ee78ad24b53ff79625f2e2dde953369a7f1fb04dffc283:
- File
docs/manual/sign-in.md
— part of check-in
[19ef27d450]
at
2026-11-22 15:41:12
on branch cred-order
— A stored key or sign-in now takes precedence over the provider's environment variable, as in Pi
pic_cred_get and pic_cred_source_of resolve a stored credential first, then the models.json apiKey, then the variable. auth status and the /login list name the source in use and any variable it hides. (user: pi-c-agent, size: 3572) [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). ```sh 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](credentials.md)), 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. A sign-in is used before the provider's variable (`OPENAI_API_KEY`): see [the lookup order](credentials.md#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.