# Monitor Production Usage

## User Intent

"How do I monitor API usage and costs? Show me usage tracking."

## Operation

**SDK Method**: `queryProjectUsage()`\
**Use Case**: Track API usage and billing

***

## Code Example (TypeScript)

```typescript
import { Graphlit } from 'graphlit-client';

const graphlit = new Graphlit();

// Query usage for date range
const usage = await graphlit.queryProjectUsage({
  startDate: '2024-01-01',
  endDate: '2024-01-31'
});

console.log('Usage Summary:');
console.log(`API Calls: ${usage.projectUsage.apiCallCount}`);
console.log(`Content Ingested: ${usage.projectUsage.contentCount}`);
console.log(`Storage Used: ${usage.projectUsage.storageBytes} bytes`);
console.log(`Embedding Tokens: ${usage.projectUsage.embeddingTokens}`);
console.log(`Completion Tokens: ${usage.projectUsage.completionTokens}`);

// Calculate estimated cost
const embeddingCost = (usage.projectUsage.embeddingTokens / 1000000) * 0.02;  // $0.02/1M
const completionCost = (usage.projectUsage.completionTokens / 1000000) * 15;  // GPT-4o pricing
const totalCost = embeddingCost + completionCost;

console.log(`\nEstimated Cost: $${totalCost.toFixed(2)}`);
```

***

## Monitoring Best Practices

1. **Track daily usage** to spot anomalies
2. **Set budget alerts** in Developer Portal
3. **Monitor cost per feature** separately
4. **Review usage monthly** for optimization
5. **Log slow queries** for performance tuning

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/production/production-monitoring-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
