Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/content/docs/ai-gateway/observability/analytics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: Analytics
description: View AI Gateway metrics for requests, tokens, caching, errors, and costs in the dashboard or via GraphQL.
pcx_content_type: reference
sidebar:
order: 2
products:
- ai-gateway
---
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/ai-gateway/observability/costs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Costs
description: Track and estimate token-based costs across AI providers using AI Gateway cost metrics.
pcx_content_type: reference
sidebar:
order: 2
order: 3
products:
- ai-gateway
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pcx_content_type: configuration
title: Custom metadata
description: Tag AI Gateway requests with custom metadata such as user IDs to improve log filtering and analysis.
sidebar:
order: 4
order: 6
products:
- ai-gateway
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Log classification
description: Classify AI Gateway traffic by task and assess whether each model matches the task requirements.
pcx_content_type: reference
sidebar:
order: 3.5
order: 5
badge:
text: Beta
variant: caution
Expand Down
66 changes: 15 additions & 51 deletions src/content/docs/ai-gateway/observability/logging/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@
pcx_content_type: reference
title: Logging
description: Store and inspect AI Gateway request logs including prompts, responses, tokens, costs, and DLP actions.
sidebar:
order: 1
products:
- ai-gateway
---

import { Render } from "~/components";

Logging is a fundamental building block for application development. Logs provide insights during the early stages of development and are often critical to understanding issues occurring in production.
Logs help you monitor requests and troubleshoot application issues. Each log can include the prompt, response, provider, timestamp, status, token usage, cost, duration, and user agent.

Your AI Gateway dashboard shows logs of individual requests, including the user prompt, model response, provider, timestamp, request status, token usage, cost, duration, and the user agent of the client that made the request. When [DLP](/ai-gateway/features/dlp/) policies are configured, logs for requests that trigger a DLP match also include the DLP action taken (Flag or Block), matched policy IDs, matched profile IDs, and the specific detection entries that were triggered. These logs persist, giving you the flexibility to store them for your preferred duration and do more with valuable request data.
When a request matches a [Data Loss Prevention (DLP)](/ai-gateway/features/dlp/) policy, its log can also include the action and matched policy details.

Each gateway has a storage limit based on your plan. You can customize this limit per gateway in your gateway settings. If your storage limit is reached, new logs will stop being saved. To continue saving logs, you must delete older logs to free up space for new logs.
To learn more about your plan limits, refer to [Limits](/ai-gateway/reference/limits/).
When [Guardrails](/ai-gateway/features/guardrails/) are turned on, Guardrails evaluation calls are also recorded in your logs.

