Skip to main content

AI Analytics

Retrieve usage, cost, and performance analytics for AI models managed by the Strongly AI Gateway. All analytics endpoints are read-only and support date range filtering.


GET /api/v1/ai/analytics/usage

Get usage statistics

Returns aggregated usage statistics including request counts and token consumption, optionally broken down by time period.

Scope: ai-gateway:read

Parameters:

NameInTypeRequiredDescription
startDatequerystringNoStart of date range (ISO 8601). Defaults to 30 days ago
endDatequerystringNoEnd of date range (ISO 8601). Defaults to now
modelIdquerystringNoFilter by specific model ID
providerquerystringNoFilter by provider: openai, anthropic, google, etc.
granularityquerystringNoTime granularity: hour, day, week, month. Default: day

Response: 200 OK

{
"data": {
"totalRequests": 145230,
"totalTokens": 28500000,
"promptTokens": 18200000,
"completionTokens": 10300000,
"period": "custom",
"startDate": "2025-01-01T00:00:00.000Z",
"endDate": "2025-02-07T23:59:59.000Z",
"modelId": null,
"provider": null,
"granularity": "day",
"breakdown": [
{
"date": "2025-02-06T00:00:00.000Z",
"requests": 4200,
"totalTokens": 820000,
"promptTokens": 520000,
"completionTokens": 300000
},
{
"date": "2025-02-07T00:00:00.000Z",
"requests": 3800,
"totalTokens": 750000,
"promptTokens": 480000,
"completionTokens": 270000
}
]
},
"meta": { "requestId": "req_abc123" }
}

GET /api/v1/ai/analytics/costs

Get cost breakdown

Returns cost data broken down by model, provider, or time period. Costs are calculated based on provider pricing and token usage.

Scope: ai-gateway:read

Parameters:

NameInTypeRequiredDescription
startDatequerystringNoStart of date range (ISO 8601). Defaults to 30 days ago
endDatequerystringNoEnd of date range (ISO 8601). Defaults to now
modelIdquerystringNoFilter by specific model ID
providerquerystringNoFilter by provider
groupByquerystringNoGroup results by: model, provider, day, week, month. Default: model

Response: 200 OK

{
"data": {
"totalCost": 1245.67,
"currency": "USD",
"period": "custom",
"startDate": "2025-01-01T00:00:00.000Z",
"endDate": "2025-02-07T23:59:59.000Z",
"modelId": null,
"provider": null,
"groupBy": "model",
"byModel": [
{
"modelId": "model_abc123",
"modelName": "GPT-4 Production",
"provider": "openai",
"cost": 890.45,
"requests": 52000,
"totalTokens": 15000000
},
{
"modelId": "model_def456",
"modelName": "Claude 3 Opus",
"provider": "anthropic",
"cost": 355.22,
"requests": 28000,
"totalTokens": 9500000
}
],
"byProvider": [
{
"provider": "openai",
"cost": 890.45,
"requests": 52000,
"totalTokens": 15000000
},
{
"provider": "anthropic",
"cost": 355.22,
"requests": 28000,
"totalTokens": 9500000
}
]
},
"meta": { "requestId": "req_abc123" }
}

GET /api/v1/ai/analytics/performance

Get performance metrics

Returns latency, error rate, and throughput statistics for AI inference requests.

Scope: ai-gateway:read

Parameters:

NameInTypeRequiredDescription
startDatequerystringNoStart of date range (ISO 8601). Defaults to 30 days ago
endDatequerystringNoEnd of date range (ISO 8601). Defaults to now
modelIdquerystringNoFilter by specific model ID
providerquerystringNoFilter by provider

Response: 200 OK

{
"data": {
"startDate": "2025-01-01T00:00:00.000Z",
"endDate": "2025-02-07T23:59:59.000Z",
"modelId": null,
"provider": null,
"avgLatencyMs": 485,
"p50LatencyMs": 320,
"p95LatencyMs": 1200,
"p99LatencyMs": 2800,
"errorRate": 0.015,
"throughput": 45.2
},
"meta": { "requestId": "req_abc123" }
}
FieldTypeDescription
avgLatencyMsnumberMean request latency in milliseconds
p50LatencyMsnumber50th percentile (median) latency
p95LatencyMsnumber95th percentile latency
p99LatencyMsnumber99th percentile latency
errorRatenumberFraction of requests that failed (0.0 - 1.0)
throughputnumberAverage requests per minute during the period

