Skip to main content
End-to-end reference of the v2 API in usage order, from verifying your API key through offboarding an agent. Every example uses the base URL https://app.sapientpriors.com/api with Authorization: Bearer $SP_API_KEY (see Authentication). Two errors can happen on any call, so the per-stage tables do not repeat them:
  • 401 unauthorized: your key is missing, unknown, revoked, or expired, or the person who created a personal key is no longer a member.
  • 503 service_unavailable: a Priors component did not respond, or the agent is restarting. Wait a few seconds and retry.
With a service-account key, include X-SP-End-User on thread calls to act for one named person on your side. It separates that person’s thread list and gives them their own rate-limit window. Memory stays shared across the agent.

Stage 0: verify your key

Your organization and project exist before your first API call. Create a service-account key or a personal key on the project’s API keys page of the Priors app (there is no API endpoint for key creation). See Set up your organization. Call GET/v2/me at startup to confirm who your key acts as and which organization it resolves to:

Stage 1: create an agent

Send POST/v2/agents. The agent lives in your key’s project. Who can teach it, update it, forget its memories, or delete it depends on your role. See Roles and permissions.
Success: status 202. The agent_id is final, and status starts as initializing.
Then: poll GET/v2/agents/ every second until status is ready (typically a few seconds). An agent still initializing after 10 minutes moves to failed; delete it and create a new one. Errors: Store the agent_id on your own record. metadata is a returned label, not a lookup index. PATCH/v2/agents/ replaces agent_config whole (send role, objective, and metadata together) without touching memory. The API cannot change visibility; a Project admin can change it in the Priors application.

Stage 2: open a thread

Send POST/v2/agents//threads. Open one thread per conversation, ticket, or user session.
Success: status 201 with a thread_id. The thread is ready at once. Errors: 409 agent_not_ready, 404 agent_not_found, 429 rate_limit_exceeded (more than 5 threads per 10 s per subject). Other thread calls:

Stage 3: teach the agent (messages or files)

Use POST/v2/agents//threads//observe to teach an agent without asking for an answer. The same endpoint accepts JSON (one message or up to 100 messages) or multipart/form-data (one file up to 30 MiB).

Send messages as JSON

Success: status 202 with an observation_id and a Location header pointing to the status endpoint.

Upload a file as multipart/form-data

One file per call, up to 30 MiB and 20,000 pieces. Supported formats include PDF, Word, PowerPoint, Excel, OpenDocument, CSV, RTF, EPUB, Markdown, plain text, source code, and images (PNG, JPEG, GIF, WebP read as one-page documents). SVG is not accepted. Success: status 202. observation_id is null, and files gives each file’s file_id and its own observation_id. Poll that observation to check whether it is queued, converting, processing, or committed.

Poll learning status

Call GET/v2/agents//threads//observe/ (respecting Retry-After when present) until status is committed. Errors on observe:

Stage 4: ask the agent

Four v2 answering calls cover two choices: Priors answers vs your own model, and learn from this turn vs read-only.

Priors answers: observe-and-respond and respond

Success: status 200.
Set "stream": true on observe-and-respond or respond to receive server-sent events (delta events, then one complete or one error). Set "include_memories": true to return the underlying memories alongside answer. Attach images in files (base64 data or an existing file_id).

Bring your own model: observe-and-recall and recall

Success: status 200 with memories in the order the search found them. Each memory is the turn it was made from, with turn_id, speaker, speaker_id, text, timestamp, and metadata. Errors on answering calls: 400/422 invalid_request, 402 payment_required, 404 thread_not_found, 409 agent_not_ready, 429 rate_limit_exceeded (20/min per subject or 2 concurrent answers per subject), 503 answer_model_unavailable. Answering calls run normally while a file is being learned.

Stage 5: manage files and memories

Files

Memories

Stage 6: activity and usage

  • GET/v2/agents//logs returns which thread was used, by which subject, and when (never message text).
  • GET/v2/projects//usage returns your key’s project usage over a date range: totals, daily buckets, and sums by agent, by API key, and by operation. Take project_id from api_key.project_id on GET/v2/me. See Credits.

Stage 7: delete

The whole lifecycle in one table