We recommend using an authenticated gateway when storing logs to prevent unauthorized access and protects against invalid requests that can inflate log storage usage and make it harder to find the data you need. Learn more about setting up an [authenticated gateway](/ai-gateway/configuration/authentication/).
:::note[Logging eligibility]
New AI Gateway customers who create their first gateway on or after September 24, 2026 follow [Workers Logs pricing and retention](/workers/observability/logs/workers-logs/#pricing).

AI Gateway customers who created a gateway before September 24, 2026 use [Legacy Logs](/ai-gateway/observability/logging/legacy-logs/).
:::

Use an [authenticated gateway](/ai-gateway/configuration/authentication/) to prevent unauthorized access. Authentication also prevents invalid requests from increasing log volume.

## Default configuration

Logs, which include metrics as well as request and response data, are enabled by default for each gateway. This logging behavior will be uniformly applied to all requests in the gateway. If you are concerned about privacy or compliance and want to turn log collection off, you can go to settings and opt out of logs. If you need to modify the log settings for specific requests, you can override this setting on a per-request basis.
Logs are enabled by default for each gateway. This setting applies to all requests unless a request overrides it.

You can turn off collection for privacy or compliance requirements.

<Render file="logging" product="ai-gateway" />

Expand Down Expand Up @@ -91,48 +100,3 @@ If `cf-aig-collect-log` is set to `false`, the entire log entry (including metad
When [Data Loss Prevention (DLP)](/ai-gateway/features/dlp/) policies are enabled on a gateway, log entries for requests that trigger a DLP policy match include additional fields:

<Render file="dlp-log-fields" product="ai-gateway" />

These fields are available both in the dashboard log viewer and through the [Logs API](/api/resources/ai_gateway/subresources/logs/methods/list/). You can filter logs by **DLP Action** in the dashboard to view only flagged or blocked requests. For more details on DLP monitoring, refer to [Monitor DLP events](/ai-gateway/features/dlp/set-up-dlp/#monitor-dlp-events).

## Managing log storage

To manage your log storage effectively, you can:

- Set Storage Limits: Configure a limit on the number of logs stored per gateway in your gateway settings to ensure you only pay for what you need.
- Enable Automatic Log Deletion: Activate the Automatic Log Deletion feature in your gateway settings to automatically delete the oldest logs once the storage limit for your account is reached. This ensures new logs are always saved without manual intervention.

## How to delete logs

To manage your log storage effectively and ensure continuous logging, you can delete logs using the following methods:

### Automatic Log Deletion

​To maintain continuous logging within your gateway's storage constraints, enable Automatic Log Deletion in your Gateway settings. This feature automatically deletes the oldest logs once the storage limit for your account is reached, ensuring new logs are saved without manual intervention.

### Manual deletion

To manually delete logs through the dashboard, navigate to the Logs tab in the dashboard. Use the available filters such as status, cache, provider, cost, or any other options in the dropdown to refine the logs you wish to delete. Once filtered, select Delete logs to complete the action.

See full list of available filters and their descriptions below:

| Filter category | Filter options | Filter by description |
| --------------- | ------------------------------------------------------------ | --------------------------------------------------- |
| Status | error, status | error type or status. |
| Cache | cached, not cached | based on whether they were cached or not. |
| Provider | specific providers | the selected AI provider. |
| AI Models | specific models | the selected AI model. |
| Cost | less than, greater than | cost, specifying a threshold. |
| Request type | Workers AI Binding, WebSockets | the type of request. |
| Tokens | Total tokens, Tokens In, Tokens Out | token count (less than or greater than). |
| Duration | less than, greater than | request duration. |
| Feedback | equals, does not equal (thumbs up, thumbs down, no feedback) | feedback type. |
| Metadata Key | equals, does not equal | specific metadata keys. |
| Metadata Value | equals, does not equal | specific metadata values. |
| Log ID | equals, does not equal | a specific Log ID. |
| Event ID | equals, does not equal | a specific Event ID. |
| DLP Action | FLAG, BLOCK | the DLP action taken on the request. |
| User Agent | equals, does not equal, contains | the user agent of the client that made the request. |

### API deletion

You can programmatically delete logs using the AI Gateway API. For more comprehensive information on the `DELETE` logs endpoint, check out the [Cloudflare API documentation](/api/resources/ai_gateway/subresources/logs/methods/delete/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
pcx_content_type: reference
title: Legacy Logs
description: Manage logs for AI Gateway customers who created a gateway before September 24, 2026.
products:
- ai-gateway
---

:::note[Account eligibility]
Legacy Logs applies only to AI Gateway customers who created a gateway before September 24, 2026. Customers who create their first gateway on or after that date use [AI Gateway logging](/ai-gateway/observability/logging/).
:::

Legacy Logs provides an AI Gateway dashboard viewer and Logs API. To configure default collection or per-request headers, refer to [Logging](/ai-gateway/observability/logging/).

## View request details

The dashboard viewer shows individual requests for each gateway. It includes the shared request fields described in [Logging](/ai-gateway/observability/logging/).

## Manage storage

Each gateway has a configurable storage limit based on your plan. Workers Free accounts can store 100,000 logs across all gateways. Workers Paid accounts can store 10 million logs per gateway.

Each stored log can be up to 10 MB. Legacy Logs does not store logs exceeding that size.

Legacy Logs persists stored logs until you delete them.

When you reach a storage limit, Legacy Logs can stop saving logs or automatically delete the oldest logs. If saving stops, delete stored logs before Legacy Logs can save more.

For plan details, refer to [AI Gateway pricing](/ai-gateway/reference/pricing/#accounts-created-before-september-24-2026).

## Delete logs automatically

In your gateway settings, turn on **Automatic Log Deletion**. Legacy Logs deletes the oldest logs when your account reaches its storage limit.

## Delete logs manually

In the dashboard, open the gateway **Logs** tab. Apply filters, and then select **Delete logs**.

The dashboard supports these filters:

| Filter category | Filter options | Description |
| --------------- | ------------------------------------------------------------ | ---------------------------------------- |
| Status | Error, status | Matches an error type or status |
| Cache | Cached, not cached | Matches cache status |
| Provider | Specific providers | Matches an AI provider |
| AI models | Specific models | Matches an AI model |
| Cost | Less than, greater than | Compares cost with a threshold |
| Request type | Workers AI Binding, WebSockets | Matches the request type |
| Tokens | Total tokens, Tokens In, Tokens Out | Compares token count with a threshold |
| Duration | Less than, greater than | Compares duration with a threshold |
| Feedback | Equals, does not equal (thumbs up, thumbs down, no feedback) | Matches feedback |
| Metadata key | Equals, does not equal | Matches a metadata key |
| Metadata value | Equals, does not equal | Matches a metadata value |
| Log ID | Equals, does not equal | Matches a log ID |
| Event ID | Equals, does not equal | Matches an event ID |
| DLP action | `FLAG`, `BLOCK` | Matches the DLP action |
| User agent | Equals, does not equal, contains | Matches the requesting client user agent |

## Use the Logs API

The Legacy Logs API lets you [list stored logs](/api/resources/ai_gateway/subresources/logs/methods/list/). To delete matching logs programmatically, use the [`DELETE` logs endpoint](/api/resources/ai_gateway/subresources/logs/methods/delete/).
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import { Render, Tabs, TabItem } from "~/components";
AI Gateway allows you to securely export logs to an external storage location, where you can decrypt and process them.
You can toggle Workers Logpush on and off in the [Cloudflare dashboard](https://dash.cloudflare.com) settings. This product is available on the Workers Paid plan. For pricing information, refer to [Pricing](/ai-gateway/reference/pricing).

Workers Logpush works with [AI Gateway logging](/ai-gateway/observability/logging/) and [Legacy Logs](/ai-gateway/observability/logging/legacy-logs/).

This guide explains how to set up Workers Logpush for AI Gateway, generate an RSA key pair for encryption, and decrypt the logs once they are received.

You can store up to 10 million logs per gateway. If your limit is reached, new logs will stop being saved and will not be exported through Workers Logpush. To continue saving and exporting logs, you must delete older logs to free up space for new logs. Workers Logpush has a limit of 4 jobs and a maximum request size of 1 MB per log.
For Legacy Logs on Workers Paid, you can store 10 million logs per gateway. If saving stops at this limit, logs are not saved or exported. Delete older logs or turn on automatic deletion to resume exports.

Workers Logpush supports four jobs per account. Each exported log can be up to 1 MB.

:::note[Note]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: OpenTelemetry
description: Export AI Gateway trace spans to OpenTelemetry-compatible backends for distributed tracing and performance monitoring.
pcx_content_type: configuration
sidebar:
order: 5
order: 7
products:
- ai-gateway
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: User Insights
description: Track organization-wide AI spend, attribute usage to identities, and detect anomalous sessions in AI Gateway.
pcx_content_type: reference
sidebar:
order: 3
order: 4
products:
- ai-gateway
---
Expand Down
Loading
Loading