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

# Create an API key with the least scope

> Create a project API key that can only send telemetry, check what it can do, and revoke it.

A key should hold only the scopes its job needs. A key for an SDK, a log forwarder, or a CI job
that sends telemetry needs one scope: `events:ingest`. A key with that scope cannot read your data,
so a leak of it does not expose your project. This recipe creates such a key, checks it, and
revokes it.

The caller needs permission to manage keys, and a key can only give scopes that the caller holds.
See [API keys](https://docs.squasher.ai/api-reference/api-keys.md) for the rules.

## Create the key

The secret appears once, in the response. Put it straight into your secret store. Do not print it,
log it, or paste it into a prompt.

> [tab] CLI
>
> ```bash theme={null}
> squasher api-keys create --project "$SQUASHER_PROJECT_ID" \
>   --label "Log forwarder" --scope events:ingest \
>   --expires-at 2026-12-31T00:00:00Z --yes --json > new-key.json
> ```
>
> The command asks for confirmation unless you pass `--yes`. Read the secret from `new-key.json`
> with `jq -r .key`, move it to your secret store, and delete the file.

> [tab] MCP
>
> The MCP server hides all API key operations, so `search("apiKeys")` returns nothing and
> `execute` refuses them. Ask the person to run the CLI or REST API tab, or to create the key in
> the dashboard.

> [tab] REST API
>
> ```bash theme={null}
> curl -X POST "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/api-keys" \
>   -H "x-squasher-key: $SQUASHER_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "label": "Log forwarder",
>     "scopes": ["events:ingest"],
>     "expires_at": "2026-12-31T00:00:00Z"
>   }'
> ```

The response is the only time the full key appears:

```json theme={null}
{
  "id": "<uuid>",
  "key": "sq_pk_<secret>",
  "key_prefix": "sq_pk_<first characters>",
  "label": "Log forwarder",
  "scopes": ["events:ingest"],
  "created_at": "<ISO time>"
}
```

`expires_at` is optional. Use it for keys that you only need for a while.

## Check what the key can do

Keys are listed by `key_prefix`, never by secret. A key with only `events:ingest` is refused when
it reads data:

```bash theme={null}
curl -i "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/errors" \
  -H "x-squasher-key: $NEW_KEY"
```

```json theme={null}
{ "error": "API key missing required permission: errors:read" }
```

The status is `403`. To send telemetry with this key, see the
[Ingestion API](https://docs.squasher.ai/api-reference/ingest.md).

Now list the keys of the project:

> [tab] CLI
>
> ```bash theme={null}
> squasher api-keys list --project "$SQUASHER_PROJECT_ID" --json
> ```

> [tab] MCP
>
> Not available. See above.

> [tab] REST API
>
> ```bash theme={null}
> curl "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/api-keys" \
>   -H "x-squasher-key: $SQUASHER_API_KEY"
> ```

The list has one object for each active key:

```json theme={null}
[
  {
    "id": "<uuid>",
    "label": "Log forwarder",
    "key_prefix": "sq_pk_<first characters>",
    "scopes": ["events:ingest"],
    "created_at": "<ISO time>",
    "expires_at": "2026-12-31T00:00:00.000Z",
    "last_used_at": null,
    "revoked_at": null
  }
]
```

## Revoke the key

Revoking is permanent. A revoked key stops working within a minute, and it leaves the list.

> [tab] CLI
>
> ```bash theme={null}
> squasher api-keys revoke KEY_ID --project "$SQUASHER_PROJECT_ID" --yes
> ```

> [tab] MCP
>
> Not available. See above.

> [tab] REST API
>
> ```bash theme={null}
> curl -X DELETE "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/api-keys/KEY_ID" \
>   -H "x-squasher-key: $SQUASHER_API_KEY"
> ```
>
> The response is `204` with no body.

## Next steps

> [card] [API keys API](https://docs.squasher.ai/api-reference/api-keys.md)
>
> Every scope and the rules for giving them.

> [card] [Ingestion API](https://docs.squasher.ai/api-reference/ingest.md)
>
> Send telemetry with an ingest-only key.


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