# Authentication

Every call, on every interface, authenticates with an [API key](/docs/authentication/api-keys.md) or as a person, with OAuth or a sign-in. The steps are in [Authentication](/docs/start/authentication.md).

## Credentials

**Code**

The CLI signs you in and stores a token in `~/.config/veryfront/token`:

```bash
npx veryfront login
```

It opens a browser. `--google`, `--github` and `--microsoft` pick the provider; with no browser, `--token` asks for an [API key](/docs/authentication/api-keys.md) instead:

```bash
npx veryfront login --token
```

In scripts and projects, the CLI and the TypeScript SDK read an API key:

```bash title=".env"
VERYFRONT_API_KEY=vf_…
```

Check who you are:

```bash
npx veryfront whoami
```

**Studio**

[Sign in](/sign-in) with Google, GitHub, Microsoft or an email link. Studio keeps the session in a browser cookie.

**API**

Send an API key in the `Authorization` header:

```bash
curl "https://api.veryfront.com/projects?limit=1" \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

`X-API-Key: $VERYFRONT_API_KEY` works too. The AI Gateway takes the same header; see [Use any SDK](/docs/ai-gateway/sdk.md).

**MCP**

A client with OAuth opens Veryfront to sign in: click **Authorize**. Any other client sends an API key:

```bash
curl -X POST https://api.veryfront.com/mcp \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "veryfront__get_current_user", "arguments": {}}}'
```

See [Connect a coding agent](/docs/mcp/connect.md).

## API keys

A key looks like `vf_<prefix>_<secret>`. Its secret is shown once, when you create it. Both headers work the same:

```bash
curl https://api.veryfront.com/projects?limit=1 \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"

curl https://api.veryfront.com/projects?limit=1 \
  -H "X-API-Key: $VERYFRONT_API_KEY"
```

A key has:

* **Scopes**: `read` by default. `read`, `write` and `delete` cover everything; narrower ones name a resource, such as `files:write` or `sandboxes:*`.
* **A project**: a project key reaches only that project. A key made without one acts for its user.
* **An expiry**: optional. An expired key is rejected as `Invalid or expired API key`.
* **Inference limits**: the models it may call and its requests per minute. See [Limits](/docs/reference/limits.md).

See:

* [Create an API key](/docs/authentication/api-keys.md)
* [Revoke access](/docs/authentication/revoke-access.md)
* [Limit an API key's models](/docs/authentication/key-models.md)

## OAuth

The MCP server signs in MCP clients with OAuth: authorization code with PKCE (`S256`), public clients, scope `mcp`, and refresh tokens. A client registers itself at `/oauth/register` and revokes an access or refresh token at `/oauth/revoke`; the rest of the server is described at `/.well-known/oauth-authorization-server`. When an app asks, Veryfront shows **Connect to Veryfront**, to use Veryfront as you with your existing permissions: click **Authorize** or **Cancel**. Your approved apps are under **MCP clients** in your own **Settings** > **Connections**, with **Project**, **Approved** and **Last used**; **Revoke** in a row's **⋯** menu removes one.

## When a call isn't authenticated

A missing, malformed or expired credential returns `401` with the error `authentication-required`:

```json
{
  "type": "https://api.veryfront.com/errors/authentication-required",
  "title": "Authentication Required",
  "status": 401,
  "detail": "Invalid or expired API key",
  "slug": "authentication-required"
}
```

`Missing or invalid Authorization header` means no credential reached the API; `Invalid or expired API key` means one did and was refused. A credential without the permission gets `403` `authorization-denied`. See [Errors](/docs/reference/errors.md).

See [Fix errors](/docs/help/errors.md).
