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

# Authentication

> Integrate securely with the Admin API using account-level admin API keys transmitted in the `X-API-KEY` header.

> [!TIP]
>
> For client-side or end-user access to the Application API, create
> [application API keys](/api-reference/authentication.md) scoped to a single user
> instead.

## Admin API keys

Admin API keys are account-level credentials with broad permissions. Use them to authenticate requests to the Admin API, and optionally to the [Application API](/api-reference/authentication.md) from trusted server-side environments.

Every account can create a maximum of 3 admin API keys from the [integration page](https://app.trophy.so/integration) of the Trophy dashboard.

Trophy keeps track of and displays when each admin API key in your account was created and when it was last used so you can easily keep track of usage.

![](https://mintcdn.com/trophy-cep/KNKynR4KUMaS-uCh/assets/api/authentication/api_keys.png?fit=max\&auto=format\&n=KNKynR4KUMaS-uCh\&q=85\&s=3283ab9f82404dbc5b52bb255c7036b8)

> [!WARNING]
>
> Admin API keys can access any user and any admin operation in your account.
> Never expose them in client-side code, mobile apps, or public repositories.

### Anatomy of an admin API key

Each admin API key is made up of 2 parts separated by a period:

```bash theme={null}
{prefix}.{body}
```

* The *prefix* is the first 8 characters. It's readable and will always stay the same so it's easily recognisable.
* The *body* is the secret part, and is only shown to you once when you create the key.

> [!NOTE]
>
> When using the API, both parts of your admin API key must be sent in the
> `X-API-KEY` header.

### Authenticating requests

When making requests to the Admin API, include both parts of your admin API key in the `X-API-KEY` header, or pass it when initializing an SDK client:

```bash cURL theme={null}
curl https://admin.trophy.so/v1/metrics \
     -H "X-API-KEY: YOUR_API_KEY"
```

```typescript Node theme={null}
import { TrophyApiClient } from "@trophyso/node";

const trophy = new TrophyApiClient({
  apiKey: "YOUR_API_KEY",
});
```

```python Python theme={null}
from trophy import TrophyApi

client = TrophyApi(
    api_key="YOUR_API_KEY",
)
```

```php PHP theme={null}
use Trophy\TrophyClient;

$trophy = new TrophyClient("YOUR_API_KEY");
```

```java Java theme={null}
TrophyApiClient client = TrophyApiClient.builder()
    .apiKey("YOUR_API_KEY")
    .build();
```

```go Go theme={null}
import (
  trophyclient "github.com/trophyso/trophy-go/client"
  "github.com/trophyso/trophy-go/option"
)

client := trophyclient.NewClient(
  option.WithApiKey("YOUR_API_KEY"),
)
```

```csharp C# theme={null}
var trophy = new TrophyApiClient(
    apiKey: "YOUR_API_KEY"
);
```

```ruby Ruby theme={null}
client = Trophy::Client.new(
  api_key: "YOUR_API_KEY"
)
```

The same key authenticates Application API requests when you use an admin API key from a server-side environment:

```bash cURL theme={null}
curl https://api.trophy.so/v1/users/user_123/metrics/<key> \
     -H "X-API-KEY: YOUR_API_KEY"
```

```typescript Node theme={null}
import { TrophyApiClient } from "@trophyso/node";

const trophy = new TrophyApiClient({
  apiKey: "YOUR_API_KEY",
});
```

```python Python theme={null}
from trophy import TrophyApi

client = TrophyApi(
    api_key="YOUR_API_KEY",
)
```

```php PHP theme={null}
use Trophy\TrophyClient;

$trophy = new TrophyClient("YOUR_API_KEY");
```

```java Java theme={null}
TrophyApiClient client = TrophyApiClient.builder()
    .apiKey("YOUR_API_KEY")
    .build();
```

```go Go theme={null}
import (
  trophyclient "github.com/trophyso/trophy-go/client"
  "github.com/trophyso/trophy-go/option"
)

client := trophyclient.NewClient(
  option.WithApiKey("YOUR_API_KEY"),
)
```

```csharp C# theme={null}
var trophy = new TrophyApiClient(
    apiKey: "YOUR_API_KEY"
);
```

```ruby Ruby theme={null}
client = Trophy::Client.new(
  api_key: "YOUR_API_KEY"
)
```

If you do not pass an API key, or your API key is invalid, you'll receive a `401` response code.

## Managing admin API keys

There are a few different operations you can perform on admin API keys from within your Trophy dashboard to manage your integration.

![](https://mintcdn.com/trophy-cep/KNKynR4KUMaS-uCh/assets/api/authentication/api_key_options.png?fit=max\&auto=format\&n=KNKynR4KUMaS-uCh\&q=85\&s=eefb892b4a347aa715e6d49315698ba0)

### Rotating keys

Admin API keys can be rotated if you want to change them for any reason. At the point of rotation, the original API key will no longer function and any requests still using it will begin receiving `401` responses immediately.

> [!NOTE]
>
> Note that when rotating keys, both the prefix and the body will change.

### Revoking keys

Admin API keys can also be revoked entirely at which point they become *Inactive*. At the point of revocation, the API key will no longer function and any requests still using it will begin receiving `401` responses immediately.

Once revoked you can re-activate the API key at any time.

> [!NOTE]
>
> Neither the prefix or the body of the key change when revoked or re-activated.

### Deleting API keys

If you're 100% sure you no longer need an admin API key, they can be deleted.

> [!CAUTION]
>
> Once API keys are deleted, they cannot be recovered.

## Get support

Want to get in touch with the Trophy team? Reach out to us via [email](mailto:support@trophy.so). We're here to help!


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