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

# Get a project's usage

> Every charge to the project over the range: totals, daily buckets, and sums by agent, by API key and by
operation. Agents the caller cannot open in this project are summed into one `agent_restricted` row. A charge made without a key
is grouped by how it was made: by a person signed in, by an app key, or before credentials were recorded.



## OpenAPI

````yaml /openapi.yaml get /v2/projects/{project_id}/usage
openapi: 3.1.0
info:
  title: Priors API
  description: >
    Priors gives you memory agents. An agent learns from the observations you
    send it and answers from what it learned.


    Authenticate with an API key, which belongs to one project:


    - A service account's key, for a product you build. It acts as the project's
    service account and keeps working when people leave. Add `X-SP-End-User` to
    act for one person on your side.

    - A personal key, for building and testing from your own code. It acts as
    you, with your role in the project.


    Another organization, or another project, gets 404 for your identifiers.
  contact:
    name: SapientPriors
    url: https://www.sapientpriors.com/
    email: hello@sapientpriors.io
  version: '2.0'
servers:
  - url: https://app.sapientpriors.com/api
    description: Production
security: []
tags:
  - name: Agents
    description: Create, read, update, and delete memory agents.
  - name: Threads
    description: 'Conversations under an agent: create them, teach them, and ask them.'
  - name: Projects
    description: Your projects, and the calls made with their keys.
paths:
  /v2/projects/{project_id}/usage:
    get:
      tags:
        - Projects
      summary: Get a project's usage
      description: >-
        Every charge to the project over the range: totals, daily buckets, and
        sums by agent, by API key and by

        operation. Agents the caller cannot open in this project are summed into
        one `agent_restricted` row. A charge made without a key

        is grouped by how it was made: by a person signed in, by an app key, or
        before credentials were recorded.
      operationId: get_project_usage
      parameters:
        - name: project_id
          in: path
          required: true
          schema:
            type: string
            pattern: ^proj_[0-9A-HJKMNP-TV-Z]{26}$
            description: The project's identifier.
            title: Project Id
          description: The project's identifier.
        - name: from
          in: query
          required: true
          schema:
            type: string
            format: date
            description: First day of the range, inclusive, in `tz`.
            title: From
          description: First day of the range, inclusive, in `tz`.
        - name: to
          in: query
          required: true
          schema:
            type: string
            format: date
            description: >-
              Last day of the range, inclusive, in `tz`. The range is at most
              366 days, counting both ends.
            title: To
          description: >-
            Last day of the range, inclusive, in `tz`. The range is at most 366
            days, counting both ends.
        - name: tz
          in: query
          required: true
          schema:
            type: string
            minLength: 1
            maxLength: 64
            pattern: ^[A-Za-z0-9_+\-/]+$
            description: IANA time zone the days are bucketed in.
            examples:
              - Asia/Kolkata
            title: Tz
          description: IANA time zone the days are bucketed in.
        - name: agent_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 200
                minLength: 1
              - type: 'null'
            description: >-
              Only this agent's charges. A non-admin naming an agent they cannot
              reach gets 404.
            title: Agent Id
          description: >-
            Only this agent's charges. A non-admin naming an agent they cannot
            reach gets 404.
        - name: route
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                enum:
                  - observe
                  - observe-and-recall
                  - recall
                  - observe-and-respond
                  - respond
              - type: 'null'
            description: Only charges made through this operation.
            title: Route
          description: Only charges made through this operation.
        - name: api_key_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 200
                minLength: 1
              - type: 'null'
            description: Only the charges made with this API key.
            title: Api Key Id
          description: Only the charges made with this API key.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProjectUsageReport'
          headers:
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
      security:
        - projectKey: []
