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

# API Keys

Manage your API keys programmatically. API keys allow you to authenticate requests to the G-Tateth API.

<Note>
  These endpoints require JWT authentication (user login), not API key authentication.
</Note>

## List API Keys

<Endpoint method="GET" path="/api/tenant/api-keys">
  List all API keys for your tenant
</Endpoint>

<ParamField query="environment" type="string" optional>
  Filter by environment: `production` or `staging`
</ParamField>

<ParamField query="isActive" type="boolean" optional>
  Filter by active status: `true` or `false`
</ParamField>

<ParamField query="page" type="integer" optional>
  Page number (default: 1)
</ParamField>

<ParamField query="limit" type="integer" optional>
  Items per page (default: 20)
</ParamField>

<ResponseField name="success" type="boolean">
  true
</ResponseField>

<ResponseField name="data.keys" type="array">
  Array of API key objects
</ResponseField>

<ResponseField name="data.total" type="number">
  Total number of API keys
</ResponseField>

<ResponseField name="data.page" type="number">
  Current page number
</ResponseField>

<ResponseField name="data.limit" type="number">
  Items per page
</ResponseField>

<ResponseField name="data.totalPages" type="number">
  Total number of pages
</ResponseField>

## Create API Key

<Endpoint method="POST" path="/api/tenant/api-keys">
  Create a new API key
</Endpoint>

<ParamField body="name" type="body" required>
  Name for the API key (e.g., "Production API Key")
</ParamField>

<ParamField body="environment" type="body" optional>
  Environment: `production` or `staging` (default: `production`)
</ParamField>

<ParamField body="permissions" type="body" required>
  Array of permission strings (e.g., `["read:conversations", "write:customers"]`)
</ParamField>

<ParamField body="expiresAt" type="body" optional>
  Expiration date (ISO 8601 format)
</ParamField>

<ParamField body="rotationPolicy" type="body" optional>
  Automatic rotation policy:

  ```json theme={null}
  {
    "enabled": true,
    "intervalDays": 90,
    "notifyDaysBefore": 7
  }
  ```
</ParamField>

<ParamField body="rateLimit" type="body" optional>
  Per-key rate limit override:

  ```json theme={null}
  {
    "requests": 1000,
    "window": "1h"
  }
  ```
</ParamField>

<ParamField body="ipWhitelist" type="body" optional>
  Array of allowed IP addresses
</ParamField>

<ResponseField name="success" type="boolean">
  true
</ResponseField>

<ResponseField name="data.key" type="string">
  The full API key (only shown once!)
</ResponseField>

<ResponseField name="data.keyPrefix" type="string">
  First 8 characters for display
</ResponseField>

<Warning>
  Save the API key immediately - it will not be shown again after this response!
</Warning>

## Get API Key

<Endpoint method="GET" path="/api/tenant/api-keys/:id">
  Get details of a specific API key
</Endpoint>

<ParamField path="id" type="string" required>
  API key ID
</ParamField>

## Update API Key

<Endpoint method="PUT" path="/api/tenant/api-keys/:id">
  Update an API key (name, permissions, etc.)
</Endpoint>

<ParamField path="id" type="string" required>
  API key ID
</ParamField>

<ParamField body="name" type="body" optional>
  New name for the API key
</ParamField>

<ParamField body="permissions" type="body" optional>
  Updated permissions array
</ParamField>

<ParamField body="isActive" type="body" optional>
  Activate or deactivate the key
</ParamField>

## Revoke API Key

<Endpoint method="POST" path="/api/tenant/api-keys/:id/revoke">
  Revoke (deactivate) an API key
</Endpoint>

<ParamField path="id" type="string" required>
  API key ID
</ParamField>

## Delete API Key

<Endpoint method="DELETE" path="/api/tenant/api-keys/:id">
  Permanently delete an API key
</Endpoint>

<ParamField path="id" type="string" required>
  API key ID
</ParamField>

<Warning>
  This action cannot be undone!
</Warning>

## Get API Key Usage

<Endpoint method="GET" path="/api/tenant/api-keys/:id/usage">
  Get usage statistics for an API key
</Endpoint>

<ParamField path="id" type="string" required>
  API key ID
</ParamField>

<ParamField query="month" type="string" optional>
  Month in YYYY-MM format (default: current month)
</ParamField>

<ResponseField name="success" type="boolean">
  true
</ResponseField>

<ResponseField name="data.totalRequests" type="number">
  Total requests in the month
</ResponseField>

<ResponseField name="data.requestsByEndpoint" type="object">
  Requests broken down by endpoint
</ResponseField>

<ResponseField name="data.requestsByMethod" type="object">
  Requests broken down by HTTP method
</ResponseField>
