# auth.md

You are an agent. This file tells you how to authenticate to Adaption on behalf of a user.

Adaption does not support agentic registration. There is no endpoint where an agent can create an account or register itself. A human must have an Adaption account. Then you authenticate in one of two ways:

- **API key**: for the REST API, the SDKs, and MCP clients that run without a browser.
- **OAuth 2.1**: for MCP clients that can open a browser so the user can sign in.

## Step 1: Discover

| What | URL |
| --- | --- |
| REST API base URL | `https://api.prod.adaptionlabs.ai/api/v1` |
| MCP server (Streamable HTTP, `POST` only) | `https://api.prod.adaptionlabs.ai/api/v1/mcp` |
| Protected resource metadata (RFC 9728) | `https://api.prod.adaptionlabs.ai/.well-known/oauth-protected-resource/api/v1/mcp` |
| Authorization server metadata (RFC 8414) | `https://api.prod.adaptionlabs.ai/.well-known/oauth-authorization-server` |
| Sign in or create an account | `https://adaptionlabs.ai/app/auth` |
| Docs | `https://docs.adaptionlabs.ai` |

A request to the MCP server without a token returns `401` with a header that points to the protected resource metadata:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.prod.adaptionlabs.ai/.well-known/oauth-protected-resource/api/v1/mcp", scope="adaption-mcp:read adaption-mcp:write"
```

## Step 2: Pick a method

1. **You can open a browser for the user, and you are an MCP client** → [OAuth](#oauth-for-the-mcp-server).
2. **Otherwise** (REST API, SDK, CI runner, headless MCP client) → [API key](#api-key).

If your MCP client can only register itself with dynamic client registration, use an API key. Adaption does not support dynamic client registration.

## Step 3: Register

The user signs in or creates an account at `https://adaptionlabs.ai/app/auth`. You cannot do this step for them.

### API key

Ask the user to create a key:

1. Sign in at `https://adaptionlabs.ai/app/auth`.
2. Open **Settings → API keys**: `https://adaptionlabs.ai/app/settings?tab=api_keys`.
3. Create a key and copy it. It is shown once. Keys start with `pt_live_`.

Ask the user to store the key in a secret manager or in the `ADAPTION_API_KEY` environment variable. Do not write it into source control or chat logs.

Keys created in the app have full access, including the MCP server. A key created with an explicit scope list needs `adaption-mcp:read` to read data and `adaption-mcp:write` to call MCP tools that create datasets or launch jobs.

### OAuth for the MCP server

The authorization server supports:

- Authorization code grant with PKCE. The only code challenge method is `S256`.
- Refresh token grant. Each refresh returns a new refresh token and revokes the old one.
- Resource indicators (RFC 8707). If you send `resource`, it must be the MCP server URL or the API origin.
- The `iss` parameter in the authorization response.

Endpoints:

- Authorization: `https://api.prod.adaptionlabs.ai/api/v1/oauth/authorize`
- Token: `https://api.prod.adaptionlabs.ai/api/v1/oauth/token`
- Revocation: `https://api.prod.adaptionlabs.ai/api/v1/oauth/revoke`

Identify your client with a [Client ID Metadata Document](https://datatracker.ietf.org/doc/draft-ietf-oauth-client-id-metadata-document/): your `client_id` is an HTTPS URL that serves your client metadata, including redirect URIs. Public clients authenticate to the token endpoint with `none` and PKCE. Redirect URIs must match exactly, except `http` loopback URIs on `localhost`, `127.0.0.1`, or `[::1]`, where the port is ignored.

Scopes:

- `adaption-mcp:read`: read datasets, evaluations, export links, models, and AutoScientist runs.
- `adaption-mcp:write`: create datasets and launch jobs that spend credits. Includes `adaption-mcp:read`.

On the consent screen, the user signs in to Adaption and chooses one organization. Tokens grant access to that organization only, and stop working when the user leaves it.

## Step 4: Use the credential

Send the API key or the OAuth access token as a bearer token:

```http
GET /api/v1/datasets
Host: api.prod.adaptionlabs.ai
Authorization: Bearer <API key or access token>
```

With the Python SDK:

```python
from adaption import Adaption

client = Adaption()  # reads ADAPTION_API_KEY
```

For MCP clients that use JSON configuration with an API key:

```json
{
  "mcpServers": {
    "adaption": {
      "url": "https://api.prod.adaptionlabs.ai/api/v1/mcp",
      "headers": { "Authorization": "Bearer YOUR_ADAPTION_API_KEY" }
    }
  }
}
```

## Step 5: Refresh

- An API key works until it expires or the user deletes it in **Settings → API keys**. Then ask the user for a new key.
- OAuth authorization codes expire after 5 minutes.
- OAuth access tokens expire after 1 hour. Use the refresh token grant at the token endpoint.
- OAuth refresh tokens expire after 30 days. After that, the user signs in again.

## Errors

OAuth endpoints use the error codes from RFC 6749.

| Code | Where | What to do |
| --- | --- | --- |
| `401` with `WWW-Authenticate` | MCP server | Missing or invalid token. Start at [Step 1](#step-1-discover). |
| `insufficient_scope` | MCP server | The token lacks a needed scope. Ask for `adaption-mcp:write`, or ask the user for a key with that scope. |
| `invalid_grant` | Token endpoint | Code or refresh token is expired, used, or revoked. Restart the authorization code flow. |
| `invalid_client` | Token endpoint | `client_id` not recognized, or its metadata document could not be fetched. |
| `invalid_target` | Authorize or token endpoint | `resource` is not the MCP server URL or the API origin. |
| `unsupported_grant_type` | Token endpoint | Use `authorization_code` or `refresh_token`. |
| `429` | Any | Too many requests. Wait and retry. |

## Revocation

- **OAuth tokens**: POST `token=<token>` to the revocation endpoint (RFC 7009). It always returns `200`.
- **API keys**: the user deletes the key in **Settings → API keys**.

Full docs: `https://docs.adaptionlabs.ai/oauth` and `https://docs.adaptionlabs.ai/introduction/create-api-keys`.
