Skip to main content
This walkthrough puts a full multi-tenant backend integration in one place: one service-account key on your server, one agent per customer, one thread per conversation, and X-SP-End-User to scope each end user’s thread list and rate-limit window.

The isolation model

Two headers identify a backend request:
  • Authorization: Bearer spk_...: identifies your service account, which reaches every public agent in its project.
  • X-SP-End-User: your stable identifier for one end user inside that customer’s agent.
The agent is the memory boundary, not X-SP-End-User. Give each customer their own agent so memories never mix across customers. Inside one agent, X-SP-End-User separates each person’s thread list and rate-limit window while memory stays shared across the agent.

Step 1: create a service-account key

A Project admin creates a service account on the project’s API keys page, gives it the Project admin role so your code can create and delete agents, and creates a key for it (90 or 365 days; default 365). Store the whole spk_<key_id>_<secret> token in your secret manager; the secret is shown once. A service account can hold up to 5 live keys for zero-downtime rotation. See Service accounts. Verify startup configuration with GET/v2/me.

Step 2: create one agent per customer

Poll GET/v2/agents/ until status is ready, then persist agent_id on your customer record. If it fails:
  • 400 invalid_request: request carried Sec-Fetch-Site (key reached a browser) or invalid config.
  • 403 forbidden: the service account’s role cannot create agents. Give it the Project admin role.
  • 409 agent_quota_exceeded: the organization holds 100 live agents. Request a quota increase once you pass roughly 80 active customers.

Step 3: open a thread for one end user

Send the same X-SP-End-User value on every call for that person. Sending an empty or whitespace header returns 400 rather than silently widening to the service account’s own scope.

Step 4: answer a question

answer is ready to show to the user. To use your own model instead, call POST…/observe-and-recall (or POST…/recall for read-only access). Notice the difference between speaker and X-SP-End-User:
  • speaker (and speaker_id) is stored on the turn so the agent knows who said what and you can filter GET…/memories by speaker_id.
  • X-SP-End-User scopes thread visibility and per-user rate limits; Priors hashes it and never stores it in memory.

Step 5: list one end user’s threads

Returns items filtered strictly to threads created by customer-4471-person-7, with next_cursor for pagination. Calling without X-SP-End-User acts as the service account, which lists only the threads it created itself. Call without the header for management routes an end user cannot use, such as GET/v2/agents//memories or DELETE/v2/agents/.

Keep the key on your server

Never bundle a key into front-end or mobile code. Priors sends no CORS headers and rejects any keyed request carrying Sec-Fetch-Site with 400.