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

# Service accounts

> The identity your production servers use: what a service account can reach, which role to give it, and how to rotate its keys.

A **service account** is a member of one project with no person behind it. Your production servers call Priors with its key. Its keys keep working when people leave the organization, and it is the only kind of key that can act for one of your own customers with `X-SP-End-User`.

## What a service account reaches

* **Only its own project.** A call to an agent in another project returns `404`.
* **Only public agents.** A service account never reaches a private agent, whatever its role. Every agent it creates is public.
* **Only its own threads.** With `X-SP-End-User`, it reads only the threads that end user created. Without the header, it reads only the threads the service account created itself.

## Create a service account and its key

A Project admin or Org admin creates a service account and its first key in one step, in the Priors app:

1. Open the project's **API keys** page and choose **Create key**.
2. Name the key and pick how long it lasts: 90 or 365 days, 365 by default. A service-account key always expires.
3. Tick **Mark as service account key**, and pick the service account's role. See the table below.
4. Choose **Generate key**, and copy the key. **The secret is shown once.** Put it straight into your secret manager.

The key looks like `spk_<key_id>_<secret>`. Note its expiry date when you store it: an expired key returns `401` with no advance warning to your code.

| Role | The key can | Pick it when |
| - | - | - |
| **Project admin** | Create, update, and delete agents, teach them, upload and delete files, read and delete memories, and read the project's usage and request log. | Your code creates an agent per customer and manages its whole lifecycle. |
| **Agent admin** | Chat with every public agent, and teach the agents picked for it. | Your code serves a fixed set of agents that you create by hand. |
| **Contributor** | Chat with every public agent. Nothing it sends is learned. | Your code only answers from agents that someone else teaches. |

The roles mean the same as for a person. See [Roles and permissions](https://www.sapientpriors.com/docs/access/roles.md). A service account cannot make an agent private or change an agent's visibility.

Check the key with [GET`/v2/me`](https://www.sapientpriors.com/docs/api-reference/v2/users/get-me). For a service account, `api_key.acts_as.type` is `service_account`.

## Rotate a key

1. Create a new service-account key with the same role, as above. In the Priors app, each new service-account key comes with its own service account.
2. Deploy the new key to every server.
3. Revoke the old key on the **API keys** page. Revocation applies on the next request.

The two keys work side by side until you revoke the old one, so a rotation never stops traffic. Threads that your customers created through `X-SP-End-User` stay reachable with the new key. Threads that the old service account created without the header stay with the old service account.

## Act for one of your customers

Send your own stable id for the customer in `X-SP-End-User` on every call made for that customer:

```http theme={null}
Authorization: Bearer spk_7Kq2mN4pXr8wLz1c_a3f9…
X-SP-End-User: customer-4471-person-7
```

The header limits the call to the threads that customer created and gives the customer their own rate-limit window. It does not separate memory: the agent does. Only a service-account key accepts the header. Every other key returns `400`. See [Authentication](https://www.sapientpriors.com/docs/authentication.md#name-one-of-your-customers).


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