# CrabTalk auth.md

How an AI agent gets credentials for CrabTalk. Every method here ends with a person approving the agent: an agent cannot create a CrabTalk account or credentials on its own. The person signs in to CrabTalk with Google or GitHub.

## Who this is for

Agents that call CrabTalk services (their tools and workflows) or manage a person's CrabTalk account on their behalf: deploying services, reading usage, creating keys.

## Methods

### 1. MCP connection (OAuth 2.1)

For agents whose host supports remote MCP.

- Resource: <https://mcp.crabtalk.ai>
- Protected resource metadata: <https://mcp.crabtalk.ai/.well-known/oauth-protected-resource>
- Authorization server metadata: <https://mcp.crabtalk.ai/.well-known/oauth-authorization-server>
- Client registration: dynamic, POST <https://mcp.crabtalk.ai/auth/register> with `client_name` and `redirect_uris` (each `https`, or `http` on a loopback host). Public clients; no client secret.
- Grant: authorization code with PKCE (`S256`). GET <https://mcp.crabtalk.ai/auth/authorize> sends the person to CrabTalk to approve the connection's name, account, permissions and daily budget. POST <https://mcp.crabtalk.ai/auth/token> exchanges the code.
- Scope: `mcp`, the only one. The person chooses the connection's permissions and budget when approving, whatever scope the client asks for.

The token is an API key (`ck_…`) dedicated to that connection. Setup per client: https://crabtalk.ai/docs/guides/mcp.md

### 2. Auth.md service registration (`service_auth`)

For agents that can make HTTP requests and ask a person to approve access. Discover the endpoints in `agent_auth` and `token_endpoint` in the [authorization server metadata](https://mcp.crabtalk.ai/.well-known/oauth-authorization-server).

1. POST JSON `{"type":"service_auth","client_name":"Research agent"}` to `identity_endpoint`. The name must be 1 to 100 characters after trimming and pre-fills **Connection name** on the approval page. Keep `claim_token` private. The registration, approval code and claim token share a 30-minute lifetime.
2. Send the person `claim.verification_uri` and `claim.user_code`. They enter the code on CrabTalk, sign in, and review the account, permissions and daily budget before approving.
3. POST to `token_endpoint` as `application/x-www-form-urlencoded` with `grant_type=urn:workos:agent-auth:grant-type:claim` and `claim_token`. Wait `claim.interval` seconds between polls while you get `authorization_pending`. Increase the wait by at least five seconds on `slow_down`. If you get `expired_token` before receiving a key, start a new registration.
4. After approval, save `access_token` as the agent's API key (`ck_…`) and discard the claim token. The server returns the key once.

While approval is pending, POST JSON `{"claim_token":"…"}` to `claim_endpoint` to retrieve the current approval details. The response has the same fields as the registration's `claim` block, with `expires_in` counting the seconds remaining. Start a new registration on `expired_token`. An unknown claim token returns HTTP 401.

### 3. CLI device sign-in

For agents with a shell.

1. Install the open-source CLI: `curl -fsSL https://crabtalk.ai/install.sh | sh`
2. Run `crab login --device`. It prints an approval link and a code. Send both to the person and keep the command running while they approve. The code lasts 30 minutes.
3. Run `crab --context cloud status` and confirm it shows the intended account.

The approved credential is an API key dedicated to the agent, requesting the standard read permissions and a $5 daily budget by default; the person can change both when approving. Steps: https://crabtalk.ai/docs/guides/contexts.md#agent-setup

### 4. API key from the person

A person can create a key under Settings → Access → API Keys or with `crab key create <label>`, and give it to the agent. See https://crabtalk.ai/docs/guides/keys.md

## Using a credential

Send the key as a bearer token:

```http
Authorization: Bearer ck_…
```

- MCP: <https://mcp.crabtalk.ai>, with the token the connection obtained.
- HTTP API: <https://api.crabtalk.ai>. Schema: https://api.crabtalk.ai/openapi.json
- CLI: `crab` stores the key in its context and sends it.

A key acts as the person who approved it, on the account it belongs to, within its permissions. Priced tools charge that account and stop at the key's daily budget. A missing, invalid, revoked or expired key gets `401`. Keys are listed, and revoked, under Settings → Access → API Keys.

More: https://crabtalk.ai/docs/reference/authentication.md and https://crabtalk.ai/docs/reference/permissions.md
