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

# Observability

> Complete visibility into every AI request across your entire codebase

# Observability

The AI Gateway provides complete visibility into every AI request made from your applications or development tools. Know exactly what data is being sent, track usage patterns, and identify issues before they become problems.

## The Problem

When using AI providers directly, you have limited visibility:

* **What code is being sent?** You don't know exactly what context is included
* **Are secrets exposed?** API keys and passwords might be in the request
* **How much are you spending?** Token usage is hard to track across tools
* **What's failing?** Errors are logged on the provider's side, not yours

## Complete Request Logging

Every request through the AI Gateway is logged with full details:

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-request-detail.png" alt="Request detail view" />
</Frame>

### What's Logged

| Field             | Description                                |
| ----------------- | ------------------------------------------ |
| **Timestamp**     | When the request was made                  |
| **Request Body**  | Full content sent to the AI provider       |
| **Response Body** | Complete response received                 |
| **Model**         | Which AI model was used                    |
| **Tokens**        | Input, output, and total token counts      |
| **Latency**       | Response time in milliseconds              |
| **User ID**       | Which user made the request (if provided)  |
| **Session ID**    | Session tracking for conversation grouping |
| **Status**        | Success, error, or blocked                 |

### Viewing Logs

Access logs at [app.leanmcp.com/observability](https://app.leanmcp.com/observability):

1. Open [app.leanmcp.com/observability](https://app.leanmcp.com/observability)
2. Use filters to narrow down:
   * Date range
   * Model
   * User ID
   * Status (success/error/blocked)
   * Contains text

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-log-filters.png" alt="Log filtering options" />
</Frame>

## See Your Entire Codebase

When using AI coding assistants, the gateway shows you exactly what's being sent:

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-code-context.png" alt="Code context visibility" />
</Frame>

### What Gets Sent to AI

AI assistants typically send:

* **The file you're editing**
* **Surrounding context** from nearby files
* **Open tabs** in your editor
* **Terminal output**
* **Error messages**

With the gateway, you can see all of this - no more guessing what context is included.

### Identifying Sensitive Data

The gateway automatically detects potentially sensitive data:

<CardGroup cols={2}>
  <Card title="Credentials" icon="key">
    * API keys (AWS, GitHub, etc.)
    * Database passwords
    * OAuth tokens
    * Private keys
  </Card>

  <Card title="Personal Data" icon="user-shield">
    * Email addresses
    * Phone numbers
    * Social security numbers
    * Credit card numbers
  </Card>

  <Card title="Internal Data" icon="building">
    * Internal URLs
    * Private IP addresses
    * Server names
    * Database connection strings
  </Card>

  <Card title="Business Data" icon="briefcase">
    * Customer data
    * Financial figures
    * Proprietary algorithms
    * Trade secrets
  </Card>
</CardGroup>

## Download and Analyze

### Export Options

Export your data for analysis:

* **JSON** - Full structured data for programmatic analysis
* **CSV** - Spreadsheet-compatible for reporting
* **Filtered exports** - Only export what you need

```bash theme={null}
# Example: Export last 7 days
curl -X GET "https://api.leanmcp.com/gateway/logs?days=7" \
  -H "Authorization: Bearer your-api-key" \
  -o logs.json
```

### What You Can Discover

<AccordionGroup>
  <Accordion title="Sensitive data exposure">
    Search logs for patterns like API keys, passwords, or personal data to find and remediate exposure.
  </Accordion>

  <Accordion title="Usage patterns">
    Understand which features generate the most AI requests and optimize accordingly.
  </Accordion>

  <Accordion title="Cost drivers">
    Identify which requests use the most tokens and find opportunities to reduce costs.
  </Accordion>

  <Accordion title="Error patterns">
    Find common failure modes and fix issues before users report them.
  </Accordion>
</AccordionGroup>

## Real-Time Monitoring

### Live Log Stream

Watch requests in real-time:

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-live-stream.png" alt="Live log stream" />
</Frame>

* **Instant visibility** - see requests as they happen
* **Error highlighting** - failed requests are immediately visible
* **Sensitive data alerts** - get notified when sensitive patterns are detected

### Metrics Dashboard

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/leanmcp/images/ai-gateway-metrics.png" alt="Metrics dashboard" />
</Frame>

Track key metrics:

* **Requests per minute/hour/day**
* **Token usage over time**
* **Error rate trends**
* **Latency percentiles**
* **Cost accumulation**

## Alerts and Notifications

Set up alerts for important events:

### Available Alert Types

| Alert                       | Trigger                                       |
| --------------------------- | --------------------------------------------- |
| **Sensitive Data Detected** | When credentials or PII are found in requests |
| **High Error Rate**         | When error rate exceeds threshold             |
| **Usage Spike**             | When request volume suddenly increases        |
| **Budget Warning**          | When approaching spending limits              |
| **Unusual Pattern**         | When usage deviates from normal               |

### Configuration

```typescript theme={null}
// Set up alerts via API
await leanmcp.gateway.createAlert({
  type: 'sensitive_data_detected',
  channels: ['email', 'slack'],
  config: {
    patterns: ['api_key', 'password', 'secret'],
    severity: 'high',
  }
});
```

## Integration with Your Tools

### Windsurf / Cursor Usage

See exactly what your coding assistant sends:

1. Configure your IDE to use the gateway
2. Code normally
3. Check [app.leanmcp.com/observability](https://app.leanmcp.com/observability) to see what context was included

<Tip>
  Review your logs after coding sessions to understand what data your AI assistant accessed.
</Tip>

### Application Requests

For your own applications, add context headers:

```typescript theme={null}
const response = await client.chat.completions.create({
  model: 'gpt-5.2',
  messages: messages,
}, {
  headers: {
    'X-Request-Source': 'mobile-app',
    'X-Feature': 'chat-completion',
    'X-User-ID': userId,
  }
});
```

These headers are logged, making it easy to filter and analyze requests.

## Data Retention

| Plan           | Retention              |
| -------------- | ---------------------- |
| **Free**       | 7 days                 |
| **Pro**        | 30 days                |
| **Enterprise** | 90 days (customizable) |

<Note>
  Export data regularly if you need longer retention. All exports are available for download within the retention period.
</Note>

## Next Steps

<CardGroup cols={2}>
  <Card title="Security Features" icon="shield" href="/ai-gateway/security">
    Block sensitive data from being sent
  </Card>

  <Card title="Token Optimization" icon="chart-pie" href="/ai-gateway/token-optimization">
    Use insights to reduce costs
  </Card>
</CardGroup>

***

<Card title="Open your Observability Dashboard →" icon="eye" href="https://app.leanmcp.com/observability" color="#ff6b35">
  View all your logged AI requests at **app.leanmcp.com/observability**
</Card>
