One key, three fields, and a green check mark
Your workspace is installed, and typing into it does nothing useful yet: it has no AI provider. This article gets you one — an OpenRouter account and key, then the three settings that turn that key into a working route.
Pi Agent supplies the workshop, not the engine
Pi Agent uses BYOK — bring your own key. The add-on does not choose an AI service for you and does not pay for one: you open an account, create a key, and paste it in. Three consequences follow.
Think of a stereo. The amplifier is wired up and the speakers are on the shelf. Nothing plays until you connect a source. This article connects one.
- You pick the model, and can change it later without reinstalling anything.
- You pay the provider directly; the add-on charges nothing.
- The key stays on your hardware, sent only to the provider you configured.
OpenRouter goes first here for three practical reasons: one key reaches model families from several vendors through an OpenAI-compatible gateway; sign-up takes an email address or a supported sign-in provider, with whatever verification its current page asks for; and it is built for API access from many regions, though model and payment availability still vary by country.
It is a gateway, not a model developer: one key reaches a catalog that changes over time, where a direct provider gives you its own catalog only, and data handling follows OpenRouter's terms plus the selected model provider and your privacy settings. No provider is best at every task, and many people keep two or three — that is Part 6. For now, one working key is the whole job.
A short string of text that spends money
An OpenRouter key is a secret string that normally begins with sk-or-v1-. Pi Agent sends it with every request; OpenRouter checks it, charges the usage to your account, and routes the request to the model you chose.
It works like the order card on a restaurant table. It identifies the table, not you, and everything written on it lands on one bill. Anyone who picks it up can order.
Since Pi Agent v0.13.0, provider keys are stored locally in /data/pi-agent/models.json on your Home Assistant host, in the add-on's persistent data. WoowTech does not receive the key, but anyone with sufficient access to the host or that data can read the file.
flowchart LR A["Your browser"] --> B["pi-web on your HA host"] B --> C["/data/pi-agent/models.json
where the key is stored"] B --> D["https://openrouter.ai/api/v1
the endpoint you configure"] D --> E["The upstream model
that writes the answer"]
Treat it like a payment credential. Three places are safe: Pi Agent's Models panel; a password manager such as 1Password, Bitwarden, Apple Passwords or KeePass, with a strong master password and multi-factor authentication; and an encrypted offline backup whose restore you have tested. Keep it out of these:
- Public repositories. Scanners find exposed keys fast, and deleting the latest commit is not enough if the value stays in the Git history.
- Chat and community groups. Other participants and the service may keep the message.
- Shared documents. Link-sharing settings are easy to misconfigure, and they change later.
- Ordinary email. Do not send an API key as email.
- Screenshots and recordings. Text too small to read is still readable by OCR.
- Support posts. Use an obviously fake example and redact the whole secret, not just its tail:
sk-or-v1-REDACTED.
Appendix B says credentials are redacted in logs at debug level as ***. Read a log yourself before sharing it anyway.
apiKey and Save. Review your usage and account activity for requests you do not recognize, and if paid credit or account information may be affected, follow the support path shown in your account. Rotation stops future use of the old key; it does not undo requests already made..tar file through a process you trust and restoring it there.Creating the key, on a phone or a computer
Dashboard labels change. Where the wording differs from what is below, follow the site.
-
Step 1
Open the official site
Go to
https://openrouter.ai/settings/keys. Check the address bar reads openrouter.ai, not a look-alike such asopenrouter.example. -
Step 2
Sign in, or create an account
Use a sign-in method OpenRouter currently offers, email or a supported identity provider, and complete any verification it shows. Do not reuse your Home Assistant password.
-
Step 3
Read the privacy and data settings
Do it before adding credit or sending anything private: requests may be handled by the selected model provider, so pick settings and models that suit what you send.
-
Step 4
Open the API Keys page
From the dashboard, open API Keys in Settings. If the labels have changed, follow the current link from the official settings page.
-
Step 5
Select Create Key
OpenRouter may offer an optional credit limit for the key. Set one only if it suits your own budget.
-
Step 6
Give it a name you will recognize later
Name it after the installation it belongs to:
pi-agent-home,pi-agent-office,test-2026-08. Separate keys make rotation and usage review far easier. -
Step 7
Create it, then use the Copy button
Use Copy rather than selecting text by hand, so you do not lose a character. This is the only time the full value is shown; a masked preview such as
sk-or-v1-…cannot recover it. -
Step 8
Put it in your password manager
Save it properly now. A temporary local note is fine — delete it once the setup below is done.
Tokens, credit, and what the account asks of you
OpenRouter measures usage in tokens, and counts vary by language and by model, so do not work out a bill from a word count. Pi Agent sends your prompt and the relevant conversation context with each request, and the answer costs tokens too.
It is metered like water, not like a monthly ticket. A long conversation is a long shower: the meter keeps running because everything said so far gets sent again as background.
Rates and availability change. Read them in the OpenRouter catalog and your own dashboard, not from a figure printed in any guide, including this one.
| What to look at | Where to check it | Worth knowing |
|---|---|---|
| Input tokens | That model's current input rate | Conversation history may be sent again as context |
| Output tokens | That model's current output rate | Long answers consume more output tokens |
| Free model variants | Whether the model ID currently has one | Availability and limits change; do not assume production capacity |
| Account credit | Your balance and payment options | Use only the values in your own account |
Watch real usage rather than inventing a monthly estimate. Cost follows prompt and response length, context length, model choice and, in video workflows, the number of generation steps. Use a per-key limit if the dashboard offers one, and review each workflow's own usage rather than assuming a fixed cost.
A registry of routes, not a list of models
Three small buttons sit at the bottom-left of the workspace sidebar: Models, Skills, Settings. Models opens the settings dialog on its Models tab — a service directory, where each card is one company or gateway you have an arrangement with, holding one endpoint, one credential and its own model entries.
- Add Provider creates another card — once now, again in Part 6 for a second route.
- Test is the control that matters: green means the settings can complete a real request, not just that the form saved.
- Save writes to
/data/pi-agent/models.json, which the documented Home Assistant backup path includes.
Add Provider opens a catalog rather than an empty form, grouped by how a provider connects rather than by brand.
- CUSTOM holds one card — “OpenAI / Anthropic compatible”, subtitled Custom endpoint format. That is the card this walkthrough uses, because it is the one that asks you for an endpoint and a key by hand.
- SUBSCRIPTIONS are all marked OAuth. You sign in to a plan you already pay for instead of pasting a secret — note that OpenRouter appears here too, as
OpenRouter OAuth, which is not the route this article takes. - API KEY cards carry a model count: Amazon Bedrock 121 models, Anthropic 14 models. The number is how many models that one entry can reach.
- OpenRouter, 366 models, sits in this list by name. One account and one key, and the count is the reason this article picked it.
- Single-vendor entries are much smaller — xAI 3, Z.AI 7, Together 21. Each of those needs its own account.
- Radius shows 0 models, so being listed here does not mean there is something to select yet.
Two ways in, then. The OpenRouter card fills the endpoint in for you; this article types it out on the custom card, and the three settings are the same either way.
The key alone does not tell Pi Agent anything
A value beginning sk-or-v1- is only a credential: Pi Agent cannot work out the endpoint, the API mode or the model ID from it. This is a one-time setup; you return to Models only to rotate a key, add a provider, or change the models on offer.
It is an address, a name and an order. baseUrl is where to knock. apiKey is who is asking. models[].name is what you are asking for. Get any one of the three wrong and the door does not open.
| Field | What it means | The OpenRouter value |
|---|---|---|
| baseUrl | The endpoint that receives Pi Agent's requests | https://openrouter.ai/api/v1 |
| apiKey | The secret that authenticates the usage to your account | The complete key from step 7, beginning sk-or-v1- |
| models[].name | The exact catalog ID to request through this route | anthropic/claude-sonnet-4 |
All three must agree. The model ID above is the one verified in the repository for this walkthrough; catalogs change, so confirm it is still listed, and otherwise copy an available model's exact ID.
-
Step 1
Open Models, then take the custom entry
Select Models, then Add Provider, and choose the card under CUSTOM labeled OpenAI / Anthropic compatible. The form has Name, API mode, baseUrl and apiKey, then the Models list.
-
Step 2
Type a Name you will read later
OpenRouteris enough. Pi Agent tells cards apart by Name, not by endpoint, so a second key on the same endpoint needs its own name, such asOpenRouter-office. -
Step 3
Set API mode to openai-completions
The four options are
openai-completions,openai-responses,anthropic-messagesandgoogle-generative-ai. This base URL exposes an OpenAI-compatible Chat Completions interface, so chooseopenai-completions; a mismatched mode returns a 400 or 404 rather than a helpful message. A documented direct Anthropic setup usesanthropic-messages, the Google equivalentgoogle-generative-ai, and a documented OpenAI Responses endpointopenai-responses. Appendix B is the provider reference. -
Step 4
Enter the base URL exactly
Copy
https://openrouter.ai/api/v1with nothing added. Use HTTPS. Do not append/chat/completions, do not leave a trailing slash, and do not paste a dashboard route such as/settings/keys. -
Step 5
Paste the key into apiKey
Paste from your password manager. The field masks the value; the eye control reveals it briefly. Check both ends for a stray space and remove it with Backspace or Delete — whitespace is the most common paste failure here. To read the whole value, use a local text field, never a shared document or anything you might screenshot.
-
Step 6
Add the model, then Test and Save
Select Add Model, enter
anthropic/claude-sonnet-4as the name, and take thecontextWindowfigure from that model's own details page — never from a different model. Then Test: a green check mark means it worked, so Save and close the panel. No restart is needed; the next request uses the new configuration.
reasoning only if the model and route actually support it. Do not enable deepSeekThinkingCompat unless your model needs that compatibility mode, and do not set thinkingLevelMap without model-specific guidance.
- The button under the message box carries the current model name — here
GPT-5.6 Sol. Selecting it opens this list. - The tick marks the model this conversation will send to. Make sure it is the one you tested.
- The list shows model names only, with no provider prefix, so give each model an ID you can recognize on sight.
Changing a card later, and deleting one
Every provider card has a three-dot menu (⋮) with two actions, not equally reversible.
| Action | What it does | When you want it |
|---|---|---|
| Edit | Reopens the form to change baseUrl or apiKey, update the models list, or change reasoning settings | Rotating a key, adding a current model such as anthropic/claude-sonnet-4, fixing its context setting |
| Delete | Removes the configuration. Old history stays readable, but a Session cannot carry on through a model that is no longer there | You have stopped using that provider, or the card needs recreating |
A second key on the same provider earns its own card in three situations: telling home and office usage apart, with cards named OpenRouter-home and OpenRouter-office; carrying separate per-key limits where the dashboard offers them, though that is no substitute for restricting Home Assistant administrator access; and reducing disruption while you rotate the other key. Follow your organization's rules for business credentials and billing. Add it with Add Provider, a different Name, the same baseUrl, the other apiKey, and anthropic/claude-sonnet-4 only if it is still in the live catalog.
Read the error before you change anything
A failed Test is specific. Match the code to a row rather than editing fields at random.
| What Test shows | What it likely means | What to check |
|---|---|---|
| 401 Unauthorized | OpenRouter rejected the credential | Reveal the field briefly and look for missing characters or whitespace. Confirm the key is still active in the dashboard; rotate it if not. |
| 404 Not Found | The endpoint path or the model ID was not found | Set baseUrl to exactly https://openrouter.ai/api/v1 — no trailing slash, no /chat/completions, and not another vendor's endpoint such as https://api.openai.com/v1, where an OpenRouter key will not authenticate. Then check models[].name against the live catalog: glm-4 fails where the ID ends .6. |
| 400 Bad Request | The request format does not match the endpoint | Almost always the API mode. anthropic-messages does not fit this configuration; select openai-completions and retry. |
| 402 Payment Required | The key works, but the route cannot draw on your credit or quota | Check your balance and the model's current availability. A new account does not necessarily include free credit. |
| Timeout, or an endless spinner | The request never completed | Check outbound DNS and HTTPS with curl -I https://openrouter.ai. If that fails too, try ping 8.8.8.8, then check service status and retry — a ping proves networking only, never API authentication. |
Some failures show up in the interface rather than as a status code.
| Symptom | What to do |
|---|---|
| Test spins for more than 30 seconds | If networking is healthy, refresh pi-web with F5 or Ctrl+R, reopen Models and retry. Rarely, restart the add-on from Settings → Add-ons → Pi Agent → Restart. |
| Test went green, but the conversation returns 401 | The conversation is on a different model entry than the one you tested — Models holds anthropic/claude-sonnet-4 while the selector points at something like “OpenRouter / glm-4”. Choose the tested model and check its models[].name. |
| Every response is slow | Latency varies with the model, the upstream provider, the route and current load. Confirm baseUrl, API mode and model ID, then compare another suitable model. A fixed latency threshold is not a reliable diagnosis. |
| The selector still says “Not set” | Select New session — an existing Session can retain its earlier model state — or refresh pi-web with F5. If the list is still empty, check that /data/pi-agent/models.json was written. |
| The selector says “Unnamed provider” | The Name field was left empty. Open the card's three-dot menu, select Edit, type OpenRouter into Name, and save. |
And some go wrong before Pi Agent ever sees the key.
| Symptom at OpenRouter | What to do |
|---|---|
| The sign-in email never arrives | Check spam and filtered folders, confirm the address, and wait before requesting another. If that method stays unavailable, use another one OpenRouter offers — only from the official sign-in page. |
| The copied key is rejected | Keys normally begin sk-or-v1- and must be copied in full. Use the Copy button rather than selecting part of the text, strip accidental leading or trailing spaces, and do not add quotation marks. Test confirms the full credential arrived. |
| The key is gone, from Pi Agent and from the dashboard | If you closed the page before saving it, and models.json has no recoverable backup and your password manager no copy, the value is gone. Create a new key and revoke the missing one if it is still listed — a masked preview is not the full secret. |
| A model in the catalog will not work | Availability depends on account settings, provider routing, region, credit and the model's own status. Read the model page and the exact error first. F5 may refresh the dashboard, but will not lift an account or provider restriction. |
| Your account or payment method is not supported | Do not invent account details and do not bypass provider controls. Use a payment method your account is offered, or move to another supported provider from Appendix B. |
openrouter.ai domain, rotate any key you may have exposed, and change any credential you reused elsewhere. Never follow a sign-in link sent by a stranger, and never enter your key on a third-party “verification” page.Does Pi Agent send my key to WoowTech?
pi-web-start.sh and your network configuration. Two caveats: anyone administering the host can read local data, and BYOK says nothing about how OpenRouter or the upstream model provider handle and retain what you send.Do I need a new key after moving Home Assistant to another host?
/data/pi-agent/models.json. The backup article later in this series covers that procedure.Can one key be used by more than one Pi Agent?
pi-agent-home, pi-agent-office. Do not assume there is no account limit on keys — the API Keys page is the authority.Must I enable reasoning?
deepSeekThinkingCompat is for routes that need DeepSeek compatibility; thinkingLevelMap needs model-specific guidance.Which file records my Models changes, and can I edit it by hand?
/data/pi-agent/models.json, and the interface manages that JSON for you. Its providers object holds fields matching the form — baseUrl, api, apiKey and models[]. You can edit it, but the interface is safer: one missing or extra comma empties the Models panel and produces a parse error. If you do, validate the JSON and refresh pi-web. Avoid opening or sharing the file — it contains secrets. Appendix C covers bulk work.Can one provider card hold several models?
anthropic/claude-sonnet-4 across several example slots: one verified ID shown six times, not six recommendations, and labels such as “primary-model” are placeholders, not catalog IDs. And do not guess availability from a suffix like -flash or -air, or copy an ID from another vendor's documentation such as docs.bigmodel.cn and expect it to resolve on OpenRouter. Use the exact live ID.Where to go from here
The route is live. Now say something to it.
Part 4 covers your first real conversation: what to ask, how to read the reply, and what a session keeps between one message and the next.
Open the full guidePart 3 of the Pi Agent Onboarding Guide series, published by WoowTech.
Based on the Woow HA Pi Agent Onboarding Guide, produced by WoowTech and released under CC BY 4.0.
The Smart Space Solution · 智慧空間解決方案 · © 2026 WOOW Technology Co., Ltd.