# Agents (/docs/api/agents)

The agent API does everything a person can do in the dashboard: apply for access, create an account, sign in, and then manage organizations, audiences, flags and tests and read their results. The endpoints live under `/api/agent/*`, take JSON and return JSON. Errors are [problem details](/docs/api/errors) with a stable `code` and a `hint`.

Every endpoint is in the [OpenAPI spec](/openapi.json), which is the full reference. These pages walk through them:

<Cards>
	<Card
		title="Organizations"
		href="/docs/api/agents/organizations"
		description="Roles, API tokens, allowed origins, members, usage"
	/>
	<Card
		title="Audiences"
		href="/docs/api/agents/audiences"
		description="Targeting rules for tests and flags"
	/>
	<Card
		title="Flags"
		href="/docs/api/agents/flags"
		description="Feature flags and their options"
	/>
	<Card
		title="Tests"
		href="/docs/api/agents/tests"
		description="A/B and multi-variant tests"
	/>
	<Card
		title="Results"
		href="/docs/api/agents/results"
		description="Test results, events and visitor analytics"
	/>
</Cards>

## Getting started [#getting-started]

1. [Sign in](#sign-in), or [create an account](#create-an-account), for a bearer token.
2. List your [organizations](/docs/api/agents/organizations) to get an `organizationId`. Without one, create one with a plan, or [apply for access](#apply-for-access) for the organization key that creates it without a checkout.
3. Work in an environment of it: `develop`, `staging` or `production`.

The account and organization endpoints are served by `www.obelism.studio` for every Obelism product, since one account, one token and one set of organizations work everywhere: creating an account, verifying, signing in and out, resetting the password, the profile, invites, applying for access, and creating, deleting and staffing organizations. Improve answers those paths with a `308` redirect there, so a client that follows redirects can keep calling Improve's host. Listing your organizations, reading one, and everything about tests, flags, audiences and results stay on `improve.obelism.studio`.

## Apply for access [#apply-for-access]

Joins the waitlist, the same as the form on the homepage. The applicant gets a confirmation email, and an **organization key** by email once the application is approved; the key creates an Organization without a plan checkout.

```bash
curl -X POST https://www.obelism.studio/api/agent/apply \
  -H "Content-Type: application/json" \
  -d '{"email":"jane@example.com","name":"Jane","company":"Acme"}'
```

```json
{ "status": "pending" }
```

## Create an account [#create-an-account]

```bash
curl -X POST https://www.obelism.studio/api/agent/auth/sign-up \
  -H "Content-Type: application/json" \
  -d '{"email":"jane@example.com","password":"a-long-Passw0rd!","firstName":"Jane","lastName":"Doe"}'
```

```json
{
	"token": "Zm9vYmFyYmF6cXV4cXV1eGNvcmdlZ3JhdWx0",
	"tokenType": "Bearer",
	"expiresAt": "2026-11-07T12:00:00.000Z",
	"userId": "user_01H8XYZ",
	"verificationRequired": true
}
```

The password needs at least 8 characters, including a number and a special character. A six-digit code is emailed to the address.

## Verify the email [#verify-the-email]

Send the code from the email with the token from sign-up or sign-in:

```bash
curl -X POST https://www.obelism.studio/api/agent/auth/verify-email \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"code":"123456"}'
```

Codes are valid for 4 hours. Signing in with an unverified account emails a new one and returns `verificationRequired: true`.

## Sign in [#sign-in]

```bash
curl -X POST https://www.obelism.studio/api/agent/auth/sign-in \
  -H "Content-Type: application/json" \
  -d '{"email":"jane@example.com","password":"a-long-Passw0rd!"}'
```

The response has the same shape as sign-up. The response is the same `401 invalid_credentials` whether the email is unknown or the password is wrong.

With two-factor authentication on (turned on under [Security](https://www.obelism.studio/account/security) on your Obelism account), the answer is `401 two_factor_required`: send the same request with `code`, the current 6-digit code from the authenticator app. The recovery code works there too, and turns two-factor authentication off.

## Forgot your password [#forgot-your-password]

Request a reset email:

```bash
curl -X POST https://www.obelism.studio/api/agent/auth/forgot-password \
  -H "Content-Type: application/json" \
  -d '{"email":"jane@example.com"}'
```

The answer is `202` whether or not the email has an account. The email links to `/reset-password?token=…`. That token is valid for 1 hour, and a newer request replaces it. Set the new password with it:

```bash
curl -X POST https://www.obelism.studio/api/agent/auth/reset-password \
  -H "Content-Type: application/json" \
  -d '{"token":"…","newPassword":"an-even-longer-Passw0rd!"}'
```

This ends every session of the account and returns a new token, like sign-in. With two-factor authentication on, send `code` as well, as for sign-in: the reset email alone doesn't change the password.

## Use the token [#use-the-token]

Send the token on every request that needs an account:

```bash
curl https://improve.obelism.studio/api/agent/me \
  -H "Authorization: Bearer $TOKEN"
```

A token is valid for 30 days and is extended while it is in use. `GET /api/agent/me` returns the account and the current expiry, so it doubles as a check that a stored token still works. A `401 unauthorized` means the token is missing, invalid or expired: sign in again.

The token is a full login session for the account. Store it like a password and never put it in client-side code.

## Update your profile [#update-your-profile]

`PATCH /api/agent/me` on `www.obelism.studio` changes the name. Fields you leave out keep their value. The email address can't be changed, since invites to organizations are matched by it.

```bash
curl -X PATCH https://www.obelism.studio/api/agent/me \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"firstName":"Jane","lastName":"Doe"}'
```

## Change your password [#change-your-password]

```bash
curl -X POST https://www.obelism.studio/api/agent/me/password \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"currentPassword":"a-long-Passw0rd!","newPassword":"an-even-longer-Passw0rd!"}'
```

This ends every session of the account, including the token you sent. The response has a new token to continue with, in the same shape as sign-in.

## Sign out [#sign-out]

```bash
curl -X POST https://www.obelism.studio/api/agent/auth/sign-out \
  -H "Authorization: Bearer $TOKEN"
```

The token stops working straight away.

## Rate limits [#rate-limits]

| Endpoint          | Limit                       |
| ----------------- | --------------------------- |
| `apply`           | 3 per email per hour        |
| `sign-up`         | 3 per email per hour        |
| `sign-in`         | 5 per email per minute      |
| `forgot-password` | 3 per email per hour        |
| `reset-password`  | 5 per reset token per 5 min |
| `verify-email`    | 5 per account per 15 min    |

Every response from these endpoints states its limit in a `RateLimit-Policy` header, such as `"sign-in";q=5;w=60`. Over the limit the response is `429 rate_limited` with `RateLimit` and a `Retry-After` header in seconds. See [Versioning](/docs/api/versioning#agent-account-endpoints).
