> ## Documentation Index
> Fetch the complete documentation index at: https://docs.styne.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Browser profiles

> A profile is one end user's logged-in browser, kept by name. Save a browser into a profile once the person is signed in, and any later session starts from it with the...

A profile is one end user's logged-in browser, kept by name. Save a browser into a profile once the person is signed in,
and any later session starts from it with the cookies, local storage, open tabs and page state it had when it was saved.
A saved profile sleeps and costs nothing to keep awake; it wakes in the region its browser is kept in.

Base URL: `https://api.styne.ai`. Every request carries `Authorization: Bearer $STYNE_API_KEY`.

## Create, save and use a profile

[//]: # "smoke: not executed, it needs a browser session that is signed in"

```bash theme={"theme":"css-variables"}
# 1. A profile for your end user.
curl -sS -X POST https://api.styne.ai/profiles -H "Authorization: Bearer $STYNE_API_KEY" \
  -H 'Content-Type: application/json' -d '{"end_user":"user_123","label":"work account"}'

# 2. Start a browser, sign in (with your client or through a person taking control), then save it into the profile.
curl -sS -X POST https://api.styne.ai/profiles/$PROFILE_ID/save -H "Authorization: Bearer $STYNE_API_KEY" \
  -H 'Content-Type: application/json' -d '{"browser_id":"'$BROWSER_ID'"}'

# 3. Later: a new session that starts logged in.
curl -sS -X POST https://api.styne.ai/browsers -H "Authorization: Bearer $STYNE_API_KEY" \
  -H 'Content-Type: application/json' -d '{"profile":"'$PROFILE_ID'"}'
```

The answer of step 3 is the usual session object with a `profile` field. Connect to its `cdp_url` as with any browser; the
page is signed in as it was left. Save again at any time to keep the newer state; the earlier one is replaced.

## Saved when the session ends

A session started with `profile` (and without `fork`) has `persist: true` by default: whenever it ends, its browser is
saved into the profile on the server, with no call from your code. That holds for every way a session ends:

* `DELETE /browsers/{id}` from any process, the dashboard, or a drop-in route (Steel, Browserbase, `DELETE /sandboxes/{id}`).
  The delete answers `204` at once; the save runs after it and billing stops at the delete.
* The session's `timeout`. The browser is paused at its timeout, saved, then stopped.
* A stop of the machine it runs on. A browser whose machine was lost before it could be saved is reported on the profile.

So step 2 above can be just "start a browser from the profile, sign in, end the session". Send `"persist": false` to keep
the explicit `POST /profiles/{id}/save` as the only way to write the profile. `persist: true` without `profile`, or with
`fork: true` (a copy that is not bound), is a `422`.

A save is not lost when it fails: the browser is kept paused, the save is tried again (after 30 s, then a doubling wait up
to 15 minutes, for up to 24 hours), and the profile says so in `last_save`. A new session from a profile whose save is still
running waits for it (up to 60 s), so a delete followed at once by a create starts with the state the first session left.

`GET /profiles/{id}` answers the newest save:

```json theme={"theme":"css-variables"}
{
  "id": "prof_8c1d0a2e4b6f8a0c2e4f",
  "state": "saved",
  "saved_at": 1764000000,
  "last_save": { "state": "saved", "trigger": "delete", "browser": "vm3f2a9c1d7e6b4a08", "at": 1764000000 }
}
```

| `last_save` field | Meaning |
| - | - |
| `state` | `saving` (under way), `saved`, or `failed` |
| `trigger` | What ended the browser: `delete`, `timeout` or `node_stop`; `save` for `POST /profiles/{id}/save` |
| `browser` | The session that was saved |
| `at` | Unix seconds of this state |
| `error` | Why the save failed (with `failed`) |
| `attempts`, `next_try_at` | Tries so far and when the next one runs (with `failed`); no `next_try_at` once the browser was stopped unsaved |

## Parallel runs

`{"profile": "<id>", "fork": true}` starts a copy of the saved browser that is not bound to the profile, so many runs can
use the same login at once and none of them changes it. `POST /v1/profiles/{id}/fork` makes a new profile that starts as a
copy of this one (for example for a second agent of the same person); it takes `end_user` and `label` and answers the new
profile.

## Is the login still valid

`POST /v1/profiles/{id}/check` starts a copy of the saved browser, opens a page and tests what you expect to see when the
person is signed in:

```json theme={"theme":"css-variables"}
{ "url": "https://app.example.com/account", "expect": { "url_matches": "/account$", "selector_exists": "#user-menu" } }
```

Expectations: `url_matches` (a regular expression on the final address), `selector_exists`, `text_contains`, `js_expr`
(a JavaScript expression that is truthy) and `cookie` (a cookie name that is present). All of them must hold within
`timeout` seconds (default 30, at most 45). The answer carries `ok`, the final `url` and the result of each expectation.
The newest outcome is also on the profile as `check`. When `ok` is false, send the person a new sign-in link.

## Hosted sign-in links

When your end user has to sign in themselves, create a link and send it to them:

[//]: # "smoke: not executed, it needs a person to open the link"

```bash theme={"theme":"css-variables"}
curl -sS -X POST https://api.styne.ai/signin-links -H "Authorization: Bearer $STYNE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"profile":"user_123","start_url":"https://app.example.com/login","allow_hosts":["accounts.google.com"],
       "success_check":{"url_matches":"/home$"},"return_url":"https://yourapp.example/connected"}'
```

The answer holds `url`, the link's address. Open it on a phone or a computer: the page shows a real browser on
`start_url` that the person controls with touch, mouse and keyboard (captchas and two-step codes work as they do in
any browser). The page can only visit the start address, the hosts it redirects to while it first loads, and
`allow_hosts`; it has no address bar and gives no access to the browser's DevTools. The address works for one person on one device
and carries no API key.

The link completes when the person presses **Done** or when `success_check` holds (`url_matches`, `selector_exists`,
`text_contains` or `cookie`). The browser is then saved into the profile and stopped. Read `GET /signin-links/{id}`:
`state` is `pending`, `opened`, `completed`, `expired` or `canceled`, and `check_passed` tells whether the success check
held. Then start the person's signed-in browser with `POST /browsers {"profile": "<profile_id>"}`.

## Calls

Every path is also served under `/v1` (for example `/v1/profiles`).

| Method | Path | What it does |
| - | - | - |
| `POST` | `/profiles` | Create a profile for an end user |
| `GET` | `/profiles` | List the account's profiles, optionally of one end user |
| `GET` | `/profiles/{id}` | Read a profile |
| `DELETE` | `/profiles/{id}` | Delete a profile and its saved browser |
| `POST` | `/profiles/{id}/save` | Save a running browser into the profile |
| `POST` | `/profiles/{id}/fork` | Make a new profile that starts as a copy |
| `POST` | `/profiles/{id}/check` | Test that the saved login still works |
| `POST` | `/signin-links` | Create a hosted sign-in link for an end user |
| `GET` | `/signin-links/{id}` | Read a sign-in link: state, profile, and whether the success check passed |
| `DELETE` | `/signin-links/{id}` | Cancel a sign-in link and stop its browser |

A profile of another account answers `404`. A profile with no saved browser answers `409` (`profile_empty`) to fork and
check. A profile counts as one saved snapshot against the plan's snapshot allowance.


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