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

# Peeng Authentication: API Keys, Scopes, and Rotation

> Every Peeng request requires an API key in the x-api-key header. Learn how to create, scope, and rotate keys safely with no OAuth required.

Every request to the Peeng ingestion API must include an API key in the `x-api-key` request header. There is no OAuth flow, no bearer token exchange, and no request signing — the key itself is the credential, and it is all you need.

```bash theme={null}
curl https://api.peeng.dev/v1/logs \
  -H "x-api-key: pk_test_a1b2c3d4e5f6..."
```

<Warning>
  Treat your API key like a password. Never commit it to source control, never embed it in client-side or browser-executed code, and never include it in a mobile app bundle — anyone who obtains the key can write logs to your project. Store it as an environment variable on your server and read it at runtime.
</Warning>

## Creating a key

Keys are created per-project from the Peeng dashboard. Navigate to **Settings → API Keys** and click **New API Key**. Peeng stores only a hash of the key, so the full key value is displayed exactly once — at the moment of creation. Copy it immediately and store it somewhere safe. If you lose it, you must [regenerate it](#regenerating-a-key) rather than retrieve it.

## Test vs. live keys

Every key has a scope — either `test` or `live` — reflected in its prefix:

```
pk_test_a1b2c3d4e5f6...
pk_live_a1b2c3d4e5f6...
```

Both scopes hit the same API endpoint and behave identically at the protocol level. The scope exists so you can distinguish your own test traffic from real production traffic at a glance — in the key list, in audit logs, and alongside the `environment` field you set in each log entry. Use a `test`-scoped key from local development and staging environments, and a `live`-scoped key from production.

<Info>
  The `test` / `live` key scope is independent of the `environment` field you include in each log body. You control both separately — key scope for visibility in the dashboard, and `environment` for filtering and grouping your own logs.
</Info>

## Regenerating a key

If a key is compromised or lost, regenerate it from **Settings → API Keys** in the Peeng dashboard. Regeneration is atomic — the old key stops working the instant the new one is issued. There is no grace period where both keys are valid simultaneously.

<Warning>
  Update every service that uses the old key before you regenerate it, or those services will begin failing requests immediately when the old key is invalidated.
</Warning>

## Missing or invalid keys

Any request that omits the `x-api-key` header, or provides a key that does not match an active key for your project, receives a `401` response:

```json theme={null}
{
  "statusCode": 401,
  "message": "Missing API key",
  "error": "UnauthorizedException"
}
```

See [Errors](/essentials/errors) for the full error envelope shape and a complete list of error codes.
