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

# Toppie Authentication

> Learn how to authenticate with the Toppie API using a Toppie agency API key

The Toppie API is authenticated via bearer tokens. Requests must include an authorization header containing a Toppie agency API key. These keys start with `TAS_` and are created in the Toppie UI. If the header is missing or invalid, the HTTP response code will be `401 Unauthorized`.

```sh theme={null}
GET /public/v1/toppie/campaigns HTTP/2
Host: api.topsort.com
...
Authorization: Bearer <YOUR-TOPPIE-API-KEY>
...
```

> [!WARNING]
>
> Marketplace (`TSE_`) and Advanced (`TSC_`) API keys from Topsort Admin are rejected on `/public/v1/toppie/*` with `401 Unauthorized`. The generic security scheme in the endpoint reference mentions those keys. For Toppie, use a `TAS_` key.

## Obtaining an API Key

**1. Open API Integration**

In the Toppie dashboard, click **Settings**, and then select **API Integration** in the left-hand menu.

**2. Generate API Key**

Click the **+ New API Key** button.

![Toppie API Integration settings page showing the New API Key button](https://mintcdn.com/topsort/uSrfRB5jaD2RxnFe/images/knowledge-base/creating-toppie-api-keys.webp?fit=max\&auto=format\&n=uSrfRB5jaD2RxnFe\&q=85\&s=7096cf2ddd962b839c008ff32ce7fa07)

**3. Copy Key**

The key is shown only once. Copy it and store it in a secrets manager or an environment variable.

**4. Use API Key**

Use the API key on your servers, in the `Authorization` header of every request.

Each key belongs to one Toppie account and has full access to it: it can read and change that account's campaigns, and read its reports and products, but nothing outside the account. An agency that manages several brand accounts needs one key per account, created from that account's settings.

## Managing Keys

Keys do not expire, and an account can have more than one key. The **API Integration** page lists the account's keys, where you can rename or delete them. A deleted key stops working within 5 minutes.

To rotate a key, create a new one, update your integration to use it, and then delete the old key.

## Authentication Errors

| Status | Description |
| - | - |
| `401 Unauthorized` | The `Authorization` header is missing, the key is invalid, it is not a `TAS_` key, or the account is inactive. |
| `403 Forbidden` | The key is not allowed to perform the action. Keys created in the Toppie UI have full access, so contact your Toppie account manager if you receive this. |

See [Toppie errors](https://docs.topsort.com/en/api-reference/toppie/handling-errors.md) for the error body and the other status codes.

> [!WARNING]
>
> **Keep API keys secret,** this is not a public key. **Do not share it with
> your frontend or clients**, and never commit it to a code repository.
> [Rotate keys](#managing-keys) regularly, and when someone with access leaves
> the team.


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