> ## 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.

# Learn messages or files

> Learn one message, a list of up to 100 messages (JSON), or documents (multipart) in the background. Returns
202; poll each observation for progress.



## OpenAPI

````yaml /openapi.yaml post /v2/agents/{agent_id}/threads/{thread_id}/observe
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/agents/{agent_id}/threads/{thread_id}/observe:
    post:
      tags:
        - Threads
      summary: Learn messages or files
      description: >-
        Learn one message, a list of up to 100 messages (JSON), or documents
        (multipart) in the background. Returns

        202; poll each observation for progress.
      operationId: observe_v2
      parameters:
        - name: agent_id
          in: path
          required: true
          schema:
            type: string
            pattern: ^agent_[0-9A-HJKMNP-TV-Z]{26}$
            description: The agent's identifier.
            title: Agent Id
          description: The agent's identifier.
        - name: thread_id
          in: path
          required: true
          schema:
            type: string
            pattern: ^thread_[0-9A-HJKMNP-TV-Z]{26}$
            description: The thread's identifier, scoped to the agent.
            title: Thread Id
          description: The thread's identifier, scoped to the agent.
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 255
                minLength: 1
              - type: 'null'
            description: >-
              A key you choose so a retry is safe: a retry with the same key and
              body gets the first response back instead of running again.
              Reusing a key for a different request, or while the first is still
              running, returns 409 `conflict`, with `details`
              `idempotency_key_reused` (use a new key) or
              `idempotency_key_in_flight` (wait, then retry).
            title: Idempotency-Key
          description: >-
            A key you choose so a retry is safe: a retry with the same key and
            body gets the first response back instead of running again. Reusing
            a key for a different request, or while the first is still running,
            returns 409 `conflict`, with `details` `idempotency_key_reused` (use
            a new key) or `idempotency_key_in_flight` (wait, then retry).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              additionalProperties: false
              description: >-
                One message as a string in `content`, or a list of up to 100
                messages. With a list, set `speaker`,

                `speaker_id`, `timestamp` and `metadata` on each message, not
                beside `content`.
              properties:
                speaker_id:
                  anyOf:
                    - type: string
                      maxLength: 200
                      minLength: 1
                    - type: 'null'
                  title: Speaker Id
                  description: >-
                    Your own id for the speaker. Kept on the turn and returned
                    with it.
                timestamp:
                  anyOf:
                    - type: string
                      format: date-time
                    - type: 'null'
                  title: Timestamp
                  description: >-
                    When the message was said, used to date its memories.
                    Defaults to when the server receives it.
                metadata:
                  anyOf:
                    - properties:
                        path:
                          anyOf:
                            - type: string
                              maxLength: 1024
                              minLength: 1
                            - type: 'null'
                          title: Path
                          description: The path of the file or page the turn came from.
                        section:
                          anyOf:
                            - type: string
                              maxLength: 500
                              minLength: 1
                            - type: 'null'
                          title: Section
                          description: The section of that source the turn came from.
                        page:
                          anyOf:
                            - type: integer
                              maximum: 1000000
                              minimum: 1
                            - type: 'null'
                          title: Page
                          description: The page the turn came from, counting from 1.
                        parent_id:
                          anyOf:
                            - type: string
                              maxLength: 200
                              minLength: 1
                            - type: 'null'
                          title: Parent Id
                          description: >-
                            The id of the item the turn belongs to, in your own
                            system.
                      additionalProperties: true
                      type: object
                      title: TurnMetadata
                      description: >-
                        Where a turn came from: four named keys, and any keys of
                        your own. At most 32 keys and 8 KiB as JSON.
                    - type: 'null'
                  description: >-
                    Where the message came from, kept on the turn and returned
                    with it.
                content:
                  anyOf:
                    - maxLength: 2000000
                      minLength: 1
                      type: string
                    - items:
                        additionalProperties: false
                        description: One message in an `observe` list.
                        properties:
                          speaker_id:
                            anyOf:
                              - type: string
                                maxLength: 200
                                minLength: 1
                              - type: 'null'
                            title: Speaker Id
                            description: >-
                              Your own id for the speaker. Kept on the turn and
                              returned with it.
                          timestamp:
                            anyOf:
                              - type: string
                                format: date-time
                              - type: 'null'
                            title: Timestamp
                            description: >-
                              When the message was said, used to date its
                              memories. Defaults to when the server receives it.
                          metadata:
                            anyOf:
                              - properties:
                                  path:
                                    anyOf:
                                      - type: string
                                        maxLength: 1024
                                        minLength: 1
                                      - type: 'null'
                                    title: Path
                                    description: >-
                                      The path of the file or page the turn came
                                      from.
                                  section:
                                    anyOf:
                                      - type: string
                                        maxLength: 500
                                        minLength: 1
                                      - type: 'null'
                                    title: Section
                                    description: >-
                                      The section of that source the turn came
                                      from.
                                  page:
                                    anyOf:
                                      - type: integer
                                        maximum: 1000000
                                        minimum: 1
                                      - type: 'null'
                                    title: Page
                                    description: >-
                                      The page the turn came from, counting from
                                      1.
                                  parent_id:
                                    anyOf:
                                      - type: string
                                        maxLength: 200
                                        minLength: 1
                                      - type: 'null'
                                    title: Parent Id
                                    description: >-
                                      The id of the item the turn belongs to, in
                                      your own system.
                                additionalProperties: true
                                type: object
                                title: TurnMetadata
                                description: >-
                                  Where a turn came from: four named keys, and
                                  any keys of your own. At most 32 keys and 8
                                  KiB as JSON.
                              - type: 'null'
                            description: >-
                              Where the message came from, kept on the turn and
                              returned with it.
                          text:
                            description: What was said.
                            maxLength: 2000000
                            minLength: 1
                            title: Text
                            type: string
                          speaker:
                            description: Who said it, such as a person's name.
                            maxLength: 200
                            minLength: 1
                            title: Speaker
                            type: string
                        required:
                          - text
                          - speaker
                        title: Message
                        type: object
                      maxItems: 100
                      minItems: 1
                      type: array
                  description: >-
                    One message as a string, or a list of up to 100 messages,
                    each with its own speaker.
                  title: Content
                speaker:
                  anyOf:
                    - type: string
                      maxLength: 200
                      minLength: 1
                    - type: 'null'
                  title: Speaker
                  description: >-
                    Who said the message, such as a person's name. Required with
                    an API key.
              required:
                - content
              title: ObserveRequest
              type: object
          multipart/form-data:
            schema:
              additionalProperties: false
              description: >-
                The multipart fields sent beside the document in `file`: who
                uploaded it, as on a message. The agent also

                learns a turn saying who uploaded the file. The server splits
                the document into turns.
              properties:
                file:
                  type: array
                  items:
                    type: string
                    format: binary
                  description: >-
                    The documents, one `file` part each: repeat the part to send
                    several, up to the session's `max_files_per_upload`;
                    together they stay under its `max_upload_bytes`.
                speaker_id:
                  anyOf:
                    - type: string
                      maxLength: 200
                      minLength: 1
                    - type: 'null'
                  title: Speaker Id
                  description: >-
                    Your own id for the speaker. Kept on the turn and returned
                    with it.
                timestamp:
                  anyOf:
                    - type: string
                      format: date-time
                    - type: 'null'
                  title: Timestamp
                  description: >-
                    When the message was said, used to date its memories.
                    Defaults to when the server receives it.
                metadata:
                  anyOf:
                    - properties:
                        path:
                          anyOf:
                            - type: string
                              maxLength: 1024
                              minLength: 1
                            - type: 'null'
                          title: Path
                          description: The path of the file or page the turn came from.
                        section:
                          anyOf:
                            - type: string
                              maxLength: 500
                              minLength: 1
                            - type: 'null'
                          title: Section
                          description: The section of that source the turn came from.
                        page:
                          anyOf:
                            - type: integer
                              maximum: 1000000
                              minimum: 1
                            - type: 'null'
                          title: Page
                          description: The page the turn came from, counting from 1.
                        parent_id:
                          anyOf:
                            - type: string
                              maxLength: 200
                              minLength: 1
                            - type: 'null'
                          title: Parent Id
                          description: >-
                            The id of the item the turn belongs to, in your own
                            system.
                      additionalProperties: true
                      type: object
                      title: TurnMetadata
                      description: >-
                        Where a turn came from: four named keys, and any keys of
                        your own. At most 32 keys and 8 KiB as JSON.
                    - type: 'null'
                  description: >-
                    Where the message came from, kept on the turn and returned
                    with it.
                speaker:
                  anyOf:
                    - type: string
                      maxLength: 200
                      minLength: 1
                    - type: 'null'
                  title: Speaker
                  description: >-
                    Who said the message, such as a person's name. Required with
                    an API key.
                source_timestamp:
                  anyOf:
                    - type: string
                      format: date-time
                    - type: 'null'
                  description: >-
                    When the source content is from, as an ISO 8601 timestamp.
                    Applies to every chunk of each file and defaults to
                    ingestion time. Timestamps without an offset use UTC. When
                    resending a partially learned file, use the original source
                    timestamp, or omit it if the original upload was undated. A
                    completed upload of the same bytes in the same conversation
                    is reused even with allow_duplicate. To apply a different
                    timestamp, read the file in another conversation.
                  title: Source Timestamp
                allow_duplicate:
                  default: false
                  title: Allow Duplicate
                  type: boolean
              title: DocumentFields
              type: object
              required:
                - file
      responses:
        '202':
          description: >-
            Accepted for learning. A message call's Location points at its
            status; a file call names each file's observation in `files`
            instead.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ObserveAccepted'
          headers:
            Location:
              description: >-
                The status endpoint for this observation, as a relative
                reference: resolve it against this request's URL. Follow it
                rather than building the path from `observation_id`.
              schema:
                type: string
                format: uri-reference
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
      security:
        - projectKey: []
