Skip to content
Longplay
Docs
Browse docs / Read usage analytics
On this page

Read usage analytics

Operation
readUsageAnalytics
Server SDK
readUsageAnalytics
Python
read_usage_analytics
Go
ReadUsageAnalytics
POST/api/v1/usage/analytics

Read scoped usage aggregates.

Markdown
API v1Updated

Request#

Credential
Server Key with credits:read. Call from your backend only.
SDK
JavaScript createLongplayServer().readUsageAnalytics · Python read_usage_analytics · Go ReadUsageAnalytics
Success
HTTP 200
request.shShell
curl -X POST "$LONGPLAY_API_URL/api/v1/usage/analytics" \  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \  -H "X-Indiana-Protocol: 0.10" \  -H "Content-Type: application/json" \  -d '{  "customerId": null,  "query": {    "range": {      "kind": "last_days",      "days": 7    },    "timezone": "UTC",    "filterBy": [],    "interval": "day",    "internal_feature_id": null,    "groupBy": "customer",    "entityId": null,    "topN": null,    "after": null,    "limit": 50  }}'

The response shows example data.

Body parameters#

application/json

customerIduuid | nullRequired

The Customer UUID. Required with a Server Key; omit it with a Customer Token.

queryobjectRequired

Query.

Show child fields
rangeobject | object | objectRequired

Time range.

Show child fields
kind"absolute" | "last_days" | "billing_cycles"Required

Kind; see the allowed values.

fromdate-timeOptional

Range start (ISO 8601).

todate-timeOptional

Range end (ISO 8601).

days1 | 7 | 30 | 90Optional

Number of days.

membershipIduuidOptional

membership ID.

countintegerOptional

For a billing_cycles range, how many of the membership's most recent billing cycles to cover (1–12); with includeCurrent: false, only completed cycles count.

min: 1 · max: 12

includeCurrentbooleanOptional

Whether to include the current period.

timezonestringRequired

Time zone.

maxLength: 100

filterByarrayRequired

Filter.

maxItems: 5

Show child fields
keystringRequired

Name of an event property to filter on (lowercase letters, digits and underscores); only events whose property equals one of values are included.

pattern: ^[a-z][a-z0-9_]{0,63}$

valuesarrayRequired

Values.

minItems: 1 · maxItems: 20

intervalenumRequired

Interval; see the allowed values.

Show allowed values

"hour""day""week""month"

internal_feature_iduuid | nullRequired

Feature ID.

entityIduuid | nullRequired

Entity ID within the current customer scope, for configured Entity and license Features.

topNinteger | nullRequired

Number of top items to return.

groupByenum | stringRequired

Group-by dimension.

afterobject | nullRequired

Pagination cursor: pass the value from the previous page; null for the first page.

Show child fields
bucketdate-timeRequired

Aggregation bucket.

groupstringRequired

Group.

maxLength: 240

isOtherbooleanRequired

Whether this row aggregates the remaining items.

internal_feature_iduuidRequired

Feature ID.

limitintegerRequired

Maximum records per page, subject to the contract limit.

min: 1 · max: 100

Response fields#