GET /api/v1/ai/analytics/time-series

Get time-series data

Returns time-series data points for a specific metric, suitable for charting and trend analysis.

Scope: ai-gateway:read

Parameters:

NameInTypeRequiredDescription
startDatequerystringNoStart of date range (ISO 8601). Defaults to 7 days ago
endDatequerystringNoEnd of date range (ISO 8601). Defaults to now
modelIdquerystringNoFilter by specific model ID
metricquerystringNoMetric to chart: requests, tokens, latency, errors, cost. Default: requests
granularityquerystringNoTime granularity: hour, day, week, month. Default: hour
providerquerystringNoFilter by provider

Response: 200 OK

{
"data": {
"metric": "requests",
"granularity": "hour",
"startDate": "2025-02-06T00:00:00.000Z",
"endDate": "2025-02-07T23:59:59.000Z",
"modelId": null,
"provider": null,
"points": [
{
"timestamp": "2025-02-06T00:00:00.000Z",
"value": 185
},
{
"timestamp": "2025-02-06T01:00:00.000Z",
"value": 142
},
{
"timestamp": "2025-02-06T02:00:00.000Z",
"value": 98
}
]
},
"meta": { "requestId": "req_abc123" }
}

GET /api/v1/ai/analytics/providers

Get per-provider statistics

Returns aggregated statistics grouped by AI provider, useful for comparing provider performance and costs side by side.

Scope: ai-gateway:read

Parameters:

NameInTypeRequiredDescription
startDatequerystringNoStart of date range (ISO 8601). Defaults to 30 days ago
endDatequerystringNoEnd of date range (ISO 8601). Defaults to now

Response: 200 OK

{
"data": {
"startDate": "2025-01-01T00:00:00.000Z",
"endDate": "2025-02-07T23:59:59.000Z",
"providers": [
{
"provider": "openai",
"models": 5,
"totalRequests": 82000,
"totalTokens": 18500000,
"totalCost": 890.45,
"avgLatencyMs": 420,
"errorRate": 0.012
},
{
"provider": "anthropic",
"models": 3,
"totalRequests": 45000,
"totalTokens": 12000000,
"totalCost": 355.22,
"avgLatencyMs": 550,
"errorRate": 0.008
},
{
"provider": "google",
"models": 2,
"totalRequests": 18230,
"totalTokens": 4200000,
"totalCost": 125.80,
"avgLatencyMs": 380,
"errorRate": 0.018
}
]
},
"meta": { "requestId": "req_abc123" }
}

Response Models Reference

UsageStats

FieldTypeDescription
totalRequestsintegerTotal number of inference requests
totalTokensintegerTotal tokens consumed (prompt + completion)
promptTokensintegerTotal input/prompt tokens
completionTokensintegerTotal output/completion tokens
periodstringTime period label (custom, last-7d, last-30d)
startDatestringPeriod start (ISO 8601)
endDatestringPeriod end (ISO 8601)
modelIdstringApplied model filter, or null
providerstringApplied provider filter, or null
granularitystringTime bucket size: hour, day, week, month
breakdownarrayTime-bucketed usage data points

CostBreakdown

FieldTypeDescription
totalCostnumberTotal cost in the specified currency
currencystringCurrency code (e.g., USD)
periodstringTime period label
startDatestringPeriod start (ISO 8601)
endDatestringPeriod end (ISO 8601)
modelIdstringApplied model filter, or null
providerstringApplied provider filter, or null
groupBystringGrouping dimension: model, provider, day, week, month
byModelarrayCost breakdown per model
byProviderarrayCost breakdown per provider

PerformanceStats

FieldTypeDescription
startDatestringPeriod start (ISO 8601)
endDatestringPeriod end (ISO 8601)
modelIdstringApplied model filter, or null
providerstringApplied provider filter, or null
avgLatencyMsnumberMean request latency in milliseconds
p50LatencyMsnumber50th percentile (median) latency in milliseconds
p95LatencyMsnumber95th percentile latency in milliseconds
p99LatencyMsnumber99th percentile latency in milliseconds
errorRatenumberFraction of requests that returned errors (0.0 - 1.0)
throughputnumberAverage requests per minute