> ## Documentation Index
> Fetch the complete documentation index at: https://docs.joinbankroll.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Secrets

> Give your app a key for an outside service, such as an API key or a database password. Your server reads it as an environment variable, and nobody can read it back.

Your app can use a service of your own: a data feed, your database, a
partner's API. A **secret** is the key to that service. You give it to your
app once, your server reads it as `process.env.NAME`, and nobody can read it
back, you and Bankroll included.

> [!NOTE]
>
> This page is for an app that Bankroll hosts: one made with `bankroll apps
>   create` or in the Bankroll app. An app on [your own origin](https://docs.joinbankroll.com/build/self-hosted.md)
> sets its environment variables where it is hosted.

## Set a secret

You need version 1.3.0 or later of the Bankroll CLI. `bankroll --version`
prints yours, and `npm i -g @joinbankroll/cli@latest` updates it.

In your app's folder:

```bash theme={null}
bankroll env set KALSHI_API_KEY
```

The command asks for the value and shows nothing while you type or paste. The
value is never an argument, so it does not stay in your shell's history. A
value of several lines, such as a PEM key, comes from a file, and a pipe works
too:

```bash theme={null}
bankroll env set KALSHI_PRIVATE_KEY --from-file kalshi.pem
pbpaste | bankroll env set KALSHI_API_KEY
```

Keep your own copy of the value where you keep keys. Bankroll cannot show it
to you again. To change a value, set it again.

## Test and live

Your app has a test version and a live version, and each has a value of its
own. With no option, a command is for both. `--test` or `--live` names one,
so a test database and a live database can sit under the same name:

```bash theme={null}
bankroll env set DATABASE_URL --test
bankroll env set DATABASE_URL --live
```

A version reads its secrets when it is built. So `set` and `rm` build the
versions again and show the build, the way [`bankroll wait`](https://docs.joinbankroll.com/build/environments)
does. Several names in one command share one build, and `--no-rebuild` leaves
the build for later. A rebuild counts as one of your builds for the day.

The live version is built again only while it serves the commit that its
`live` branch holds. If you pushed to `live` and that build did not go
through, the secret is read at your next publish.

## Read a secret

Read it on the server, in a route handler or a server module:

```ts theme={null}
// src/lib/feed.ts
const key = process.env.KALSHI_API_KEY;

/** Whether this version of the app has the key. */
export const feedReady = () => Boolean(key);
```

* Never read a secret in a client component, and never send one to the
  browser.
* Write your app so that it runs without the secret, with that one feature
  closed. A fresh clone of your app does not have it.
* To use the secret on your own computer, put the value in `.env.local`. Git
  ignores that file, and Bankroll never sees it.

## List and remove

```bash theme={null}
bankroll env             # the names, and which versions have a value
bankroll env rm KALSHI_API_KEY
```

The list shows names and the day each value was set. It never shows a value.

## Names

A name is capital letters, digits and underscores, and starts with a letter:
`KALSHI_API_KEY`, `DATABASE_URL`. Three kinds of name are refused:

| Name | Why |
| - | - |
| `NEXT_PUBLIC_…` | Next.js builds these into the code the browser downloads, so they are public. |
| `BANKROLL_…` | Bankroll sets these for your app: its wallet, its key, its signed manifest. |
| `NODE_…`, `PATH`, `PORT` and the like | The server itself reads these. |

A version holds up to 20 secrets, each up to 8 KB.

## Remixing

A remix copies an app's code and never its secrets, so the copy of an app
that needs one would not work. An app that holds a secret cannot be remixed.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.