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

# Monitoring

> Track token consumption, resource usage, and costs in your PLai projects

Costs vary widely by model and provider, and a single expensive workflow can quietly drive up your bill without anyone noticing. Monitoring aggregates usage as it happens so you can catch spikes early instead of finding out at invoice time.

***

## What Monitoring Shows

Monitoring is a **project-level dashboard** that tracks:

* **Token Consumption** - Input and output tokens by LLM model
* **Cost Breakdown** - Costs by provider (Claude, GPT-4, Perplexity, etc.)
* **Service Usage** - Resource consumption by tool type <Badge color="blue" size="xs">In Roadmap</Badge>
* **Trends** - Usage patterns over time <Badge color="blue" size="xs">In Roadmap</Badge>
* **Budget Tracking** - Spending vs budget limits <Badge color="blue" size="xs">In Roadmap</Badge>

<Tip>
  Monitor shows CONSUMPTION and COSTS. For detailed analytics about agent performance, conversations, and execution logs, see [Agent Analytics](../agents/analytics.mdx).
</Tip>

***

## Cost Tracking

### Understanding Your Costs

**Cost structure**:

* **LLM Services** (Claude, GPT-4, etc.)
  * Based on tokens consumed
  * Different rates for input vs output
  * Rates vary by model
* **Tool Services** (Web Search, Code Execution, etc.)
  * Based on usage (searches, executions, calls)
  * Per-unit pricing or flat fees
  * Varies by service
* **External Services** (via API tools)
  * Billing by external provider
  * PLai may charge platform fee
  * Check service docs for pricing

### Cost Per Agent/Workflow

Track which agents or workflows are most expensive:

Estimated Cost Breakdown:

| Agent / Workflow         | Daily Cost | Avg Cost             | Weekly Cost |
| ------------------------ | ---------- | -------------------- | ----------- |
| Support Bot Agent        | \$8.50     | \$0.15 per request   | \$59.50     |
| Data Processing Workflow | \$12.30    | \$2.50 per execution | \$86.10     |
| Lead Scoring Agent       | \$3.20     | \$0.32 per lead      | \$22.40     |

<Tip>
  These are estimated breakdowns. For exact per-agent costs and usage details, check [Agent Analytics](../agents/analytics.mdx).
</Tip>

***

## Reducing Consumption

### Optimize Token Usage

|                    | Before (Expensive)                | After (Optimized)                   |
| ------------------ | --------------------------------- | ----------------------------------- |
| System prompt      | 1,000 tokens (verbose)            | 200 tokens (concise)                |
| Datasource context | 2,000 tokens (full context)       | 400 tokens (relevant excerpts only) |
| User input         | 100 tokens                        | 100 tokens                          |
| **Total input**    | **3,100 tokens → Cost: \$0.0093** | **700 tokens → Cost: \$0.0021**     |

Savings: 77% reduction

### Best Practices

<CardGroup cols={2}>
  <Card title="Concise Prompts" icon="edit">
    Every token costs. Be brief and specific.
  </Card>

  <Card title="Smart Context" icon="brain">
    Include only relevant information, not full datasets.
  </Card>

  <Card title="Cheaper Models" icon="trending-down">
    Use Haiku for simple tasks, Sonnet for complex.
  </Card>

  <Card title="Batch Processing" icon="stack">
    Process multiple requests together when possible.
  </Card>
</CardGroup>

### Example Optimization

**Email Support Bot**:

* **Problem**:
  * Current: 500 requests/day
  * Avg input tokens: 1,500 per request
  * Daily token cost: $2.25 (500 × 1,500 × $3/1M)
* **Optimization**:
  * Reduce context from 1,500 to 500 tokens
  * New daily token cost: $0.75 (500 × 500 × $3/1M)
  * Monthly savings: \$45 (66% reduction)

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Unexpected cost increase">
    **Steps:**

    1. Check which model/service increased
    2. Look at token consumption
    3. Review recent agent/workflow changes
    4. Optimize expensive components
    5. Set alerts to catch next time
  </Accordion>

  <Accordion title="Cost not updating">
    **Check:**

    * Monitor refreshes every 5-15 minutes
    * Some costs finalized at end of day/week
    * Different providers have different billing cycles
    * Wait a few hours for full update
  </Accordion>

  <Accordion title="Budget alert not working">
    **Verify:**

    * Budget is set in project settings
    * Alert threshold configured correctly
    * Notifications enabled
    * Check spam folder for alert emails
  </Accordion>

  <Accordion title="Need detailed usage breakdown">
    **Use:**

    * Agent Analytics for per-agent data
    * API endpoints for programmatic access
    * Export data for custom analysis
  </Accordion>
</AccordionGroup>

***

## Monitoring Best Practices

<CardGroup cols={2}>
  <Card title="Review Weekly" icon="calendar-week">
    Spend 5 minutes weekly checking consumption
  </Card>

  <Card title="Set Budgets" icon="wallet">
    Know your spending limits before issues arise
  </Card>

  <Card title="Enable Alerts" icon="bell">
    Get notified of cost spikes immediately
  </Card>

  <Card title="Optimize Early" icon="target">
    Don't wait for problems. Optimize as you build.
  </Card>
</CardGroup>

### Monitoring Checklist

* ✅ Check project monitoring dashboard daily
* ✅ Review cost trends weekly
* ✅ Set realistic budget limits
* ✅ Configure alert thresholds
* ✅ Identify expensive agents/workflows
* ✅ Optimize high-consumption components
* ✅ Export reports for stakeholders
* ✅ Archive data per retention policy

***

## Key Takeaways

✅ **Monitor tracks consumption** - Tokens and service usage\
✅ **Understand costs** - Different models and services cost differently\
✅ **Set budgets & alerts** - Avoid surprise bills\
✅ **Optimize early** - Reduce consumption before it becomes expensive\
✅ **Track trends** - Understand patterns and plan capacity

***

## Related Topics

* **[Agent Analytics](../agents/analytics.mdx)** - Conversations, executions, performance per agent
* **[Security & Compliance](./security-and-compliance.mdx)** - Audit logs and access tracking
* **[Organizations & Projects](./organizations-and-projects.mdx)** - Project-level management
* **API** - Programmatic access to detailed metrics and analytics