components:
  schemas:
    ProjectUsageReport:
      properties:
        enabled:
          type: boolean
          title: Enabled
          description: >-
            False when this deployment records no credits; every value is then
            zero.
        filters:
          $ref: '#/components/schemas/ProjectUsageFilters'
          description: The filters the report applied.
        totals:
          $ref: '#/components/schemas/UsageSums'
        daily:
          items:
            $ref: '#/components/schemas/UsageDay'
          type: array
          title: Daily
          description: One bucket per day of the range, zero-filled.
        by_agent:
          items:
            $ref: '#/components/schemas/UsageByAgent'
          type: array
          title: By Agent
          description: >-
            Highest credits first. A null `agent_id` groups charges with no
            recorded agent or, when `agent_restricted` is true, every agent the
            caller cannot reach.
        project_id:
          type: string
          title: Project Id
          description: The project the report covers.
        by_api_key:
          items:
            $ref: '#/components/schemas/UsageByApiKey'
          type: array
          title: By Api Key
          description: Highest credits first.
        by_operation:
          items:
            $ref: '#/components/schemas/UsageByOperation'
          type: array
          title: By Operation
          description: Highest credits first.
      type: object
      required:
        - enabled
        - filters
        - totals
        - daily
        - by_agent
        - project_id
        - by_api_key
        - by_operation
      title: ProjectUsageReport
      description: >-
        A project's usage over a range: totals, by day, by agent, by API key and
        by operation.
    ProjectUsageFilters:
      properties:
        from:
          type: string
          format: date
          title: From
          description: The first day of the range.
        to:
          type: string
          format: date
          title: To
          description: The last day of the range.
        tz:
          type: string
          title: Tz
          description: The time zone the days are bucketed in.
        agent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Id
          description: The agent filter that was applied; null for none.
        route:
          anyOf:
            - type: string
              enum:
                - observe
                - observe-and-recall
                - recall
                - observe-and-respond
                - respond
            - type: 'null'
          title: Route
          description: The operation filter that was applied; null for none.
        api_key_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Api Key Id
          description: The API key filter that was applied; null for none.
      type: object
      required:
        - from
        - to
        - tz
        - agent_id
        - route
        - api_key_id
      title: ProjectUsageFilters
      description: The filters a project usage read applied.
    UsageSums:
      properties:
        requests:
          type: integer
          minimum: 0
          title: Requests
          description: How many requests were charged.
        message_requests:
          type: integer
          minimum: 0
          title: Message Requests
          description: >-
            Requests on routes that answer a message (every route but
            `observe`).
        credits:
          type: string
          pattern: ^-?\d+(\.\d+)?$
          title: Credits
          description: Credits charged, net of refunds.
        refunded_credits:
          type: string
          pattern: ^-?\d+(\.\d+)?$
          title: Refunded Credits
          description: Credits refunded against the charges counted here.
        ingested_tokens:
          type: integer
          minimum: 0
          title: Ingested Tokens
          description: Input tokens of `observe` calls (messages and files).
        input_tokens:
          type: integer
          minimum: 0
          title: Input Tokens
          description: Input tokens of message routes.
        output_tokens:
          type: integer
          minimum: 0
          title: Output Tokens
          description: Output tokens billed.
        total_tokens:
          type: integer
          minimum: 0
          title: Total Tokens
          description: ingested_tokens + input_tokens + output_tokens.
        message_tokens:
          type: integer
          minimum: 0
          title: Message Tokens
          description: input_tokens + output_tokens
        tokens_estimated:
          type: boolean
          title: Tokens Estimated
          description: True when some tokens are estimated from words.
      type: object
      required:
        - requests
        - message_requests
        - credits
        - refunded_credits
        - ingested_tokens
        - input_tokens
        - output_tokens
        - total_tokens
        - message_tokens
        - tokens_estimated
      title: UsageSums
      description: Usage totals.
    UsageDay:
      properties:
        date:
          type: string
          format: date
          title: Date
          description: The day, in the report's time zone.
        requests:
          type: integer
          minimum: 0
          title: Requests
          description: How many requests were charged.
        credits:
          type: string
          pattern: ^-?\d+(\.\d+)?$
          title: Credits
          description: Credits charged on this day.
        ingested_tokens:
          type: integer
          minimum: 0
          title: Ingested Tokens
          description: Input tokens of `observe` calls (messages and files).
        input_tokens:
          type: integer
          minimum: 0
          title: Input Tokens
          description: Input tokens of message routes.
        output_tokens:
          type: integer
          minimum: 0
          title: Output Tokens
          description: Output tokens billed.
      type: object
      required:
        - date
        - requests
        - credits
        - ingested_tokens
        - input_tokens
        - output_tokens
      title: UsageDay
      description: Usage on one day.
    UsageByAgent:
      properties:
        requests:
          type: integer
          minimum: 0
          title: Requests
          description: How many requests were charged.
        message_requests:
          type: integer
          minimum: 0
          title: Message Requests
          description: >-
            Requests on routes that answer a message (every route but
            `observe`).
        credits:
          type: string
          pattern: ^-?\d+(\.\d+)?$
          title: Credits
          description: Credits charged, net of refunds.
        refunded_credits:
          type: string
          pattern: ^-?\d+(\.\d+)?$
          title: Refunded Credits
          description: Credits refunded against the charges counted here.
        ingested_tokens:
          type: integer
          minimum: 0
          title: Ingested Tokens
          description: Input tokens of `observe` calls (messages and files).
        input_tokens:
          type: integer
          minimum: 0
          title: Input Tokens
          description: Input tokens of message routes.
        output_tokens:
          type: integer
          minimum: 0
          title: Output Tokens
          description: Output tokens billed.
        total_tokens:
          type: integer
          minimum: 0
          title: Total Tokens
          description: ingested_tokens + input_tokens + output_tokens.
        message_tokens:
          type: integer
          minimum: 0
          title: Message Tokens
          description: input_tokens + output_tokens
        tokens_estimated:
          type: boolean
          title: Tokens Estimated
          description: True when some tokens are estimated from words.
        agent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Id
          description: The agent; null for the grouped rows described on `by_agent`.
        agent_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Name
          description: The agent's name; null when `agent_id` is null.
        agent_restricted:
          type: boolean
          title: Agent Restricted
          description: True for the one row that sums the agents the caller cannot reach.
          default: false
      type: object
      required:
        - requests
        - message_requests
        - credits
        - refunded_credits
        - ingested_tokens
        - input_tokens
        - output_tokens
        - total_tokens
        - message_tokens
        - tokens_estimated
        - agent_id
        - agent_name
        - agent_restricted
      title: UsageByAgent
      description: Usage summed for one agent.
    UsageByApiKey:
      properties:
        api_key:
          anyOf:
            - $ref: '#/components/schemas/ApiKeyRef'
            - type: 'null'
          description: The key; null for charges made without one.
        credential:
          anyOf:
            - type: string
              enum:
                - session
                - personal_key
                - service_account_key
                - app_key
            - type: 'null'
          enum:
            - session
            - app_key
            - null
          title: Credential
          description: >-
            Null with a key. Without one: `session` for a person signed in (the
            console, voice and the website playground), `app_key` for an
            organization's app key, and null for charges recorded before
            credentials were.
        requests:
          type: integer
          minimum: 0
          title: Requests
          description: How many requests were charged.
        credits:
          type: string
          pattern: ^-?\d+(\.\d+)?$
          title: Credits
          description: Credits charged, net of refunds.
      type: object
      required:
        - api_key
        - credential
        - requests
        - credits
      title: UsageByApiKey
      description: Usage summed for one API key, or for the charges made without one.
    UsageByOperation:
      properties:
        operation:
          anyOf:
            - type: string
              enum:
                - observe
                - observe-and-recall
                - recall
                - observe-and-respond
                - respond
            - type: string
              const: other
          title: Operation
          description: >-
            The operation; `other` sums the charges no operation listed here
            claims.
        kind:
          anyOf:
            - type: string
              enum:
                - learning
                - recall
                - answering
            - type: 'null'
          title: Kind
          description: >-
            `learning`, `recall` or `answering`: what the operation does. Null
            for `other`.
        requests:
          type: integer
          minimum: 0
          title: Requests
          description: How many requests were charged.
        credits:
          type: string
          pattern: ^-?\d+(\.\d+)?$
          title: Credits
          description: Credits charged, net of refunds.
      type: object
      required:
        - operation
        - kind
        - requests
        - credits
      title: UsageByOperation
      description: Usage summed for one operation.
    ErrorResponse:
      properties:
        error:
          type: string
          title: Error
          description: A sentence describing what went wrong, for a person to read.
        code:
          type: string
          title: Code
          description: >
            Machine-readable condition. Branch on this, not on the status. Treat
            an unknown value as the status code's default meaning.


            Known values: invalid_request, images_not_accepted, unauthorized,
            forbidden, payment_required, insufficient_credits, not_found,
            agent_not_found, project_not_found, thread_not_found, conflict,
            agent_quota_exceeded, upload_in_progress,
            duplicate_upload_in_progress, document_already_ingested,
            document_uploaded_elsewhere, agent_not_ready, session_changed,
            trial_ended, trial_full_today, payload_too_large,
            unsupported_media_type, rate_limit_exceeded, service_unavailable,
            service_not_configured, answer_model_unavailable, empty_answer,
            upstream_timeout, internal_error, and the upload codes
            (unsupported_document, document_needs_ocr, encrypted_document,
            malformed_document, empty_document, document_too_large,
            document_too_complex, document_too_many_turns,
            document_too_many_pages, document_too_large_for_ocr,
            document_pages_unexpected, document_service_unavailable, ocr_failed,
            ingestion_failed, secret_file, document_contains_secret).


            Codes that need their own handling:


            - `service_unavailable` (503): a dependency is down. Retry.

            - `answer_model_unavailable` (503): the model that writes the reply
            could not be reached, so the turn has no answer. Retry shortly.

            - `empty_answer` (503): the model returned an empty reply. Retry.

            - `upstream_timeout` (504): an answer or recall ran too long and was
            stopped. Nothing was charged. Retry.

            - `service_not_configured` (503): the deployment is missing
            configuration. Retrying never clears it.

            - `internal_error` (500): a defect. The same request fails the same
            way again.

            - `agent_not_found`, `project_not_found`, `thread_not_found`:
            narrower `not_found` codes that say which resource is gone.
        request_id:
          type: string
          title: Request Id
          description: >
            Server-issued identifier for this request. Include it when reporting
            a problem.
        details:
          type: string
          title: Details
          description: >
            Condition-specific detail. On a 429 (`rate_limit_exceeded`) it names
            the limit that refused. For every scope: wait for `Retry-After`,
            then retry. Do not resend a non-idempotent request automatically.


            - `user`: your own credential's rate (before sign-in, your client
            address). Slowing this caller clears it.

            - `organization`: the organization's shared rate. Your
            organization's other credentials are refused too.

            - `capacity`: a service-wide limit, unrelated to your rate.

            - `ingestion-organization`: your organization is processing as many
            documents as it may at once. The document was not started. The same
            file is accepted once one finishes.

            - `ingestion-capacity`: as `ingestion-organization`, service-wide.

            - `agent-occupancy`: this discoverable agent has as many users as
            its owner allows, and you are not one of them. `Retry-After` is when
            the earliest slot frees.


            Waits range from seconds (rate limits) to about ninety seconds
            (document limits), so read `Retry-After`. Treat an unknown scope the
            same way: wait, then retry. On other statuses this field is absent
            or free text; do not parse it.
      type: object
      required:
        - error
        - code
        - request_id
      title: ErrorResponse
      description: The body of an error response.
    ApiKeyRef:
      properties:
        key_id:
          type: string
          title: Key Id
          description: The key's id, the part between its prefix and its secret.
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: The key's name; null when it is not known.
        owner:
          anyOf:
            - $ref: '#/components/schemas/PrincipalRef'
            - type: 'null'
          description: Who the key acts as; null when it is not known.
      type: object
      required:
        - key_id
        - name
        - owner
      title: ApiKeyRef
      description: An API key.
    PrincipalRef:
      properties:
        type:
          type: string
          enum:
            - user
            - service_account
            - system
          title: Type
          description: '`user` for a person, `service_account`, or `system`.'
        id:
          type: string
          title: Id
          description: 'Their id: a user id, a service account id, or `system`.'
        display_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Display Name
          description: Their name; null when it is not known.
      type: object
      required:
        - type
        - id
        - display_name
      title: PrincipalRef
      description: >-
        Who something is: a person, a service account, or the system for what
        nobody asked for.
  headers:
    X-Request-Id:
      description: >
        Server-issued identifier for this request, the same value as an error
        body's `request_id`. Include it when reporting a problem.
      schema:
        type: string
    RetryAfterWhenKnown:
      description: >
        Seconds to wait before retrying, when the wait is known (an agent being
        handed over during a restart). Absent for an outage with no known end.
      schema:
        type: integer
        minimum: 1
  responses:
    BadRequest:
      description: >
        The request is invalid, and resending it unchanged will not help. The
        body's `code` is `invalid_request`, and `error` says which of these it
        was:


        - A field is missing, out of range, or in a combination the route
        refuses.

        - `X-SP-End-User` is sent with a key other than a service account's, is
        empty, or is longer than 255 characters.

        - An API key is sent with a `Sec-Fetch-Site` header, which only a
        browser sets.

        - A service account's key creates an agent with `visibility: private`.


        One exception: `images_not_accepted` means the message carried images
        and this deployment's answer model does not take them. Send the message
        without its images. Only the routes that answer a message and the image
        upload return it.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/X-Request-Id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid credentials
      headers:
        X-Request-Id:
          $ref: '#/components/headers/X-Request-Id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: >
        The server failed unexpectedly. The body's `code` is `internal_error`,
        and its message does not name the cause. Quote the body's `request_id`
        (the same value as the `X-Request-Id` header) when reporting the
        problem. The same request sent again is not expected to succeed.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/X-Request-Id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ServiceUnavailable:
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfterWhenKnown'
        X-Request-Id:
          $ref: '#/components/headers/X-Request-Id'
      description: >
        A dependency could not complete the request. Check the body's `code`
        before retrying:


        - `service_unavailable`: a later attempt may succeed. While a restart
        hands an agent to a new instance, the response carries `Retry-After`,
        and an upload in progress resumes where it stopped, so keep polling.

        - `service_not_configured`: the deployment lacks configuration this
        route needs. Every attempt fails the same way until it is fixed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    projectKey:
      type: http
      scheme: bearer
      description: >
        An API key, shaped `spk_<key_id>_<secret><checksum>`, sent as
        `Authorization: Bearer spk_...`. Each key belongs to one project and
        reaches only that project: an id from another project answers 404.


        - A service account's key runs your product. It acts as the service
        account, with the role the service account holds in the project, and
        keeps working when people leave. It reaches the project's public agents,
        never a private one. Only this key may send `X-SP-End-User`.

        - A personal key acts as the person who created it, with their role in
        the project. It is for building and testing: every response carries
        `X-SP-Warning: personal API key, not for production`, and
        `X-SP-End-User` is refused with 400.


        Keys are created and revoked on the API keys page of the Priors
        application. No API endpoint creates or revokes a service account's key.
        A personal key lasts 30, 90, or 365 days (90 by default), and a person
        can hold 10 live personal keys in an organization. A service account's
        key lasts 90 or 365 days (365 by default), and a service account can
        hold 5 live keys. The secret is shown once, at creation, and cannot be
        recovered.


        A personal key made before projects (`spu_...`) keeps working until it
        expires, in its organization's Default project.


        Keep keys on your server: a request with a `Sec-Fetch-Site` header is
        refused with 400, and Priors sends no CORS headers.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.