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

# Authentication

> Authenticate API requests with a bearer token.

All API requests require a bearer token in the `Authorization` header.

```
Authorization: Bearer $LIGHTON_API_KEY
```

You can create an API key from the **API Keys** section of the [console](https://console.lighton.ai), or programmatically via [`POST /api/v3/keys`](/api-reference/api-keys/create-api-key). Existing keys can be listed and revoked through the same endpoint family.

<CodeGroup>
  ```python Python SDK theme={null}
  from lighton import ApiKey, LightOn

  with LightOn() as client:  # reads LIGHTON_API_KEY from the environment
      # Omitting expires_at creates a key that never expires
      key = ApiKey(name="ci-pipeline").create(client)
      print(key.id, key.key.get_secret_value())  # the secret is shown once, store it now

      # List the keys you already have, then revoke this one
      for existing in ApiKey.list(client):
          print(existing.id, existing.name, existing.prefix)

      key.delete()
  ```

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

  headers = {"Authorization": f"Bearer {os.environ['LIGHTON_API_KEY']}"}

  # expires_at is required: null creates a key that never expires
  response = requests.post(
      "https://api.lighton.ai/api/v3/keys",
      headers=headers,
      json={"name": "ci-pipeline", "expires_at": None},
  )
  key = response.json()
  print(key["id"], key["key"])  # the full key is returned only here, store it now

  # Revoke it when it is no longer needed
  response = requests.delete(
      f"https://api.lighton.ai/api/v3/keys/{key['id']}",
      headers=headers,
  )
  print(response.status_code)  # 204
  ```

  ```bash cURL theme={null}
  # Create a key. The full `key` value is in this response and nowhere else.
  curl https://api.lighton.ai/api/v3/keys \
    -H "Authorization: Bearer $LIGHTON_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name": "ci-pipeline", "expires_at": null}'

  # Revoke it (204 No Content)
  curl -X DELETE https://api.lighton.ai/api/v3/keys/$KEY_ID \
    -H "Authorization: Bearer $LIGHTON_API_KEY"
  ```
</CodeGroup>

## Error responses

| Status | Meaning                                           |
| ------ | ------------------------------------------------- |
| `401`  | Missing or invalid API key                        |
| `403`  | Key exists but lacks permission for this resource |
| `429`  | Rate limit exceeded                               |
