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

# Authentication

> Authenticate the ReyGrid Python SDK with an API key.

The SDK authenticates with your API key as a Bearer token. Provide it once and it is sent as `Authorization: Bearer <key>` on every request.

```python theme={"system"}
import os
from reygrid import ReyGrid

client = ReyGrid(api_key=os.environ["REYGRID_API_KEY"])
```

## Change the key at runtime

```python theme={"system"}
client.set_api_key("new-key")   # replace
client.set_api_key(None)        # clear
```

## Validate the key

```python theme={"system"}
validation = client.validate()
print(validation.valid, validation.usage.total, validation.usage.quotaLimit)

usage = client.get_usage()       # shortcut for validate().usage
```

An invalid or missing key raises [`ReyGridAuthError`](/integrations/python/error-handling).

<Tip>
  Keep keys in environment variables or a secrets manager, and call ReyGrid from your server. See [REST API authentication](/rest-api/authentication) for security guidance.
</Tip>


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