> ## Documentation Index
> Fetch the complete documentation index at: https://developers.meshapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Spend Trend

> Return historical spend bucketed by the chosen granularity, plus a trailing
3-bucket moving average and the window's total spend.



## OpenAPI

````yaml /api/openapi.json get /v1/usage/spend-trend
openapi: 3.1.0
info:
  title: MeshAPI
  description: One key, all AI models.
  version: 0.1.0
servers:
  - url: https://api.meshapi.ai
security:
  - BearerAuth: []
paths:
  /v1/usage/spend-trend:
    get:
      tags:
        - Usage
      summary: Get Spend Trend
      description: >-
        Return historical spend bucketed by the chosen granularity, plus a
        trailing

        3-bucket moving average and the window's total spend.
      operationId: get_spend_trend
      parameters:
        - name: org_id
          in: query
          required: true
          schema:
            type: string
            description: Organisation UUID
            title: Org Id
          description: Organisation UUID
        - name: team_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: Team UUID (optional filter)
            title: Team Id
          description: Team UUID (optional filter)
        - name: granularity
          in: query
          required: false
          schema:
            enum:
              - hourly
              - weekly
              - monthly
            type: string
            description: >-
              Bucketing window: 'hourly' (last 24h, hourly), 'weekly' (last 12
              weeks, weekly), 'monthly' (last 30 days, daily).
            default: monthly
            title: Granularity
          description: >-
            Bucketing window: 'hourly' (last 24h, hourly), 'weekly' (last 12
            weeks, weekly), 'monthly' (last 30 days, daily).
        - name: force_refresh
          in: query
          required: false
          schema:
            type: boolean
            description: Skip the cache and recompute from the database.
            default: false
            title: Force Refresh
          description: Skip the cache and recompute from the database.
        - in: header
          name: X-Mesh-Version
          required: false
          schema:
            type: string
            enum:
              - 2026-08
            default: 2026-08
          example: 2026-08
          description: >-
            Dated version of the API contract to pin this request to. Omit it
            and the request is served under `2026-08` — the oldest supported
            version, so an existing integration is never moved by a release. A
            malformed or unsupported value is rejected with `400
            invalid_api_version` rather than falling back silently. The version
            actually served is echoed as `X-Mesh-Version` on every response,
            including errors.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SpendTrendResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    SpendTrendResponse:
      properties:
        as_of:
          type: string
          title: As Of
        granularity:
          type: string
          enum:
            - hourly
            - weekly
            - monthly
          title: Granularity
        period_start:
          type: string
          title: Period Start
        period_end:
          type: string
          title: Period End
        summary:
          $ref: '#/components/schemas/SpendTrendSummary'
        buckets:
          items:
            $ref: '#/components/schemas/SpendBucketPoint'
          type: array
          title: Buckets
        moving_average:
          items:
            $ref: '#/components/schemas/MovingAveragePoint'
          type: array
          title: Moving Average
      type: object
      required:
        - as_of
        - granularity
        - period_start
        - period_end
        - summary
        - buckets
        - moving_average
      title: SpendTrendResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SpendTrendSummary:
      properties:
        total_spend_usd:
          type: string
          title: Total Spend Usd
        latest_ma_usd:
          type: string
          title: Latest Ma Usd
      type: object
      required:
        - total_spend_usd
        - latest_ma_usd
      title: SpendTrendSummary
    SpendBucketPoint:
      properties:
        bucket_index:
          type: integer
          title: Bucket Index
        bucket_start:
          type: string
          title: Bucket Start
        label:
          type: string
          title: Label
        cost_usd:
          type: string
          title: Cost Usd
      type: object
      required:
        - bucket_index
        - bucket_start
        - label
        - cost_usd
      title: SpendBucketPoint
    MovingAveragePoint:
      properties:
        bucket_index:
          type: integer
          title: Bucket Index
        bucket_start:
          type: string
          title: Bucket Start
        label:
          type: string
          title: Label
        ma_usd:
          type: string
          title: Ma Usd
      type: object
      required:
        - bucket_index
        - bucket_start
        - label
        - ma_usd
      title: MovingAveragePoint
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Enter your MeshAPI key (`rsk_...`) — sent as `Authorization: Bearer
        <key>`.

````