# Usage Explorer
Monitor and analyze your xAI API usage with the Usage Explorer.
## Overview
The Usage Explorer in the xAI Console provides:
- Real-time usage tracking
- Historical usage data
- Cost breakdown by model
- API key-level analytics
## Accessing Usage Explorer
1. Go to console.x.ai
2. Navigate to "Usage" or "Usage Explorer"
3. Select your team
## Viewing Usage
### Usage Dashboard
The dashboard shows:
- Total tokens consumed
- Total cost
- Request count
- Usage trends over time
### Grouping Options
Group usage data by:
- **API Key**: Compare test vs production keys
- **Model**: See usage per model
- **Day/Week/Month**: Time-based analysis
- **Endpoint**: Usage by API endpoint
Example: Compare consumptions across test and production API keys by selecting "Group by: API Key"
## Filtering
Filter usage data by:
- Date range
- API key
- Model
- Team member
## Usage Metrics
### Token Metrics
| Metric | Description |
|--------|-------------|
| Input tokens | Tokens sent to the model |
| Output tokens | Tokens generated by the model |
| Cached tokens | Tokens served from cache |
| Reasoning tokens | Tokens used for reasoning (Grok 4) |
| Total tokens | Sum of all token types |
### Cost Metrics
| Metric | Description |
|--------|-------------|
| Input cost | Cost of input tokens |
| Output cost | Cost of output tokens |
| Tool cost | Cost of tool invocations |
| Total cost | Sum of all costs |
### Request Metrics
| Metric | Description |
|--------|-------------|
| Request count | Number of API requests |
| Success rate | Percentage of successful requests |
| Error rate | Percentage of failed requests |
| Avg latency | Average response time |
## Charts and Visualizations
### Usage Over Time
Line chart showing:
- Token usage trends
- Cost trends
- Request volume
### Usage by Model
Bar chart comparing:
- Tokens per model
- Cost per model
- Requests per model
### Usage by API Key
Pie chart showing distribution across API keys.
## Exporting Data
### Export Options
- CSV download
- JSON export
- PDF report
### Scheduled Reports
Set up automated reports:
- Daily summaries
- Weekly reports
- Monthly invoices
## Setting Alerts
### Usage Alerts
Configure alerts for:
- Token threshold reached
- Cost limit approaching
- Error rate spike
- Rate limit warnings
### Alert Channels
Receive alerts via:
- Email
- Webhook
- Console notification
## Cost Optimization Insights
The Usage Explorer may show:
- Cache hit rates
- Opportunities to use cheaper models
- High-cost operations
- Unused API keys
## Team Usage
For team admins:
- See usage by team member
- Identify heavy users
- Allocate budgets
- Set per-user limits
## API Access
Access usage data programmatically:
```python
# Using Management API
response = requests.get(
"https://management-api.x.ai/v1/usage",
headers={"Authorization": f"Bearer {management_key}"},
params={
"start_date": "2024-01-01",
"end_date": "2024-01-31",
"group_by": "model"
}
)
usage_data = response.json()
```
## Best Practices
1. **Regular monitoring**: Check usage weekly
2. **Set alerts**: Prevent surprise bills
3. **Compare periods**: Identify trends
4. **Optimize high-cost operations**: Review expensive requests
5. **Clean up unused keys**: Remove inactive API keys