# Authentication & API keys

> Authenticate Shaw API and MCP requests with OAuth 2.1 PKCE tokens or scoped sk_ keys, configure plugin permissions, and handle 401-403 and 402 errors.

Shaw's REST API and Workspace MCP (`https://shaw.ai/mcp`) accept two credential
types. Both run with the signed-in user's workspace permissions and are narrowed
to the scopes granted when the credential was created.

|                  | API key                                                      | OAuth access token                                                    |
| ---------------- | ------------------------------------------------------------ | --------------------------------------------------------------------- |
| **Best for**     | Scripts, CI pipelines, GitHub Actions, headless MCP clients  | Claude, Claude Code, ChatGPT, Codex, and interactive tools            |
| **Created by**   | Signed-in user in [API keys](https://shaw.ai/app/developers) | User approving consent on [Shaw Connect](https://shaw.ai/app/connect) |
| **Token format** | `sk_` followed by 43 characters                              | `sat_...` access token (`srt_...` refresh token)                      |
| **Lifetime**     | 1 to 365 days (90 days default)                              | Access token 1 hour; refresh token 60 days, rotated on each use       |
| **Storage**      | SHA-256 hash only; secret shown once on creation             | Hashed in D1; revoking a grant takes effect immediately               |
| **Limits**       | 120 requests/min per key; up to 25 active keys per user      | 120 requests/min per grant                                            |

Send either credential in the `Authorization` header:

```http
Authorization: Bearer <credential>
```

## Active plugin & API scopes [#active-plugin--api-scopes]

Grant only the scopes your workflow requires. A write scope never implies its
read scope—select both when an integration reads and mutates state, and note
that scopes never widen a user's organization role.

| Scope             | What it allows                                                                                                                                                                                                                                                 |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `org:read`        | Read accessible organizations (`GET /api/me`), runtime status, and monthly credit balances (`GET /api/credits`)                                                                                                                                                |
| `pages:read`      | Search catalog metadata (`GET /api/templates/search`), inspect template credit cost (`GET /api/templates/detail/{id}`), unlock metered source (`POST /api/templates/use`), and read Brand Kits, remixes, hosted pages, custom domains, and Email Studio drafts |
| `pages:write`     | Update workspace Brand Kits, create or edit AI remixes (`POST /api/templates/remixes`), publish hosted landing pages and custom domains, publish to Shopify Pages, and save or publish Email Studio drafts                                                     |
| `connectors:read` | Inspect connected providers such as Shopify and Klaviyo (`GET /api/connections`) without exposing stored credentials                                                                                                                                           |

Additional scopes (`org:write`, `connectors:manage`, `files:read`,
`files:write`, `memory:read`, `memory:write`, `tools:read`, `tools:write`, and
`webhooks:manage`) can be selected when creating personal API keys for broader
automation workflows.

API keys can only be created or revoked from a signed-in browser session at
[shaw.ai/app/developers](https://shaw.ai/app/developers). Bearer credentials
cannot mint or revoke keys (`403 bearer_not_allowed`).

## OAuth 2.1 + PKCE on /app/connect [#oauth-21--pkce-on-appconnect]

Interactive AI clients connect to `https://shaw.ai/mcp` using standard OAuth 2.1
with mandatory `S256` PKCE and dynamic client registration (RFC 7591):

- **Authorization server discovery:**
  `https://shaw.ai/.well-known/oauth-authorization-server/api/auth`
- **Protected resource metadata:**
  `https://shaw.ai/.well-known/oauth-protected-resource/mcp`
- **Consent screen:** `https://shaw.ai/app/connect` (highlights `org:read`,
  `pages:read`, `pages:write`, and `connectors:read` by default and lets the
  user untick optional scopes before approving)
- **Organization selection:** Target a specific workspace by passing
  `X-Shaw-Tenant: <organization-id>` (or the MCP `tenant` field), or pin an API
  key to one organization at creation time.

## Error responses [#error-responses]

API and MCP HTTP errors return structured JSON with a machine-readable `error`
(or `code` for credit errors) field:

| HTTP status                                            | Error code                | Meaning                                                                                                                                                     |
| ------------------------------------------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <StatusBadge code={401} label="Unauthorized" />        | `invalid_token`           | Missing, malformed, expired, or revoked credential (`WWW-Authenticate` includes `resource_metadata`)                                                        |
| <StatusBadge code={402} label="Payment Required" />    | `INSUFFICIENT_CREDITS`    | Requested template exceeds remaining monthly credits; payload includes `"You need more credits"`, `requiredCredits`, `remainingCredits`, and `upgradeUrl`   |
| <StatusBadge code={403} label="Forbidden" />           | `insufficient_scope`      | Credential lacks the required scope (named in `WWW-Authenticate`)                                                                                           |
| <StatusBadge code={403} label="Forbidden" />           | `bearer_not_allowed`      | Session-only route such as key management, `/api/templates/zip/*`, `/api/templates/ticket`, `/api/templates/remixes/*/view`, or `/api/builder/pages/export` |
| <StatusBadge code={403} label="Forbidden" />           | `tenant_pinned`           | API key is pinned to a different organization than `X-Shaw-Tenant`                                                                                          |
| <StatusBadge code={403} label="Forbidden" />           | `forbidden_workspace`     | Authenticated user does not belong to the requested organization                                                                                            |
| <StatusBadge code={429} label="Too Many Requests" />   | `rate_limited`            | Exceeded 120 requests/min per credential; wait `Retry-After` seconds                                                                                        |
| <StatusBadge code={503} label="Service Unavailable" /> | `temporarily_unavailable` | Transient upstream verification error; retry after `Retry-After` seconds                                                                                    |

See [Monthly credits](/developers/credits) for `402` retry guidance,
or browse the [Organization API Reference](/api-reference/organization) and
[Connections API Reference](/api-reference/connections).