components:
  schemas:
    ObserveAccepted:
      properties:
        observation_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Observation Id
          description: >-
            A message call's background learning: poll GET
            .../observe/{observation_id} for its progress. Null for a file call,
            whose `files` name one each.
        files:
          anyOf:
            - items:
                $ref: '#/components/schemas/ObservedFile'
              type: array
            - type: 'null'
          title: Files
          description: >-
            A file call's files, every one in the order sent, each with its own
            observation. The agent reads them in the background one at a time,
            after any file it is already reading. Null for a message call.
      type: object
      required:
        - observation_id
        - files
      title: ObserveAccepted
      description: What an `observe` call accepted. Learning runs in the background.
    ObservedFile:
      properties:
        file_id:
          anyOf:
            - type: string
            - type: 'null'
          title: File Id
          description: The id the file is kept under; null when it was refused.
        observation_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Observation Id
          description: >-
            This file's background learning; poll GET
            .../observe/{observation_id}. Null when refused.
        duplicate:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Duplicate
          description: >-
            True when this agent already had these exact bytes, or the call sent
            them earlier in `files`: nothing was read or billed, and the ids are
            the earlier upload's. Null when refused.
        error:
          anyOf:
            - $ref: '#/components/schemas/FileRefusal'
            - type: 'null'
          description: >-
            Why this file was not accepted, null when it was; a retry under the
            same Idempotency-Key replays this answer, so resend a refused file
            in a new call under a new key.
      type: object
      required:
        - file_id
        - observation_id
        - duplicate
        - error
      title: ObservedFile
      description: One file of an `observe` call, in the place it was sent.
    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.
    FileRefusal:
      properties:
        code:
          type: string
          title: Code
          description: The error code a call sending only this file would answer.
        message:
          type: string
          title: Message
          description: What went wrong, in a sentence.
        retry_after:
          anyOf:
            - type: integer
            - type: 'null'
          title: Retry After
          description: >-
            Seconds after which sending this file again may succeed; null when
            waiting will not help.
      type: object
      required:
        - code
        - message
        - retry_after
      title: FileRefusal
      description: >-
        Why one file of the call was not accepted, as a call sending it alone
        would have been told.
  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
    Retry-After:
      description: Seconds to wait before retrying. Always at least 1.
      required: true
      schema:
        type: integer
        minimum: 1
    X-RateLimit-Limit:
      description: Requests admitted per period by the window closest to its limit.
      schema:
        type: integer
        minimum: 1
    X-RateLimit-Remaining:
      description: Requests left in that window. Zero when that window refused the request.
      schema:
        type: integer
        minimum: 0
    X-RateLimit-Reset:
      description: Unix timestamp (seconds) at which that window admits again.
      schema:
        type: integer
    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'
    TooManyRequests:
      description: >
        A rate limit refused the request. The body's `code` is
        `rate_limit_exceeded`, and `details` names the limit that refused. Wait
        the seconds in `Retry-After` before retrying; a sooner retry is refused
        again. The `X-RateLimit-*` headers describe the window closest to its
        limit, which may not be the one that refused.
      headers:
        Retry-After:
          $ref: '#/components/headers/Retry-After'
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
        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.