# The owner's own key — one secret the app runs on

> Hidden: the owner's own key for a third-party service as one Setup item (missing-key verdict, Settings → Secrets steps, no redeploy), kept to backend.js, the /_api second door that spends it only on the owner's calls, refusals that keep their reason, and rotation

Source: https://good.vibes.diy/docs/reference/owner-secret

Some services answer only with a key, and the key belongs to the app's owner:
they create it on the service's site once, paste it into the vibe's Secrets,
and backend.js reads it as `ctx.secrets.<NAME>`. The service skill that loaded
this page names the secret and the provider pages; this page is what every
owner-key feature does the same way.

## The owner's key, not each visitor's

The key is the owner's, its quota or bill is the owner's, and every visitor sees
what the owner's key can see. An app where each person sees **their own**
account is a **connection** instead: the platform runs the sign-in and holds the
credential, and the app's code never sees a token (the connections docs). So
never ask a visitor to paste a token or send one to a developer console: the
console trip in the service's steps is the owner's, once.

## The secret is a Setup item

The key is one item on the app's Setup surface (the use-vibe docs' *Some apps
need setup before they work*). The `/setup` route marks it done when
`ctx.secrets.<NAME>` is present, and every feature route answers
`{ ok: false, reason: "missing-key" }` while it is absent, so the page can say
*not open yet* to a visitor and show the owner the steps.

The item's steps are written for someone who has never opened the provider's
console: each one links the exact page and uses that page's own words, and the
last two are always the same:

- Open this vibe's settings (in Code mode, the **App settings** tab, or
  `https://vibes.diy/vibes/mine/<ownerHandle>/<appSlug>/settings`), and under
  **Secrets** enter the name under **KEY** (`SPOTIFY_CLIENT_SECRET`, in so many
  words), paste the value beside it, and press **Set**. From a terminal: `npx vibes-diy secrets set <NAME> --vibe <ownerHandle>/<appSlug>`.
- Come back to the app: it works the moment the key is saved, with no redeploy.

A service that hands the owner several values (a key id and its private key, a
client id and its secret) gets one secret for each, and a multi-line private key
pasted into the value field is kept whole, line breaks included. When Secrets
turns a value away, the reply says so plainly with what the refusal said, and
the item stays open with the rest of the app working around it.

Wherever the owner types the value (this tab, the terminal, or a secure field
the vibes.diy assistant opens for them), it lands in the same store under the
same name, so the app's copy only has to name it. The app never asks for the key
itself: no input, no form, no "paste your key here" field on any page, because a
value typed into the app is a value the app's own data and every visitor's
browser can reach.

## The key never reaches the browser

Every call to the service is made in backend.js with `ctx.fetch`, and the key
rides only that request. App.jsx talks to the app's own `/_api/...` routes and
never names the service's API host. A key in a React component ships to every
visitor who views source.

## The `/_api` routes are a second door

A published vibe's `/_api/...` routes answer anyone, so a route that calls the
service on every request lets a stranger spend the owner's quota or bill. Spend
the key on the owner's own calls and on the backend's scheduled jobs; a
visitor's request is answered from what those calls stored, with the date it was
read, or with a stated reason when nothing is stored yet.

```js
// backend.js — who may spend the owner's key
const isOwnerCall = (ctx) => ctx.userInfo?.userHandle != null && ctx.userInfo.userHandle === ctx.appInfo.ownerHandle;
```

A service that charges per call (voice, images, video) needs this most: a
visitor-facing route that generates with the owner's key is a wallet with a
public URL. Let visitors use it only behind a limit the owner sets, kept in a
document the backend checks before each call.

## Errors keep their reason

Classify every refusal and pass the reason to the screen: the key is missing,
the key is wrong (the service's 401 or 403, which also means the Setup item
reads *Done* while one value is bad), the quota or rate limit is spent (keep the
service's own wait or reset time), or the item was not found. Wrap every route in
`try`/`catch` and answer with that reason, because an uncaught throw reaches the
page as a bare `500` that names nothing the owner can fix.

## Rotating the key

The owner rotates a key by saving a new value under the same name, and handlers
read the current value on every call, so there is nothing to restart. When a key
leaks (pasted into a chat, committed somewhere), the fix is a fresh key from the
provider and the old one revoked there.
