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

# API keys

> Create an API key and use it to authenticate API requests

Every Fairground API request needs an API key, sent as a bearer token in the `Authorization` header. Requests without a valid key return `401 unauthenticated`.

## Create an API key

**1. Open the API Keys page**

Go to [app.fairground.fi/421614/api-keys](https://app.fairground.fi/421614/api-keys) and connect your wallet.

**2. Create a key**

Create a new API key and give it a label, such as the name of the bot or tool that will use it, so you can tell your keys apart later.

**3. Copy and store it**

Copy the key right away and store it somewhere safe, such as a password manager or an environment variable. Treat it like a password.

> [!WARNING]
>
> Never commit an API key to source control or share it in chat. If a key is exposed, regenerate it
> on the [API Keys page](https://app.fairground.fi/421614/api-keys).

## Manage your keys

The [API Keys page](https://app.fairground.fi/421614/api-keys) lists your keys by label. Each wallet can have up to **3 active keys**. From there you can:

* **Regenerate a key** to rotate it. You get a new key with the same label, and the old key stops working immediately. Update anything that uses the key with the new value.
* **Delete a key** you no longer use. It stops working immediately.

## Use your key in requests

Send the key in the `Authorization` header with the `Bearer` prefix:

```bash cURL theme={null}
export FAIRGROUND_API_KEY="your-api-key"

curl -X POST https://api.fairground.fi/market_service.v2.MarketService/GetMarkets \
  -H "Authorization: Bearer $FAIRGROUND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Reading the key from an environment variable keeps it out of your code and your shell history.

## Use your key in the API playground

Every endpoint page in the [API reference](https://docs.fairground.fi/developers/api-reference/introduction.md) has a **Try it** button that sends a live request from your browser.

**1. Open an endpoint and click Try it**

Open any endpoint page, for example [GetMarkets](https://docs.fairground.fi/api-reference/markets/getmarkets.md), and click **Try it**.

**2. Paste your key into the Authorization field**

Under **Authorization**, paste your API key into the field next to **Bearer**. Enter only the key: the playground adds the `Bearer` prefix for you.

**3. Send the request**

Fill in any request fields you need, then click **Send**.

The playground keeps your key filled in as you move between endpoint pages in the same browser, so you only need to enter it once. Because it stays in your browser, avoid using the playground with your key on a shared computer.

## Troubleshooting

| Response | Likely cause |
| - | - |
| `401 unauthenticated` | The `Authorization` header is missing, or the key is wrong, deleted, or was replaced by a regenerated key. In the playground, check that you pasted only the key, without the word `Bearer`. |
| `resource_exhausted` | Your wallet already has 3 active keys. Delete or regenerate an existing key instead of creating a new one. |
| `invalid_argument` | The key worked, but a request field is missing or malformed. Check the endpoint page for required fields. |


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