# Authentication

Use a bearer API key for every request.

## Create a key

Open [Settings → API keys](https://app.smallworld.sh/app/settings/keys). Copy your new key; it is shown only once.

Follow the [Quick start](https://smallworld.sh/docs/guides/quick-start.md) to make your first authenticated request with this key.

Store it on your server, outside source control and model messages.

Server environment

```bash
export SMALLWORLD_API_KEY="swk_replace_with_your_key"
```

## Authenticate requests

Request headers

```http
Authorization: Bearer swk_replace_with_your_key
```

Use the JSON content type for request bodies. Browser login cookies do not authenticate `/api/v1`.

## Access and identity

Keys access the owner’s entire workspace. Your backend must authorize each user’s access to sessions, executions, connections, and approvals.

Derive `userId` from your authenticated application user. It is your identifier, not a Smallworld login ID.

To connect a user’s external account, create a [connect session](https://smallworld.sh/docs/create-connect-session.md).

IP restrictions and key rotation

[IP restrictions](https://app.smallworld.sh/app/settings/security) apply to every `/api/v1` request made with your API keys, including keys created by the dashboard Quick start. Disallowed addresses receive `403 ip_not_allowed`. The dashboard and the Playground, which uses a Smallworld-managed key, work from any address.

To rotate a key, create a replacement, update your backend, then revoke the old key in Settings.
