# Authentication

> Authenticate to the Layerz REST API with an API key or an OAuth access token, scope a key to one model or to read-only, and what each access level allows.

Every request carries a Bearer token:

```http
Authorization: Bearer lz_0123456789abcdef0123456789abcdef01234567
```

Two kinds of tokens are accepted.

## API keys

Created in the app: account menu, then **API**. A key is `lz_` followed by 40 hex characters, shown once, and stored hashed. At creation you choose:

| Option      | Values                        |
| ----------- | ----------------------------- |
| Scope       | All your models, or one model |
| Permissions | Full, or read-only            |
| Expiry      | None, or a date               |

A key acts as you: it sees the models of your workspaces and the models shared with you. A key limited to one model can only call that model's routes; a read-only key gets `403` on every write. Revoke a key from the same screen.

## OAuth access tokens

Applications that act for other users use OAuth 2.1 with PKCE: dynamic client registration, the authorization endpoint, then the token endpoint. Discovery documents are served at `/.well-known/oauth-authorization-server` and `/.well-known/oauth-protected-resource`. Tokens are audience-bound to the API or to the MCP server and give full access to the user's models.

## Access to a model

Each model in a response carries the caller's `access`: `owner`, `editor` or `viewer`. Reading needs any access; writing needs `owner` or `editor`; deleting a model needs `owner`. A model outside your access returns `404`, never a hint that it exists.
