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

# Logs Export

> Easily access your Prisma AIRS AI Gateway logs data for further analysis and reporting

> [!NOTE]
>
> [Data Service](https://docs.portkey.ai/docs/changelog/data-service.md) must be enabled to use the Logs Export feature in hybrid deployments.

At the AI Gateway, we understand the importance of data analysis and reporting for businesses and teams. That's why we provide a comprehensive logs export feature that allows you to download your AI Gateway logs data in a **structured format**, enabling you to gain valuable insights into your LLM usage, performance, costs, and more.

## Exporting Logs In-App

You can now export logs directly from the AI Gateway application by following these steps:

1. Navigate to the **Exports** section on the main sidebar.

2. Click the **Request Data** button in the top-right corner.

3. Configure your export parameters:
   * **Time Range**: Select the period for which you want to export logs
   * **Logs Limits**: Choose maximum number of logs or set a custom offset
   * **Requested Fields**: Select which data columns to include in your export

4. After setting your parameters, click **Request Export**.

## Available Export Fields

When configuring your log export, you can select from the following fields:

| Field Name | Description |
| - | - |
| ID | Unique identifier for the log entry |
| Trace ID | Identifier for tracing related requests |
| Created At | Timestamp of the request |
| Request | Request JSON payload |
| Response | Response JSON payload |
| AI Provider | Name of the AI provider used |
| AI Model | Name of the AI model used |
| Request Tokens | Number of tokens in the request |
| Response Tokens | Number of tokens in the response |
| Total Tokens | Total number of tokens (request + response) |
| Cost | Cost of the request in cents (USD) |
| Cost Currency | Currency of the cost (USD) |
| Response Time | Response time in milliseconds |
| Status Code | HTTP response status code |
| Config | Config ID used for the request |
| Prompt Slug | Prompt ID used for the request |
| Metadata | Custom metadata key-value pairs |

> [!NOTE]
>
> Admins can block specific fields from being exported. See [Restricting exportable fields](#restricting-exportable-fields) below.

5. Once your export is processed, you'll see it in the exports list with a status indicator:
   * **Draft**: Export job created but not yet started
   * **Success**: Export completed successfully
   * **Failure**: Export job failed. Click on the `Start Again` button to retry the job.

6. Clik on the **Start** button the dashboard to start the logs-export job

7. For completed exports, click the **Download** button to get your logs data file. You can

> [!NOTE]
>
> Currently we only support exporting 50k logs per job.

## Restricting Exportable Fields

Organisation owners and admins can prevent sensitive log fields — such as `request` and `response` payloads or `metadata` — from leaving the AI Gateway through exports.

Set `export_settings.deniedFields` on the organisation to apply the restriction everywhere:

```json theme={"system"}
{
  "export_settings": {
    "deniedFields": ["request", "response", "metadata"]
  }
}
```

Every entry must be a valid log export field id (`id`, `trace_id`, `created_at`, `request`, `response`, `ai_org`, `ai_model`, `req_units`, `res_units`, `total_units`, `request_url`, `cost`, `cost_currency`, `response_time`, `response_status_code`, `config`, `prompt_slug`, `metadata`).

Individual workspaces can set their own `export_settings` only if the organisation has enabled the `export_settings` [workspace override](https://docs.portkey.ai/docs/aigw/product/administration/enforce-default-config.md). Otherwise the organisation's list applies to all workspaces.

Creating or updating an export that requests a denied field is rejected. To check what a workspace is allowed to export before building a request, call:

```bash theme={"system"}
curl "https://aigw.portkey.ai/v1/logs/exports/field-restrictions?workspace_id=WORKSPACE_ID" \
  -H "Authorization: Bearer YOUR_PORTKEY_API_KEY"
```

## Export File Details

Exported logs are provided in JSONL format (JSON Lines), where each line is a valid JSON object representing a single log entry. This format is ideal for data processing and analysis with tools like Python's Pandas or other data analysis frameworks.

Each export includes:

* Up to 50,000 logs per export job (as shown in the preview panel)
* All fields selected during the export configuration
* A timestamp indicating when the export was created

## Use Cases for Exported Logs

With your exported logs data, you can:

* Generate custom reports for stakeholders
* Feed data into business intelligence tools
* Identify patterns in user behaviour and model performance

You can analyze your API usage patterns, monitor performance, optimize costs, and make data-driven decisions for your business or team.

## Exporting logs via API

You can programmatically export logs using the Log Export API. This follows an asynchronous workflow:

1. **Create an export job** — Define your export parameters
2. **Start the export** — Begin processing the export
3. **Poll for status** — Check until the job completes
4. **Download the file** — Retrieve the JSONL file via signed URL

### Prerequisites

* API key with `logs.export` scope enabled
* For completion logs, the `completion` scope may also be required

### Step 1: Create a log export

Create an export job by specifying the time range and fields you want to export.

```bash cURL theme={"system"}
curl -X POST "https://aigw.portkey.ai/v1/logs/exports" \
  -H "Authorization: Bearer YOUR_PORTKEY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filters": {
      "created_at": {
        "gte": "2024-01-01T00:00:00Z",
        "lte": "2024-01-31T23:59:59Z"
      }
    },
    "requested_data": [
      "id",
      "trace_id",
      "created_at",
      "request",
      "response",
      "ai_provider",
      "ai_model",
      "request_tokens",
      "response_tokens",
      "total_tokens",
      "cost",
      "response_time",
      "status_code"
    ]
  }'
```

### Step 2: Start the export

Once the export job is created, start processing it.

```python Python theme={"system"}
client.logs.exports.start(export_id)
print("Export job started")
```

```typescript Node.js theme={"system"}
await client.logs.exports.start(exportId);
console.log("Export job started");
```

```bash cURL theme={"system"}
curl -X POST "https://aigw.portkey.ai/v1/logs/exports/{export_id}/start" \
  -H "Authorization: Bearer YOUR_PORTKEY_API_KEY"
```

### Step 3: Poll for completion

Check the export status until it returns `success`.

```python Python theme={"system"}
import time

while True:
    status = client.logs.exports.retrieve(export_id)
    print(f"Status: {status.status}")

    if status.status == "success":
        print("Export completed!")
        break
    elif status.status == "failure":
        print(f"Export failed: {status.error}")
        break

    time.sleep(5)  # Wait 5 seconds before polling again
```

```typescript Node.js theme={"system"}
const pollForCompletion = async (exportId: string) => {
  while (true) {
    const status = await client.logs.exports.retrieve(exportId);
    console.log(`Status: ${status.status}`);

    if (status.status === "success") {
      console.log("Export completed!");
      break;
    } else if (status.status === "failure") {
      console.log(`Export failed: ${status.error}`);
      break;
    }

    await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5 seconds
  }
};

await pollForCompletion(exportId);
```

```bash cURL theme={"system"}
curl "https://aigw.portkey.ai/v1/logs/exports/{export_id}" \
  -H "Authorization: Bearer YOUR_PORTKEY_API_KEY"
```

### Step 4: Download the export

Once the export is complete, retrieve the signed download URL.

```python Python theme={"system"}
download_response = client.logs.exports.download(export_id)
download_url = download_response.url

print(f"Download URL: {download_url}")

# Download the file
import requests

response = requests.get(download_url)
with open("logs_export.jsonl", "wb") as f:
    f.write(response.content)

print("Logs exported to logs_export.jsonl")
```

```typescript Node.js theme={"system"}
const downloadResponse = await client.logs.exports.download(exportId);
const downloadUrl = downloadResponse.url;

console.log(`Download URL: ${downloadUrl}`);

// Download the file using fetch
const fileResponse = await fetch(downloadUrl);
const fileContent = await fileResponse.text();

// Save to file (Node.js)
import fs from "fs";
fs.writeFileSync("logs_export.jsonl", fileContent);

console.log("Logs exported to logs_export.jsonl");
```

```bash cURL theme={"system"}
# Get the download URL
curl "https://aigw.portkey.ai/v1/logs/exports/{export_id}/download" \
  -H "Authorization: Bearer YOUR_PORTKEY_API_KEY"

# Then download using the returned URL
curl -o logs_export.jsonl "{signed_download_url}"
```

### Complete example

Here's a complete script that creates, starts, monitors, and downloads a log export:

### API reference

| Endpoint | Description |
| - | - |
| `POST /v1/logs/exports` | Create a new export job |
| `POST /v1/logs/exports/{id}/start` | Start processing an export |
| `GET /v1/logs/exports/{id}` | Retrieve export status |
| `GET /v1/logs/exports/{id}/download` | Get signed download URL |
| `POST /v1/logs/exports/{id}/cancel` | Cancel an in-progress export |
| `DELETE /v1/logs/exports/{id}` | Delete an export job |
| `GET /v1/logs/{id}` | Fetch a single log entry |

## Support

> **[(Deprecated) Logs Export Page](https://docs.portkey.ai/docs/product/observability/logs-export-deprecated)**


## Related topics

- [Complete Logs Export](https://docs.portkey.ai/docs/aigw/product/enterprise-offering/otel/complete-logs.md)
- [Analytics Export](https://docs.portkey.ai/docs/aigw/product/enterprise-offering/otel/analytics.md)
- [OpenTelemetry(OTel) Export](https://docs.portkey.ai/docs/aigw/product/enterprise-offering/otel/otel.md)
- [Configure Logs Access Permissions for Workspace](https://docs.portkey.ai/docs/aigw/product/administration/configure-logs-access-permissions-in-workspace.md)
- [Error AB03: You do not have enough permissions](https://docs.portkey.ai/docs/aigw/help-center/you-do-not-have-enough-permissions.md)


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