Skip to content
Sign in Create account

Usage analytics (full)

GET /api/billing/usage

Returns the authenticated account's usage records, pagination metadata, and totals computed over the same optional filters. Requires billing.read; per_page defaults to 50 and is capped at 100. to must not precede from, and the date range cannot exceed 366 days. This list uses offset pagination ordered by created_at DESC, then id DESC. Keep the same filters and per_page value for every page. If rows are added or deleted while paging, rows can repeat or be skipped. Restart at page 1 after the list has stopped changing for a fresh traversal; this endpoint does not provide a point-in-time snapshot.

Authenticate with a portal session token.

Parameters

  • from string (date) query
  • to string (date) query

    Must be on or after from.

  • provider string query
    Length: at most 64 characters. Pattern: ^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$
  • per_page integer query
    Default: 50. Range: 1 to 100

Responses

200 Paginated usage records and totals over the same optional filters.

application/json object

  • pagination object required
    • current_page integer required
    • last_page integer required
    • per_page integer required
      Range: 1 to 100
    • total integer required
  • records array of object required

    Each item:

    • provider_cost_micros integer required

      Exact provider cost in USD micro-dollars; legacy cents-only rows are returned as the corresponding cents × 10,000.

    • markup_micros integer required

      Exact markup in USD micro-dollars; legacy cents-only rows are returned as the corresponding cents × 10,000.

    • total_cost_micros integer required

      Exact billed cost in USD micro-dollars; legacy cents-only rows are returned as the corresponding cents × 10,000.

    • has_receipt boolean required

      Whether a signed receipt is linked to this usage record.

    • cache_usage any

      Per-type cache provider-cost detail, already included in provider_cost_micros and not added again to the billed total.

      Any of

    • receipt_mode string or null

      Optional mode from the linked receipt; absent when no receipt is linked.

    • receipt_tier string or null

      Optional privacy tier from the linked receipt; absent when no receipt is linked.

  • totals object required
    • input_tokens integer required
    • markup_cents integer required
    • output_tokens integer required
    • provider_cost_cents integer required
    • scope_filtered boolean required
    • total_cost_cents integer required
    • total_cost_dollars number required
    • provider_cost_micros integer required
    • markup_micros integer required
    • total_cost_micros integer required
    • cache_usage CacheUsageBreakdown required

Generated sample

{
  "pagination": {
    "current_page": 0,
    "last_page": 0,
    "per_page": 1,
    "total": 0
  },
  "records": [
    {
      "provider_cost_micros": 0,
      "markup_micros": 0,
      "total_cost_micros": 0,
      "has_receipt": true,
      "cache_usage": {
        "read": {
          "tokens": 0,
          "rate_cents_per_million": 0,
          "provider_cost_micros": 0,
          "unpriced_tokens": 0
        },
        "write_5m": {
          "tokens": 0,
          "rate_cents_per_million": 0,
          "provider_cost_micros": 0,
          "unpriced_tokens": 0
        },
        "write_1h": {
          "tokens": 0,
          "rate_cents_per_million": 0,
          "provider_cost_micros": 0,
          "unpriced_tokens": 0
        },
        "write_30m": {
          "tokens": 0,
          "rate_cents_per_million": 0,
          "provider_cost_micros": 0,
          "unpriced_tokens": 0
        },
        "write_12h": {
          "tokens": 0,
          "rate_cents_per_million": 0,
          "provider_cost_micros": 0,
          "unpriced_tokens": 0
        },
        "write_total_tokens": 0,
        "per_type_available": true,
        "records_without_audit_detail": 0
      },
      "receipt_mode": "string",
      "receipt_tier": "string"
    }
  ],
  "totals": {
    "input_tokens": 0,
    "markup_cents": 0,
    "output_tokens": 0,
    "provider_cost_cents": 0,
    "scope_filtered": true,
    "total_cost_cents": 0,
    "total_cost_dollars": 0,
    "provider_cost_micros": 0,
    "markup_micros": 0,
    "total_cost_micros": 0,
    "cache_usage": {
      "read": {
        "tokens": 0,
        "rate_cents_per_million": 0,
        "provider_cost_micros": 0,
        "unpriced_tokens": 0
      },
      "write_5m": {
        "tokens": 0,
        "rate_cents_per_million": 0,
        "provider_cost_micros": 0,
        "unpriced_tokens": 0
      },
      "write_1h": {
        "tokens": 0,
        "rate_cents_per_million": 0,
        "provider_cost_micros": 0,
        "unpriced_tokens": 0
      },
      "write_30m": {
        "tokens": 0,
        "rate_cents_per_million": 0,
        "provider_cost_micros": 0,
        "unpriced_tokens": 0
      },
      "write_12h": {
        "tokens": 0,
        "rate_cents_per_million": 0,
        "provider_cost_micros": 0,
        "unpriced_tokens": 0
      },
      "write_total_tokens": 0,
      "per_type_available": true,
      "records_without_audit_detail": 0
    }
  }
}
401 Missing or invalid bearer token.

application/json object

Any keys are accepted.

403 The caller does not meet the route requirements: accepted Terms of Service and Privacy Policy.

application/json object

Any keys are accepted.

422 Invalid filters or a requested date range exceeding 366 days.

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

429 The request was rate limited. API-generated responses are JSON;

Response headers

  • Retry-After string header

    Seconds to wait before retrying, when provided.

  • X-RateLimit-Scope string header

    Identifies the scope of the request limit, when provided.

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

text/html string