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

# API Keys

> Create, configure, and rotate Waniwani API keys.

Every Waniwani client authenticates with a single API key scoped to one **MCP environment**. When you create a project, two environments are provisioned automatically: **Staging** and **Production**, each with its own unique API key.

The key you use determines which environment your data (events, sessions, knowledge base) is stored in. Use the Staging key during development and the Production key for live traffic. This keeps your data cleanly separated.

## Managed projects

Both API keys (Staging and Production) are pre-configured in your deployed instance. You can view and rotate them from your MCP app page under **Settings > API Keys**.

No manual setup needed for managed projects. API keys are pre-configured in your environment.

## Self-hosted projects

When you create a self-hosted project, you get your **Production** API key right away. Set it in the environment where your MCP server runs:

```bash .env theme={null}
WANIWANI_API_KEY=wwk_...
```

```ts theme={null}
import { waniwani } from "@waniwani/sdk";

const wani = waniwani(); // reads WANIWANI_API_KEY from env
```

Manage the variable wherever you normally keep secrets (`.env` file, your platform's secret manager, etc.).

To set up a **Staging** environment, create one from your project's dashboard and use its key for local dev and preview deploys.

<Warning>
  API keys grant rights to ingest events and mint widget tokens for their environment. Treat them as server-side secrets. Never commit them to git, never ship them in client-side bundles.
</Warning>

## Per-environment keys

Use the **Staging** key during development and the **Production** key for your live deployment. Mixing environments pollutes your metrics and makes rotation harder.

| Environment | When to use                   | Where the env var lives               |
| ----------- | ----------------------------- | ------------------------------------- |
| Production  | Live traffic                  | Platform secret manager               |
| Staging     | Local dev and preview deploys | `.env` (gitignored) / preview secrets |

## Rotate a key

Rotate from the environment settings in the dashboard. Clients using the old key start receiving `401 Unauthorized`; the SDK's transport detects auth failures and stops retrying, so you get a clean shutdown instead of a retry storm.

## Troubleshooting

If events do not appear in the dashboard:

1. Confirm `WANIWANI_API_KEY` is set in the process running the MCP server (setting it only in your shell is not enough).
2. Check for typos. The key is a single string, no quotes, no trailing whitespace.
3. Look for `[waniwani]` lines in your server logs.
4. Trigger a tool call. The dashboard only shows events from real traffic.

## Also supported

Pass the key explicitly when you need multiple clients in one process (multi-tenant setups):

```ts theme={null}
import { waniwani } from "@waniwani/sdk";

const wani = waniwani({ apiKey: process.env.TENANT_A_KEY });
```

Next: [wrap your MCP server](/sdk/configuration/wrap-server).
