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

# Export API Key Usage

> API endpoint to export usage and cost by API key

This endpoint exports API usage grouped by API key for the selected period.

<Warning>
  **Using a dedicated deployment?**

  Replace `api.langdock.com` with `<your-deployment>/api/public` in all requests.
</Warning>

<Info>
  For details on prerequisites and rate limits, please refer to the [main Usage Export API documentation](/en/developer/usage-export-api/intro-to-usage-export-api).
</Info>

<Info>
  Langdock intentionally blocks browser-origin requests to protect your API key and ensure your applications remain secure. For more information, please see our guide on [API Key Best Practices](/en/admin/ai-adoption-and-rollout/best-practices/api-key-best-practices).
</Info>

## Data Included

By default, the API key export returns one row per API key.

| Column           | Description              |
| ---------------- | ------------------------ |
| `period_start`   | Start date of the report |
| `period_end`     | End date of the report   |
| `org_id`         | ID of the workspace      |
| `api_key_id`     | ID of the API key        |
| `api_key_name`   | Name of the API key      |
| `requests`       | Number of API requests   |
| `total_cost_usd` | API usage cost in USD    |

### Additional Columns for BYOK Workspaces

| Column                  | Description                                  |
| ----------------------- | -------------------------------------------- |
| `sum_prompt_tokens`     | Total input tokens                           |
| `sum_completion_tokens` | Total output tokens                          |
| `cached_prompt_tokens`  | Cache-read input tokens                      |
| `cache_creation_tokens` | Cache-write input tokens                     |
| `no_cache_tokens`       | Input tokens that were not served from cache |

## Grouped Export

Use `group_by=model` to return one row per API key and model.


## OpenAPI

````yaml POST /export/api-keys
openapi: 3.0.0
info:
  title: Langdock API
  version: 3.0.0
servers:
  - url: https://api.langdock.com
security:
  - bearerAuth: []
paths:
  /export/api-keys:
    post:
      tags:
        - Usage Export
      summary: Export API key usage data
      description: Export detailed usage and cost data grouped by API key
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UsageExportModelGroupByRequest'
            example:
              from:
                date: '2024-01-01T00:00:00.000Z'
                timezone: UTC
              to:
                date: '2024-01-31T23:59:59.999Z'
                timezone: UTC
              group_by: model
      responses:
        '200':
          description: Export successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageExportResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageExportError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageExportError'
        '404':
          description: No data found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageExportError'
components:
  schemas:
    UsageExportModelGroupByRequest:
      allOf:
        - $ref: '#/components/schemas/UsageExportRequest'
        - type: object
          properties:
            group_by:
              type: string
              description: Optional aggregation dimension.
              enum:
                - model
    UsageExportResponse:
      type: object
      description: Successful response from usage export endpoints
      properties:
        success:
          type: boolean
          description: Indicates if the export was successful
          example: true
        data:
          type: object
          description: Export data information
          properties:
            filePath:
              type: string
              description: Path to the generated export file
              example: >-
                agents-usage/workspace-id/agents-usage-2024-01-01-2024-01-31-abc12345.csv
            downloadUrl:
              type: string
              format: uri
              description: Signed URL to download the export file
              example: https://storage.example.com/signed-url
            dataType:
              type: string
              description: Type of data exported
              enum:
                - assistants
                - agents
                - api_keys
                - users
                - projects
                - models
              example: assistants
            recordCount:
              type: integer
              description: Number of records in the export
              example: 1250
            dateRange:
              type: object
              description: Actual date range of the exported data
              properties:
                from:
                  type: string
                  format: date-time
                  description: Start date of the export
                  example: '2024-01-01T00:00:00.000Z'
                to:
                  type: string
                  format: date-time
                  description: End date of the export
                  example: '2024-01-31T23:59:59.999Z'
              required:
                - from
                - to
          required:
            - filePath
            - downloadUrl
            - dataType
            - recordCount
            - dateRange
      required:
        - success
        - data
    UsageExportError:
      type: object
      description: Error response from usage export endpoints
      properties:
        error:
          type: string
          description: Error type
          example: No data found
        message:
          type: string
          description: Detailed error message
          example: No usage data found for the selected period
      required:
        - error
        - message
    UsageExportRequest:
      type: object
      description: Request body for usage export endpoints
      properties:
        from:
          type: object
          description: Start date and timezone for the export
          properties:
            date:
              type: string
              format: date-time
              description: Start date in ISO 8601 format
              example: '2024-01-01T00:00:00.000Z'
            timezone:
              type: string
              description: Timezone for the date range
              example: UTC
          required:
            - date
            - timezone
        to:
          type: object
          description: End date and timezone for the export
          properties:
            date:
              type: string
              format: date-time
              description: End date in ISO 8601 format
              example: '2024-01-31T23:59:59.999Z'
            timezone:
              type: string
              description: Timezone for the date range
              example: UTC
          required:
            - date
            - timezone
      required:
        - from
        - to
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"

````