# Authentication (/developers/authentication)

> Authenticate server-to-server with workspace API keys, or act on behalf of a user with Rexplore ID OAuth.

> **Preview:** this feature is in preview. The contract is stable enough to build against, but details may change before general availability.

The Luso8 API supports two ways to authenticate. Pick the one that matches who is acting.

| Method | Acts as | Best for |
| --- | --- | --- |
| **API key** | Your workspace | Backends, scheduled jobs, integrations you run on a server |
| **Rexplore ID OAuth** | A signed-in user | Apps where each person signs in with their own Rexplore ID, and MCP clients |

## API keys [#api-keys]

An API key belongs to exactly one workspace and carries a set of [scopes](#scopes). Every request made with the key reads and writes that workspace's data only.

Send the key in the `Authorization` header as a bearer token:

```bash
curl https://api.luso8.rexplore.ai/api/v1/contacts \
  -H "Authorization: Bearer luso8_sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```

If your HTTP client or proxy makes the `Authorization` header awkward, send the same key in `X-API-Key` instead:

```bash
curl https://api.luso8.rexplore.ai/api/v1/contacts \
  -H "X-API-Key: luso8_sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```

Create and manage keys in **Settings → Developers → API keys**. See [API keys](/developers/api-keys) for formats, rotation and best practices.

<Callout type="warn" title="Keep keys on the server">
An API key grants access to your whole workspace within its scopes. Never put it in a browser bundle, a mobile app, a public repository or a URL. Store it in a secret manager or environment variable and call Luso8 from your backend.
</Callout>

## Rexplore ID OAuth [#rexplore-id-oauth]

When your app acts for a specific person, have them sign in with [Rexplore ID](/rexplore-id), the account system behind every Rexplore product. Rexplore ID is a standard OpenID Connect provider:

- **Issuer**: `https://auth.rexplore.ai`
- **Flow**: authorization code with PKCE (`S256`)
- **Tokens**: short-lived RS256 JWT access tokens, rotating refresh tokens with `offline_access`

Send the user's access token exactly like an API key:

```bash
curl https://api.luso8.rexplore.ai/api/v1/contacts \
  -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..."
```

Requests made with a user token run with that user's permissions in their active workspace. The endpoints, discovery document and token lifetimes are documented in [Rexplore ID for developers](/rexplore-id/developers).

AI tools that connect to the [remote MCP server](/developers/mcp) use this flow automatically, with dynamic client registration.

## Scopes [#scopes]

API keys are limited to the scopes you choose when you create them. Each scope is `<resource>:read` or `<resource>:write`.

| Rule | Meaning |
| --- | --- |
| `contacts:read` | Read-only access to one resource (`GET` requests) |
| `contacts:write` | Create, update and delete on that resource. **Write implies read.** |
| `*` | Full access to every resource, now and in the future |

The resources are `contacts`, `companies`, `deals`, `leads`, `lists`, `campaigns`, `conversations`, `calls`, `appointments`, `tickets`, `agents`, `knowledge`, `workflows` and `reports`. Each endpoint in the [API reference](/developers/api-reference) states the scope it requires.

A request without the needed scope fails with `403`:

```json
{ "detail": "Missing scope: contacts:write" }
```

## Authentication errors [#authentication-errors]

| Status | Body | Cause |
| --- | --- | --- |
| `401` | `{"detail": "Invalid API key"}` | Missing, malformed, revoked or unknown key |
| `401` | `{"detail": "..."}` | Expired or invalid OAuth access token. Refresh it and retry. |
| `403` | `{"detail": "Missing scope: x:y"}` | The key is valid but lacks the scope for this endpoint |

See [Errors](/developers/errors) for every status code.