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

# Authentication

> How to authenticate your MarketDataset API requests

## API Keys

All requests to the MarketDataset API require an API key passed via the `X-API-KEY` header.

```bash theme={null}
curl "https://api.marketdataset.ai/forex/prices?pair=EURUSD" \
  -H "X-API-KEY: sk_your_key_here"
```

## Getting an API key

1. Sign in at [marketdataset.ai/dashboard](https://marketdataset.ai/dashboard)
2. In the **Overview** section, click **Create API Key**
3. Give your key a descriptive name (e.g., "production", "backtesting")
4. Copy the key immediately — it's only shown once

## Key format

API keys use the prefix `sk_` followed by a 32-character random string:

```
sk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
```

## Security best practices

<AccordionGroup>
  <Accordion title="Never expose keys in client-side code">
    API keys should only be used in server-side code or secure environments. Never embed them in frontend JavaScript, mobile apps, or public repositories.
  </Accordion>

  <Accordion title="Use environment variables">
    Store keys in environment variables, not hardcoded in source code.

    ```bash theme={null}
    export MARKETDATASET_API_KEY=sk_your_key_here
    ```
  </Accordion>

  <Accordion title="Rotate keys periodically">
    Create a new key and delete the old one from the Dashboard. Old keys are invalidated immediately upon deletion.
  </Accordion>

  <Accordion title="Use separate keys per environment">
    Create distinct keys for development, staging, and production to limit blast radius if a key is compromised.
  </Accordion>
</AccordionGroup>

## Error responses

| Status | Error                  | Cause                           |
| ------ | ---------------------- | ------------------------------- |
| `401`  | `Missing API key`      | `X-API-KEY` header not provided |
| `401`  | `Invalid API key`      | Key not found or deleted        |
| `402`  | `Insufficient credits` | Account balance is \$0.00       |
| `429`  | `Rate limit exceeded`  | Too many requests per minute    |
