Appearance
Cost Transparency
Track and control costs for every MCP agent in real-time.
Real-time Cost Tracking
Every tool invocation includes cost information:
json
{
"tool": "llm/chat",
"response": {...},
"cost": {
"input_tokens": 150,
"output_tokens": 200,
"total": 0.0035
}
}Session Costs
Track costs per agent session:
bash
curl https://api.gateflow.ai/v1/mcp/sessions/sess_abc123/cost \
-H "Authorization: Bearer gw_prod_..."Response:
json
{
"session_id": "sess_abc123",
"agent_id": "agent_support_bot",
"started_at": "2024-01-15T10:00:00Z",
"cost": {
"total": 0.45,
"by_tool": {
"llm/chat": 0.40,
"retrieval/search": 0.05
}
},
"limits": {
"session_limit": 5.00,
"remaining": 4.55
}
}Cost Limits
Per-Session Limits
yaml
permissions:
rate_limits:
cost_per_session: 5.00 # USDWhen reached:
json
{
"error": "session_cost_limit_exceeded",
"message": "Session cost limit of $5.00 reached",
"spent": 5.02
}Daily Limits
yaml
permissions:
rate_limits:
cost_per_day: 100.00 # USDMonthly Limits
yaml
permissions:
rate_limits:
cost_per_month: 2000.00 # USDCost Alerts
Configure alerts before limits are hit:
bash
curl -X POST https://api.gateflow.ai/v1/mcp/alerts \
-H "Authorization: Bearer gw_prod_..." \
-H "Content-Type: application/json" \
-d '{
"agent_id": "agent_123",
"condition": {
"metric": "session_cost",
"threshold": 4.00
},
"notify": ["slack"]
}'Cost Analytics
By Agent
bash
curl https://api.gateflow.ai/v1/mcp/analytics/cost \
-H "Authorization: Bearer gw_prod_..." \
-G -d "group_by=agent" -d "period=30d"By Tool
bash
curl https://api.gateflow.ai/v1/mcp/analytics/cost \
-H "Authorization: Bearer gw_prod_..." \
-G -d "group_by=tool" -d "period=30d"Agent Self-Inspection
Agents can check their own costs:
python
# Using the whoami tool
my_usage = await agent.tools.whoami()
print(f"Session cost: ${my_usage.session_cost}")
print(f"Remaining budget: ${my_usage.cost_remaining}")Best Practices
- Set conservative limits initially, increase as needed
- Use alerts at 80% of limits
- Review costs weekly to identify optimization opportunities
- Use cheaper models for simple tasks
Next Steps
- Rate Limits - Request rate limiting
- Audit Logging - Track all agent activity