> ## 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.

# API Usage Export

> Export detailed API key usage data to CSV format for cost analysis, monitoring, and billing reconciliation.

<Info>
  API usage exports are available to workspace administrators and provide detailed cost breakdowns for each API key over your selected time period.
</Info>

<Card title="Open API Settings" icon="chart-line" href="https://app.langdock.com/settings/workspace/products/api">
  View analytics and export usage data for your API keys.
</Card>

## Accessing API Usage Export

Navigate to your API settings page to view analytics and export detailed usage data for your API keys.

<Steps>
  <Step title="Open API Settings">
    Go to **Settings > API** in your workspace settings
  </Step>

  <Step title="View Analytics">
    Review the API key analytics displayed on the page
  </Step>

  <Step title="Select Time Period">
    Choose your desired time frame from the timeframe selector (default: last 30 days)
  </Step>

  <Step title="Export to CSV">
    Click the **Export** button to download a CSV file with detailed API usage data
  </Step>
</Steps>

## Time Period Selection

The export includes all API calls made within the selected timeframe:

* **Default period**: Last 30 days
* **Custom ranges**: Select any timeframe using the timeframe selector
* Data is filtered based on the date/timestamp of each API call

<Note>
  The same timeframe selection applies to both the analytics visualization and the CSV export.
</Note>

## Export Data Structure

The CSV export contains one row per API call with detailed cost and performance information.

### Column Definitions

| Column                             | Description                                        |
| ---------------------------------- | -------------------------------------------------- |
| Date                               | Date and timestamp of the API call (UTC)           |
| API Key ID                         | Unique identifier of the API key used              |
| API Key Name                       | Human-readable name of the API key                 |
| Provider                           | AI provider used for the request                   |
| Model                              | Specific model name                                |
| Input Tokens                       | Number of tokens in the request prompt             |
| Output Tokens                      | Number of tokens in the model's response           |
| Completion Time (ms)               | Time taken to complete the request in milliseconds |
| Input Token Price (USD/1M tokens)  | Cost per 1 million input tokens                    |
| Output Token Price (USD/1M tokens) | Cost per 1 million output tokens                   |

<Note>
  The export includes both completion and embedding API calls. For embedding calls, the Output Tokens column will be empty.
</Note>

## Calculating Costs

<Info>
  **What is a token?** A token is a piece of text (roughly a word or word fragment) that the model processes. On average, 1 token equals about 4 characters. API call pricing is based on the number of tokens processed.
</Info>

To calculate the cost of an individual API call, use the following formula:

```
Total Cost = (input_tokens × input_token_price_per_1m / 1,000,000) +
             (output_tokens × output_token_price_per_1m / 1,000,000)
```

### Example Calculation

For an API call with:

* 500 input tokens
* 1,200 output tokens
* Input price: \$2.50 per 1M tokens
* Output price: \$10.00 per 1M tokens

```
Input Cost  = 500 × $2.50 / 1,000,000 = $0.00125
Output Cost = 1,200 × $10.00 / 1,000,000 = $0.01200
Total Cost  = $0.01325
```

<Tip>
  To calculate the total cost for an API key, sum the individual costs across all rows for that key in your spreadsheet application.
</Tip>

## Use Cases

### Cost Monitoring

Track spending across different API keys to identify high-usage keys and optimize costs.

### Billing Reconciliation

Reconcile API usage with invoices and verify charges from AI providers.

### Performance Analysis

Analyze completion times across different models and providers to optimize response times.

### Usage Patterns

Identify peak usage times and model preferences to inform capacity planning.

## Export Limits

<Warning>
  Exports are limited to 1,000,000 rows. If your export exceeds this limit, narrow your date range.
</Warning>

## Data Privacy

* API key IDs and names are included for administrative visibility
* No end-user personal information is included in API usage exports
* Data reflects actual API calls made through your workspace