Every successful response includes requestId (this request's ID, for support) and scope (App and environment).

HTTP 200 · application/json

requestIduuidRequired

UUID the server generated for this HTTP request; include it when reporting a problem. It is not your business requestId.

scopeobjectRequired

The App and environment of this response. Headers only verify scope; they cannot switch key scope.

Show child fields
projectIdstringRequired

App ID bound to the credential.

minLength: 1

environmentenumRequired

Separate data scope: sandbox or live.

Show allowed values

"sandbox""live"

analyticsobjectRequired

The report page: the resolved from/to range, interval and timezone, the aggregated rows and nextCursor for the next page.

Show child fields
fromdate-timeRequired

Range start (ISO 8601).

todate-timeRequired

Range end (ISO 8601).

intervalenumRequired

Interval; see the allowed values.

Show allowed values

"hour""day""week""month"

timezonestringRequired

Time zone.

maxLength: 100

rowsarrayRequired

Data rows.

maxItems: 100

Show child fields
bucketdate-timeRequired

Aggregation bucket.

groupstringRequired

Group.

maxLength: 240

isOtherbooleanRequired

Whether this row aggregates the remaining items.

internal_feature_iduuidRequired

Feature ID.

eventCountstringRequired

Number of accepted usage events in this row (consumptions and confirmed reservations, including zero-quantity ones), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

unitsstringRequired

Units as a decimal string.

pattern: ^(0|[1-9]\d{0,29})(\.\d{1,18})?$

tokenEventCountstringRequired

Number of events in this row with a valid ai_tokens report, as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

tokensobjectRequired

AI token totals by pool, summed over the events in this row with valid token reports; each value is an integer string.

Show child fields
inputstringRequired

Total of the input pool (input tokens not counted in another pool), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

outputstringRequired

Total of the output pool (output tokens not counted in another pool), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

cache_readstringRequired

Total tokens read from the prompt cache (cache_read pool), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

cache_writestringRequired

Total tokens written to the prompt cache (cache_write pool), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

reasoningstringRequired

Total reasoning tokens (reasoning pool), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

input_audiostringRequired

Total audio input tokens (input_audio pool), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

output_audiostringRequired

Total audio output tokens (output_audio pool), as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

totalTokensstringRequired

Sum of all seven token pools in this row, as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

providerCostEventCountstringRequired

Number of events in this row with a valid ai_provider_cost_usd report, as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

providerCostUsdstringRequired

Total AI provider cost in USD reported by events in this row, as a decimal string; events without a valid report add nothing.

pattern: ^(0|[1-9]\d{0,29})(\.\d{1,18})?$

invalidTelemetryEventCountstringRequired

Number of events in this row whose ai_tokens or ai_provider_cost_usd report is malformed and therefore excluded from the totals, as an integer string.

pattern: ^(0|[1-9]\d{0,29})$

nextCursorobject | nullRequired

Next-page cursor; null means end. Pass unchanged and clear when filters change.

Show child fields
bucketdate-timeRequired

Aggregation bucket.

groupstringRequired

Group.

maxLength: 240

isOtherbooleanRequired

Whether this row aggregates the remaining items.

internal_feature_iduuidRequired

Feature ID.

Errors#

Failures return an error object; handle them by error.code and error.recovery. The table lists the errors that follow from this operation's credential, scope and idempotency fields; depending on the request it can also return NOT_FOUND (a referenced resource doesn't exist), NOT_CONFIGURED (a required integration isn't connected) or PAYLOAD_TOO_LARGE. Some refusals, such as insufficient balance, are not errors but a reason in a successful response.

Possible errors
codeHTTPWhenrecovery
INVALID_REQUEST400The request doesn't match this page's parameters. A missing or malformed protocol header returns UNSUPPORTED_PROTOCOL_VERSION or INVALID_PROTOCOL_VERSION instead.fix_request
UNAUTHENTICATED401The credential is missing, invalid, expired or revoked.authenticate
FORBIDDEN403The credential lacks credits:read.check_permissions
SCOPE_MISMATCH403X-Indiana-Project or X-Indiana-Environment doesn't match the credential's App and environment.check_scope
RATE_LIMITED429Too many requests; wait for Retry-After and retry the same request.retry_same_request
SERVICE_UNAVAILABLE503The service is temporarily unavailable; retry the same request.retry_same_request
INTERNAL_ERROR500The outcome is unknown; retry later.recover_operation

Possible errors

  • INVALID_REQUEST

    HTTP
    400
    When
    The request doesn't match this page's parameters. A missing or malformed protocol header returns UNSUPPORTED_PROTOCOL_VERSION or INVALID_PROTOCOL_VERSION instead.
    recovery
    fix_request
  • UNAUTHENTICATED

    HTTP
    401
    When
    The credential is missing, invalid, expired or revoked.
    recovery
    authenticate
  • FORBIDDEN

    HTTP
    403
    When
    The credential lacks credits:read.
    recovery
    check_permissions
  • SCOPE_MISMATCH

    HTTP
    403
    When
    X-Indiana-Project or X-Indiana-Environment doesn't match the credential's App and environment.
    recovery
    check_scope
  • RATE_LIMITED

    HTTP
    429
    When
    Too many requests; wait for Retry-After and retry the same request.
    recovery
    retry_same_request
  • SERVICE_UNAVAILABLE

    HTTP
    503
    When
    The service is temporarily unavailable; retry the same request.
    recovery
    retry_same_request
  • INTERNAL_ERROR

    HTTP
    500
    When
    The outcome is unknown; retry later.
    recovery
    recover_operation

Related: Error codes and recovery·Request conventions·All operations