# Environments and API keys

> Every project has a live environment for real traffic and a test environment for development, and each has its own API keys. The key decides where a call goes.

## Live and test environments

Each project in the dashboard has two environments:

| Environment | For | Billed |
|---|---|---|
| Live | Real traffic | Yes: live sessions count towards your monthly usage |
| Test | Development and staging | No: test sessions are free |

- **They work the same.** A test environment behaves like a live one: decisions, outcomes, holdouts, reports, pausing and rate limits.
- **They're kept apart.** Each environment has its own flows, data, learning and keys. Nothing learned in test carries over to live, so a flow you take live starts from your defaults there. Data is never pooled across projects or customers either.
- **The key decides.** Both use the same base URL, `https://zigbongo.com`; the key you call with decides which environment the call goes to.
- **Use the test key while you build.** A flow is created the first time your code asks about it, in whichever environment the key belongs to.

The dashboard shows each environment's flows apart (switch between Live and Test on the project's pages), and the organization's Usage page shows the month's live sessions against the free allowance, with the test sessions beside them. The first 10,000 live sessions each month are free ([Pricing](https://zigbongo.com/pricing/)).

## API keys

A key looks like this, here as a line in an `.env` file:

```sh
ZIGBONGO_KEY=zb_7k2mq9xrtv4h_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
```

- `zb_` says it's a Zigbongo key, which makes it easy to spot, for you and for a secret scanner.
- Then the key id: 12 characters, public, safe to name in a support request. The dashboard lists keys by it (`zb_7k2mq9xrtv4h…`).
- Then the secret: 64 hexadecimal characters. The whole key is 80 characters long.

A test key and a live key look alike: what makes a key test or live is the environment you created it in. Label your keys so you can tell them apart.

Zigbongo stores only a hash of each key, so it can't show you a key again or recover a lost one: create a new one.

## Creating a key

On the project's API keys page, each environment has its own list:

1. Under the environment you want, give the key a label if you like, such as "production server", and select "Create key".
2. Copy the key at once: it's shown only this one time.
3. Put it on your server, for example in an environment variable, `ZIGBONGO_KEY`:

```js
import { Zigbongo } from "@zigbongo/sdk";

const zb = new Zigbongo({ apiKey: process.env.ZIGBONGO_KEY, baseUrl: "https://zigbongo.com" });
```

```php
use Zigbongo\Zigbongo;

$zb = new Zigbongo(apiKey: getenv('ZIGBONGO_KEY'), baseUrl: 'https://zigbongo.com');
```

Anyone who can open the project can create and revoke its keys, and the organization's audit log records each one by its key id and label, never the secret.

## Revoking and rotating keys

Select "Revoke" next to a key, and again to confirm. Calls with it get `401 unauthorized` on every server within a few seconds, usually about one. A decide call with a revoked key falls back to your default, so watch `onError` ([Fallbacks and timeouts](https://zigbongo.com/docs/fallbacks-and-timeouts.md)).

To rotate a key without a gap:

1. Create a new key in the same environment.
2. Deploy it everywhere the old one was used.
3. Check the old key's "Last used" column, which also names the SDK and version that made the last call, until it stops moving.
4. Revoke the old key.

Revoke at once any key that may have leaked.

## Keep keys on your server

A key acts for your environment: it can make decisions, report outcomes, pause flows and erase customers. So it never leaves your servers:

- **Call Zigbongo from your back end only,** never from a browser, a mobile app or a desktop app. The Node.js SDK refuses to load where `window` exists.
- **Keep it out of your code,** in an environment variable or your secrets manager, and out of version control and logs.
- **One key per server or service,** labelled, so you can revoke one without touching the others.

Under the [terms](https://zigbongo.com/terms/), you're responsible for keeping your keys secret, and what's done with them counts as done by you.

---

The Markdown of https://zigbongo.com/docs/environments-and-keys/. Every docs page: https://zigbongo.com/llms.txt
