# Workspaces and teams

> Personal and organization workspaces, roles, invitations, and how a request picks the workspace it acts in.

Source: https://openpipe.health/docs/workspaces/

Every request acts in one workspace. The workspace owns the credits, the API keys, the usage history, the dashboards and the exports. People belong to workspaces; data does not belong to people.

## Two kinds of workspace

| Kind | Who is in it | How it is created |
|---|---|---|
| Personal | You alone | Automatically, on your first signed-in request |
| Organization | You and the people you invite | You create it and become its owner |

Each workspace has its own plan and its own monthly [credit](https://openpipe.health/docs/credits.md) allowance. A new workspace of either kind starts on the `free` plan with 100 credits a month. Credits spent in an organization workspace do not touch your personal one, and the other way round.

You can belong to several organization workspaces as well as your personal one.

## Which workspace a request acts in

| You send | Workspace |
|---|---|
| An API key | Always the workspace that created the key. This cannot be changed per request. |
| A session token | Your personal workspace |
| A session token and `X-Oph-Workspace: <organization id>` | That organization workspace, if you are a member |

```http
GET /api/me
Authorization: Bearer <session token>
X-Oph-Workspace: 5b0c9a52-7f1e-4a4e-9d1c-2f6f0c1d8e11
```

- The header value is the organization's id, as returned by `GET /api/auth/orgs`.
- If you are not a member, or the organization does not exist, the response is `403` with `You are not a member of that workspace.` The two cases are not told apart.
- The header is ignored when the token is an API key.

[`GET /api/me`](https://openpipe.health/docs/api/account.md#get-your-account) reports the workspace a request resolved to, and your role in it.

## Roles

An organization workspace has three roles. In your personal workspace you are always the owner.

| | Owner | Admin | Member |
|---|---|---|---|
| Use the data: search, lookup, Ask, exports | Yes | Yes | Yes |
| See the workspace's balance, usage, keys list, dashboards and exports | Yes | Yes | Yes |
| Refresh a dashboard, save a dashboard | Yes | Yes | Yes |
| Rename or delete a recent (unsaved) dashboard | Yes | Yes | Yes |
| Rename, unsave or delete a saved dashboard | Yes | Yes | Only one they saved |
| Create and revoke API keys | Yes | Yes | No |
| Invite people, cancel invitations | Yes | Yes | No |
| Change a person's role, remove a person | Yes | Yes | No |

The key rows and the dashboard rows are enforced by this API. The invitation and people rows are enforced by the sign-in service (Neon Auth), which holds the membership records.

Things to know:

- **Members share everything they can see.** Usage history, dashboards and export links are per workspace, not per person. Any member can open and refresh them.
- **Saved dashboards have an owner.** A member can change or delete only the dashboards they saved. Owners and admins can change or delete anyone's. An API key can list, open and refresh, but never save, change or delete. See [who can do what](https://openpipe.health/docs/api/saved.md#who-can-do-what).
- **An onboarding profile is the exception to "data does not belong to people".** A [profile](https://openpipe.health/docs/api/profile.md) belongs to the person and is the same in every workspace they open.
- **Key management needs a signed-in person.** An API key can never create or revoke keys, whatever the role of the person who made it. See [Create a key](https://openpipe.health/docs/api/account.md#create-a-key).
- **A workspace must keep an owner.** The only owner cannot leave until someone else is made an owner.
- **Removal is quick but not instant.** A removed member's session token can keep working in that workspace for up to 30 seconds. The same delay applies to a role change.
- **Keys outlive their creator.** An API key belongs to the workspace. It keeps working after the person who created it leaves or is removed, until an owner or admin revokes it.

## Invitations

Owners and admins invite people by email address, as a `member` or an `admin`.

**The platform does not email the invitation.** Creating one returns an invite code, and the person who created it passes it on themselves:

1. An owner or admin creates the invitation for an email address. The response includes a `code` and an expiry time.
2. They send the code to the invitee by whatever channel they like.
3. The invitee signs in with the invited email address. An account with a different email cannot accept: `That invitation was sent to a different email address.`
4. The invitee's email must be confirmed first. Signing in with an [emailed code](https://openpipe.health/docs/authentication.md#browser-sign-in) confirms it; an account that only ever used a password confirms it with a `verify` code.
5. The invitee accepts or rejects. On accept they become a member with the invited role, and can then send `X-Oph-Workspace` with that organization's id.

An invitation can be cancelled by an owner or admin while it is pending. An expired or cancelled code returns `That invitation does not exist or has expired.`

## Workspace endpoints

These endpoints are part of the browser sign-in surface under `/api/auth`. They are for the web app: they authenticate with the sign-in cookie, not with a bearer token, so **an API key cannot call them**. They are listed here so the behaviour is clear, and may change without notice.

| Endpoint | Does |
|---|---|
| `GET /api/auth/orgs` | Lists your organization workspaces: `id`, `name`, `slug` |
| `POST /api/auth/orgs` | Creates one. Body `{ "name": "…" }`, 2 to 60 characters. Returns `201` with `org`. |
| `GET /api/auth/orgs/:id` | Returns `org`, `members` (`id`, `userId`, `role`, `email`, `name`, `joinedAt`) and pending `invitations` (`id`, `email`, `role`, `expiresAt`) |
| `POST /api/auth/orgs/:id/invitations` | Invites. Body `{ "email": "…", "role": "member" }`; `role` is `member` (default) or `admin`. Returns `201` with `invitation`: `id`, `email`, `role`, `expiresAt`, `code`. |
| `GET /api/auth/invitations/:id` | What an invite code points at: `email`, `role`, `status`, `orgId`, `orgName`, `invitedBy`. Needs the signed-in, confirmed recipient. |
| `POST /api/auth/invitations/:id/accept` | Accepts. Returns `{ "accepted": true, "orgId": "…" }`. |
| `POST /api/auth/invitations/:id/reject` | Rejects. Returns `{ "rejected": true, "orgId": "…" }`. |
| `POST /api/auth/invitations/:id/cancel` | Cancels a pending invitation |
| `POST /api/auth/orgs/:id/members/:memberId/role` | Changes a role. Body `{ "role": "member" }`; `member`, `admin` or `owner`. |
| `POST /api/auth/orgs/:id/members/:memberId/remove` | Removes a person |
| `POST /api/auth/orgs/:id/leave` | Leaves the workspace |

The invite `code` is the invitation's `id`. `:memberId` is the member's `id` from `GET /api/auth/orgs/:id`, not their `userId`.

`POST` bodies must be sent as `application/json`. Errors on these endpoints carry a machine-readable `code` next to the message, for example:

```json
{ "error": "Only owners and admins can invite people.", "code": "YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION" }
```

Creating workspaces, inviting, and answering invitations are rate limited per client address. See [Rate limits](https://openpipe.health/docs/api/errors.md#rate-limits).
