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

# REST API Authentication

> Authenticate HTTP requests to the Meter API

# REST API Authentication

All Meter API requests require authentication using an API key in the `Authorization` header.

## Authentication header

Include your API key using the Bearer authentication scheme:

```
Authorization: Bearer sk_live_your_key_here
```

## Example requests

### Using curl

```bash theme={null}
curl https://api.meter.sh/api/strategies \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -H "Content-Type: application/json"
```

### Using JavaScript (fetch)

```javascript theme={null}
const response = await fetch('https://api.meter.sh/api/strategies', {
  headers: {
    'Authorization': `Bearer ${process.env.METER_API_KEY}`,
    'Content-Type': 'application/json'
  }
});

const data = await response.json();
```

### Using Python (requests)

```python theme={null}
import requests
import os

headers = {
    'Authorization': f'Bearer {os.getenv("METER_API_KEY")}',
    'Content-Type': 'application/json'
}

response = requests.get('https://api.meter.sh/api/strategies', headers=headers)
data = response.json()
```

## Getting an API key

See the main [Authentication](/authentication) guide for instructions on obtaining and managing API keys.

## Error responses

### 401 Unauthorized

Missing or invalid API key:

```json theme={null}
{
  "detail": "Invalid or missing API key"
}
```

**Solutions:**

* Verify your API key is correct
* Ensure the `Authorization` header is included
* Check the key hasn't been deleted

### 403 Forbidden

Valid key but insufficient permissions:

```json theme={null}
{
  "detail": "You do not have permission to access this resource"
}
```

**Solutions:**

* Verify you're accessing your own resources
* Check the resource exists

## Best practices

<CardGroup cols={2}>
  <Card title="Use Environment Variables" icon="shield-halved">
    Never hardcode API keys in source code
  </Card>

  <Card title="Secure Transmission" icon="lock">
    Always use HTTPS, never HTTP
  </Card>

  <Card title="Rotate Keys" icon="arrows-rotate">
    Generate new keys periodically
  </Card>

  <Card title="Monitor Usage" icon="chart-line">
    Track API calls in your dashboard
  </Card>
</CardGroup>

## Next steps

<CardGroup cols={2}>
  <Card title="API Key Management" icon="key" href="/authentication">
    Learn how to create and manage API keys
  </Card>

  <Card title="REST API Overview" icon="book" href="/api-reference/rest/overview">
    Explore the REST API
  </Card>

  <Card title="Strategy Endpoints" icon="brain" href="/api-reference/rest/strategies">
    Start making API calls
  </Card>
</CardGroup>

## Need help?

Email me at [mckinnon@meter.sh](mailto:mckinnon@meter.sh)
