GuidesHosting choices

Pi "No API key found": signing in on a server

Pi's "No API key found" on a server: sign in with pi auth login --no-browser by a copied code or device code, save an API key, or check it from a script.

November 14, 2026The Everpod team
The short answer

“No API key found for the selected model” means Pi has no credential for any model provider yet: no saved sign-in, no saved key, and no key in the environment. On a server with no browser, sign in from the shell with pi auth login <provider> --no-browser, which gives Anthropic a code to copy and OpenAI Codex a device code, or save a key with pi auth login <provider> --api-key, or export the provider’s variable, such as ANTHROPIC_API_KEY. Pi keeps what you save in ~/.pi/agent/auth.json, and pi auth check --provider <provider> exits 0 once a script can run. pi auth login arrived in Pi 1.5.1 (November 9, 2026); older versions sign in only with /login inside Pi.

What you see

On Pi 1.5.2 with nothing connected, a one-shot run stops at once and exits with status 1:

$ pi -p "say hi"
No API key found for the selected model.

Use /login to log into a provider via OAuth or API key. See:
  …/pi-coding-agent/docs/providers.md
  …/pi-coding-agent/docs/models.md
Copied

The two paths point at the docs inside your own install. When no provider can be worked out, the message says “the selected model”; in Pi’s source the same message names the provider instead (“No API key found for anthropic.”) when it knows which one the model needs, so that form means the model you picked belongs to a provider you have not connected, even if another one is. pi --list-models says the same thing another way: “No models available. Use /login to log into a provider via OAuth or API key.”

The message suggests /login, which works in Pi’s full-screen interface. On a server you can do the same without starting a session, and from a script you have to, which is what pi auth is for. There is no pi auth status; the check is pi auth check, below.

Signing in with no browser

Pi’s CLI reference gives the command as pi auth login <provider> [--api-key] [--no-browser]. Without a flag it signs in with an account and opens a browser, which a server does not have; with --no-browser it uses “the provider’s other sign-in method, such as a device code, for example over SSH.” Where a provider has exactly one other method, Pi picks it without asking; where it has several, it asks. Each provider’s methods, as Pi 1.5.2’s source lists them:

Provider (id)What --no-browser does
Anthropic, Claude Pro or Max (anthropic)
“Copy code login (headless)”: open the link on any device, sign in, and paste back the code Anthropic shows
OpenAI Codex, a ChatGPT plan (openai-codex)
“Device code login (headless)”: enter a one-time code at auth.openai.com/codex/device within 15 minutes
GitHub Copilot
A device code always, browser or not
OpenAI’s Sign in with ChatGPT (openai)
No other method: sign in on another device, then paste the address the browser ends on back into Pi

A provider id you get wrong is answered with “Unknown provider” and the list of providers that can log in, so the list is one mistyped command away. Two rules from the reference matter on a server: the command “requires an interactive terminal,” so it runs in your SSH session, never from cloud-init or a cron job, and --no-browser cannot be combined with --api-key.

Anthropic: a code to copy

pi auth login anthropic --no-browser
Copied

Pi prints “Open this URL to sign in:” and the link. Open it on your laptop or phone, sign in, and Anthropic shows a code; Pi’s prompt is “Paste the code Anthropic shows after you sign in:”, and the code has the shape code#state. Before pi auth existed, the same choice was the second option in /login’s Anthropic menu, under “Browser login (default)”, and it still is. If you take the browser login on a server anyway, its own instruction applies: “If the browser is on another machine, paste the final redirect URL here.” How the usage from this sign-in is billed, and what Anthropic’s terms say about a Claude plan in a third-party agent, are covered in using a Claude subscription in Hermes, Pi or OpenCode.

OpenAI Codex: a device code

pi auth login openai-codex --no-browser
Copied

Pi prints a line of the form “Open … and enter code: …”, then “Waiting for authentication...”. Open auth.openai.com/codex/device on any device, sign in with the ChatGPT account, and type the code; Pi stops waiting after 15 minutes. Pi lists this provider as “OpenAI Codex”, separately from its newer Sign in with ChatGPT under the openai provider, and only the Codex one has a device code. That newer sign-in listens on port 1455, and on a machine that also runs the Codex CLI, Pi warns that the port “is in use, probably by an unfinished login in another pi session or by the Codex CLI.”

On success either login ends with “Logged in to” the provider’s name and “Credentials saved to” the path of auth.json.

An API key instead

For a key, the same command takes --api-key, and the reference says “the key is read without echoing it,” so it does not land in your shell history:

pi auth login anthropic --api-key
Copied

Pi also reads keys from the environment without saving them, which its providers page recommends “in CI and anywhere Pi should not store the key”:

export ANTHROPIC_API_KEY=sk-ant-...
pi
Copied

The variable for each provider is in that page’s table: ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY and OPENROUTER_API_KEY among more than thirty. A variable set in your login shell is not set for a systemd unit or a cron job, which start with their own environment, so a key that works when you type pi can still produce “No API key found” when the same command runs on a timer. For one run only, pi --api-key <key> overrides without saving, and it needs a model chosen with --model. A saved key can also be a command rather than the key itself: in auth.json, a key that starts with ! is run when the key is first needed, which lets a secret manager hold it.

Checking from a script

pi auth check prints ready, not_ready or invalid and exits with 0, 1 or 2 respectively. It needs --provider or --model, refreshes an expired sign-in unless you pass --no-refresh, and with --json writes the result as JSON. A script that runs Pi unattended can test before it starts, so a missing credential fails with a clear status rather than the message above:

pi auth check --provider anthropic || exit 1
pi -p "summarise the changes since yesterday"
Copied

not_ready covers both a provider with nothing configured and a provider name Pi does not know; invalid means the credential or Pi’s own state could not be read. Since pi auth login needs a terminal, the order on a new server is to sign in once over SSH and let the scheduled runs reuse what it saved.

Where the credential lives

Saved keys and sign-ins go to ~/.pi/agent/auth.json, which Pi’s installer creates with mode 600 (readable by your user only); the providers page says it “can contain API keys and OAuth tokens. Keep it private and do not commit it.” The folder moves if you set PI_CODING_AGENT_DIR, which also means a job that runs as another user, or with that variable pointing elsewhere, sees a different auth.json and reports no key. pi auth logout <provider> removes what was stored and leaves environment variables alone, so a key exported in your shell keeps working after a logout. The rest of Pi’s files and what it is for are in what Pi is, and how its sign-ins compare with OpenCode’s on a server is in Pi vs OpenCode.

Run the Pi coding agent on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.