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

# explain charge

> Explain one invoice line using ledger metadata and rated meter facts.



## OpenAPI

````yaml /openapi.json post /v1/analytics/charges/explain
openapi: 3.0.3
info:
  title: Unprice API
  version: 1.0.0
servers:
  - url: https://api.unprice.dev
    description: Production
  - url: http://localhost:8787
    description: Development
  - url: https://preview-api.unprice.dev
    description: Preview
security:
  - bearerAuth: []
paths:
  /v1/analytics/charges/explain:
    post:
      tags:
        - analytics
      summary: explain charge
      description: Explain one invoice line using ledger metadata and rated meter facts.
      operationId: analytics.charges.explain
      requestBody:
        description: Explain charge request
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                project_id:
                  type: string
                invoice_id:
                  type: string
                entry_id:
                  type: string
                limit:
                  type: integer
                  minimum: 1
                  maximum: 500
                  default: 100
                offset:
                  type: integer
                  minimum: 0
                  default: 0
              required:
                - invoice_id
                - entry_id
      responses:
        '200':
          description: Explain charge response
          content:
            application/json:
              schema:
                type: object
                properties:
                  invoice:
                    type: object
                    properties:
                      id:
                        type: string
                      statement_key:
                        type: string
                      customer_id:
                        type: string
                      currency:
                        type: string
                    required:
                      - id
                      - statement_key
                      - customer_id
                      - currency
                  line:
                    type: object
                    properties:
                      entry_id:
                        type: string
                      billing_period_id:
                        type: string
                      kind:
                        type: string
                      amount:
                        type: integer
                      currency:
                        type: string
                    required:
                      - entry_id
                      - billing_period_id
                      - kind
                      - amount
                      - currency
                  scope:
                    type: object
                    properties:
                      project_id:
                        type: string
                      customer_id:
                        type: string
                      feature_slug:
                        type: string
                      period_key:
                        type: string
                      customer_entitlement_id:
                        type: string
                        nullable: true
                      feature_plan_version_id:
                        type: string
                        nullable: true
                    required:
                      - project_id
                      - customer_id
                      - feature_slug
                      - period_key
                      - customer_entitlement_id
                      - feature_plan_version_id
                  summary:
                    type: object
                    properties:
                      event_count:
                        type: integer
                      total_usage:
                        type: number
                      total_amount:
                        type: integer
                      latest_amount_after:
                        type: integer
                      currency:
                        type: string
                      amount_scale:
                        type: integer
                      first_event_at:
                        type: integer
                        nullable: true
                      last_event_at:
                        type: integer
                        nullable: true
                      multi_component_event_count:
                        type: integer
                    required:
                      - event_count
                      - total_usage
                      - total_amount
                      - latest_amount_after
                      - currency
                      - amount_scale
                      - first_event_at
                      - last_event_at
                      - multi_component_event_count
                  pricing:
                    type: object
                    properties:
                      feature_type:
                        type: string
                      usage_mode:
                        type: string
                        nullable: true
                      tier_mode:
                        type: string
                        nullable: true
                      unit_of_measure:
                        type: string
                      description:
                        type: string
                      rows:
                        type: array
                        items:
                          type: object
                          properties:
                            label:
                              type: string
                            value:
                              type: string
                          required:
                            - label
                            - value
                    required:
                      - feature_type
                      - usage_mode
                      - tier_mode
                      - unit_of_measure
                      - description
                      - rows
                  events:
                    type: array
                    items:
                      type: object
                      properties:
                        event_id:
                          type: string
                        idempotency_key:
                          type: string
                        customer_entitlement_id:
                          type: string
                        grant_id:
                          type: string
                        feature_plan_version_id:
                          type: string
                          nullable: true
                        feature_slug:
                          type: string
                        period_key:
                          type: string
                        event_slug:
                          type: string
                        aggregation_method:
                          type: string
                        timestamp:
                          type: number
                          description: timestamp of the ingested event
                        created_at:
                          type: number
                          description: timestamp of when the fact row was created
                        delta:
                          type: number
                        value_after:
                          type: number
                        amount:
                          type: integer
                        amount_after:
                          type: integer
                        amount_scale:
                          type: number
                          enum:
                            - 8
                        currency:
                          type: string
                          minLength: 3
                          maxLength: 3
                        priced_at:
                          type: integer
                        tier_index:
                          type: integer
                          nullable: true
                        tier_mode:
                          anyOf:
                            - type: string
                              enum:
                                - volume
                                - graduated
                            - nullable: true
                            - nullable: true
                        pricing_component_count:
                          type: integer
                          minimum: 0
                        source_type:
                          type: string
                          enum:
                            - api_key
                            - system
                            - unknown
                        source_id:
                          type: string
                      required:
                        - event_id
                        - idempotency_key
                        - customer_entitlement_id
                        - grant_id
                        - feature_plan_version_id
                        - feature_slug
                        - period_key
                        - event_slug
                        - aggregation_method
                        - timestamp
                        - created_at
                        - delta
                        - value_after
                        - amount
                        - amount_after
                        - amount_scale
                        - currency
                        - priced_at
                        - tier_index
                        - tier_mode
                        - pricing_component_count
                        - source_type
                        - source_id
                  answer:
                    type: string
                  confidence:
                    type: string
                    enum:
                      - high
                      - medium
                      - low
                  freshness:
                    type: object
                    properties:
                      generatedAt:
                        type: integer
                      dataFrom:
                        type: integer
                        nullable: true
                      dataTo:
                        type: integer
                        nullable: true
                    required:
                      - generatedAt
                      - dataFrom
                      - dataTo
                  evidence:
                    type: array
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                          enum:
                            - event
                            - meter_fact
                            - ingestion_status
                            - ledger_line
                            - billing_period
                            - invoice
                            - plan_version
                        id:
                          type: string
                        source:
                          type: string
                          enum:
                            - tinybird
                            - r2
                            - ledger
                            - postgres
                        timestamp:
                          type: integer
                          nullable: true
                      required:
                        - type
                        - id
                        - source
                        - timestamp
                  warnings:
                    type: array
                    items:
                      type: string
                  nextActions:
                    type: array
                    items:
                      type: string
                  pagination:
                    type: object
                    properties:
                      limit:
                        type: integer
                      offset:
                        type: integer
                      has_more:
                        type: boolean
                    required:
                      - limit
                      - offset
                      - has_more
                required:
                  - invoice
                  - line
                  - scope
                  - summary
                  - pricing
                  - events
                  - answer
                  - confidence
                  - freshness
                  - evidence
                  - warnings
                  - nextActions
                  - pagination
        '400':
          description: >-
            The server cannot or will not process the request due to something
            that is perceived to be a client error (e.g., malformed request
            syntax, invalid request message framing, or deceptive request
            routing).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrBadRequest'
        '401':
          description: >-
            Although the HTTP standard specifies "unauthorized", semantically
            this response means "unauthenticated". That is, the client must
            authenticate itself to get the requested response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrUnauthorized'
        '403':
          description: >-
            The client does not have access rights to the content; that is, it
            is unauthorized, so the server is refusing to give the requested
            resource. Unlike 401 Unauthorized, the client's identity is known to
            the server.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrForbidden'
        '404':
          description: >-
            The server cannot find the requested resource. In the browser, this
            means the URL is not recognized. In an API, this can also mean that
            the endpoint is valid but the resource itself does not exist.
            Servers may also send this response instead of 403 Forbidden to hide
            the existence of a resource from an unauthorized client. This
            response code is probably the most well known due to its frequent
            occurrence on the web.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrNotFound'
        '409':
          description: >-
            This response is sent when a request conflicts with the current
            state of the server.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrConflict'
        '412':
          description: >-
            The requested operation cannot be completed because certain
            conditions were not met. This typically occurs when a required
            resource state or version check fails.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrPreconditionFailed'
        '429':
          description: >-
            The user has sent too many requests in a given amount of time ("rate
            limiting")
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrTooManyRequests'
        '500':
          description: >-
            The server has encountered a situation it does not know how to
            handle.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrInternalServerError'
components:
  schemas:
    ErrBadRequest:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - BAD_REQUEST
              description: A machine readable error code.
              example: BAD_REQUEST
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: https://docs.unprice.dev/api-reference/errors/code/BAD_REQUEST
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
    ErrUnauthorized:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - UNAUTHORIZED
              description: A machine readable error code.
              example: UNAUTHORIZED
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: https://docs.unprice.dev/api-reference/errors/code/UNAUTHORIZED
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
    ErrForbidden:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - FORBIDDEN
              description: A machine readable error code.
              example: FORBIDDEN
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: https://docs.unprice.dev/api-reference/errors/code/FORBIDDEN
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
    ErrNotFound:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - NOT_FOUND
              description: A machine readable error code.
              example: NOT_FOUND
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: https://docs.unprice.dev/api-reference/errors/code/NOT_FOUND
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
    ErrConflict:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - CONFLICT
              description: A machine readable error code.
              example: CONFLICT
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: https://docs.unprice.dev/api-reference/errors/code/CONFLICT
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
    ErrPreconditionFailed:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - PRECONDITION_FAILED
              description: A machine readable error code.
              example: PRECONDITION_FAILED
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: >-
                https://docs.unprice.dev/api-reference/errors/code/PRECONDITION_FAILED
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
    ErrTooManyRequests:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - TOO_MANY_REQUESTS
              description: A machine readable error code.
              example: TOO_MANY_REQUESTS
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: >-
                https://docs.unprice.dev/api-reference/errors/code/TOO_MANY_REQUESTS
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
    ErrInternalServerError:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - INTERNAL_SERVER_ERROR
              description: A machine readable error code.
              example: INTERNAL_SERVER_ERROR
            docs:
              type: string
              description: >-
                A link to our documentation with more details about this error
                code
              example: >-
                https://docs.unprice.dev/api-reference/errors/code/INTERNAL_SERVER_ERROR
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - docs
            - message
            - requestId
      required:
        - error
  securitySchemes:
    bearerAuth:
      bearerFormat: root key
      type: http
      scheme: bearer
      x-speakeasy-example: UNPRICE_API_KEY

````