> ## Documentation Index
> Fetch the complete documentation index at: https://docs.widgetic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Learn how to authenticate with the Widgetic API

The Widgetic API uses Bearer token authentication. Send an `Authorization` header with your API key or editor session token on every request, except the public embed routes, which take no key. There are two kinds of API key, an organisation key and a partner key: see [API keys](https://docs.widgetic.com/docs/api-keys.md) for which one you need.

## Authentication Methods

### API Keys (Server-Side)

API keys are the recommended authentication method for server-side applications. They give long-lived access: a key made in the dashboard works for ten years, or until you delete it.

```bash theme={"theme":"css-variables"}
Authorization: Bearer wdg_org_your_api_key_here
```

You make a key in the dashboard: open the workspace, then **Settings → API keys** (the owner of a workspace opens that page). A key you make there is a **workspace key**. It starts with `wdg_org_` (`wgt_prt_` in your partner's home workspace: see [API keys](https://docs.widgetic.com/docs/api-keys.md#what-makes-a-key-a-partner-key)), acts as that workspace and works in it only, and it does not follow the workspace you have open afterwards, so make one key for each workspace you work in. `GET /tokens/validate` says which workspace a key works in (`data.workspace`: its `id` and `name`).

A key can be limited to what its application needs, a build server for example: see [Limit what a key can do](#limit-what-a-key-can-do). Only a person signed in on widgetic.com can make a key (a key cannot make another key), and the workspace needs a paid plan to hold keys (the home workspace of a [partner](https://docs.widgetic.com/docs/partners/overview.md#partner-api-key) needs none: it pays by the invoices of its contract).

### Editor Sessions (For Customer Browsers)

To run Widgetic's editors inside your own page for one of your customers, mint a short-lived [editor session](https://docs.widgetic.com/docs/partners/editor-sessions.md) on your server and pass that session token to the browser.

```bash theme={"theme":"css-variables"}
Authorization: Bearer wgt_ses_your_editor_session_token_here
```

## API Key Types and Access Levels

Your API key prefix determines your role and what endpoints you can access. [API keys](https://docs.widgetic.com/docs/api-keys.md) puts the two kinds side by side, lists what each can call and shows how to check which one you hold:

| Key Prefix | Role | Access Level | Use Case |
| - | - | - | - |
| `wdg_org_` | Workspace | `user` | The key of a workspace, made in the dashboard: it acts as that workspace, in that workspace only |
| `wgt_prt_` | Partner | `partner` | White-label integrations: the key of your partner's home workspace, made by its owner in the dashboard like any other. It acts as your partner. Widgetic never makes or sends one |

## Understanding Access Levels

Each API endpoint specifies an `x-access-level` that determines which keys can call it:

* **`public`**: No key. These are the routes a visitor's browser calls to show a published widget (the [embed routes](https://docs.widgetic.com/docs/api/embedding.md)).
* **`user`**: An organisation key or a partner key.
* **`partner`**: A partner key (`wgt_prt_`), made in your partner's home workspace.

> [!NOTE]
>
> The `x-access-level` is a **role gate**, not a visibility gate. Every endpoint appears in the API reference, and your key decides which ones answer. A call with the wrong kind of key is refused with `403` and the code `AUTHZ_INSUFFICIENT_PERMISSIONS`. In the sidebar of the reference, an endpoint that needs a partner key carries a **Partner key** label. See [API keys](https://docs.widgetic.com/docs/api-keys.md#what-each-key-can-call) for the calls of each group.

## Limit What a Key Can Do

A key made without a limit has **full access**: it does everything its owner can, and so does every key made before limits existed. A key you put on a build server, or in a partner's backend, needs only the part of the API it uses. Limit it, and a leaked key can do no more than that.

You choose the limit when you make the key, in the dialog on **Settings → API keys**: Full access, Content, Read only or Custom, where you tick what the key may do. The names below are the ones the dialog shows. A limit is one preset or a list of scopes, never both:

| Preset | What the key may do |
| - | - |
| `read_only` | Looks at everything its owner holds and changes nothing. It holds `content:read`, `partner:read`, `billing:read` and `account:read`. |
| `content` | Builds and manages widgets and compositions, and runs the AI. It holds `content:read`, `content:write` and `generate`, and touches no billing, no people and no partners. |
| `full_access` | Everything its owner may do. A key made with neither a preset nor scopes is this. |

When a preset is not enough, name the scopes you want:

| Scope | What it lets a key do |
| - | - |
| `content:read` | Read widgets, compositions, canvases, projects, folders, uploads, translations and the analytics of your content. |
| `content:write` | Create, change, publish and delete the same. Includes `content:read`. |
| `generate` | Run the AI that builds widgets and compositions, and follow or cancel what it is doing. This spends credits. |
| `partner:read` | Read managed users, what they spent, presets, the contract and the storage destination (partners). |
| `partner:write` | Create, change and delete managed users and presets (partners). Includes `partner:read`. |
| `billing:read` | Read credits, usage, invoices, subscriptions and payment methods. |
| `billing:write` | Buy credits, pay invoices, change a subscription or a payment method. Includes `billing:read`. |
| `account:read` | Read the profile, organizations and members, allowed domains, notices, the names of API keys and the [Brand Kit](https://docs.widgetic.com/docs/partners/brand-kit.md). |
| `account:write` | Change the profile, organizations and members, allowed domains and integrations. Includes `account:read`. |

* **Writing includes reading.** Naming `content:write` gives `content:read` too, and the same goes for the other `write` scopes. A list that names every scope makes a key with full access.
* **Scopes only narrow.** A limited key still needs what its owner needs: the role, the plan and, for a [partner](https://docs.widgetic.com/docs/partners/account-status.md), an account in force.
* **The partner scopes (`partner:read`, `partner:write`) are for a partner's home workspace.** Only there is a key a partner key, so only there does the dialog offer them; in any other workspace they would open nothing.
* **The limit is fixed when the key is made.** To widen it, make a new key and delete the old one.
* **A limited key cannot make itself a bigger one.** No key can make a key: only a person signed in on widgetic.com can, and only that person can switch a key back on. A key with `account:read` can list the keys of its account, and renaming, switching off and deleting them needs full access.
* **Changing the Brand Kit needs full access**, because a change reshapes every widget the account makes from then on. A key with `account:read` may look at it. See [Brand Kit](https://docs.widgetic.com/docs/partners/brand-kit.md).
* **The MCP server needs full access.** `https://mcp.widgetic.com` hands an assistant every tool your account has, so only a key made with full access opens it, and a limited key is refused with `403`. See [Authentication for AI assistants](https://docs.widgetic.com/docs/agents/authentication.md#api-keys).
* **A partner's backend needs three scopes to start an editor session** for a managed user: `partner:write`, `content:write` and `generate` together. See [Editor Sessions](https://docs.widgetic.com/docs/partners/editor-sessions.md#make-a-session).
* **Moving an item to another managed user needs two scopes**: `partner:write` and `content:write`. See [Moving Content to Another Managed User](https://docs.widgetic.com/docs/partners/managed-users.md#moving-content-to-another-managed-user).

A request outside the scopes of the key is refused with `403` and the code `API_KEY_SCOPE_MISSING`. `error.details.missingScopes` lists what a new key needs, and `error.details.fullAccessRequired` is `true` when no list of scopes would have been enough:

```json theme={"theme":"css-variables"}
{
  "success": false,
  "error": {
    "code": "API_KEY_SCOPE_MISSING",
    "message": "This API key may not do this: it lacks the content:write scope (it holds content:read, partner:read, billing:read, account:read). The scopes of a key cannot be changed once it is made, so make a new key that includes them.",
    "details": {
      "missingScopes": ["content:write"],
      "fullAccessRequired": false
    }
  }
}
```

> [!NOTE]
>
> These scopes belong to the key and last as long as it does. To give a customer's browser limited, short-lived access to only that customer's content, mint an [editor session](https://docs.widgetic.com/docs/partners/editor-sessions.md) on your server instead.

## Keys and your workspace plan

A key is a credential for a paying workspace, so it follows the plan of the workspace it was made for. One rule covers the REST API, the [CLI](https://docs.widgetic.com/docs/cli/getting-started.md) and the [MCP server](https://docs.widgetic.com/docs/agents/authentication.md): none of them lets a key in that another one refuses.

| The workspace is... | A request made with its key gets |
| - | - |
| On a paid plan, or paying late inside its grace period | The answer. |
| In its free trial | `403` `AUTHZ_PLAN_RESTRICTION`: the free trial does not include the API, the CLI or the MCP server. A key cannot be made yet either. Choose a plan to use them. |
| Without a plan: the trial ended, the plan was cancelled, the payment failed for good, or it never had one | `403` `WORKSPACE_LOCKED`. Your work is kept for 90 days, and a plan unlocks it. |
| On a plan whose payment is overdue beyond the grace period | `403` `AUTHZ_PLAN_RESTRICTION`: update billing to restore it. |
| Deleted | Its keys are deleted with it, and so are the connections of AI assistants made for it. They stop working within a minute. |

A key of a workspace that has lapsed is switched off, **not deleted**. Choose a plan (or update billing) and the same key works again within about a minute, with nothing to make again. Only the workspace's own plan counts: another workspace of the same person, paid or not, neither unlocks it nor locks it.

> [!NOTE]
>
> An assistant connected through the MCP server is told in another way once its workspace has no plan: the connection is accepted, and each tool answers with the plan's words instead of doing the work. Only `get_profile`, and the tools that follow or cancel a build that started while the plan was active, answer. See [When the workspace has no plan](https://docs.widgetic.com/docs/agents/authentication.md#when-the-workspace-has-no-plan). The CLI exits with code `3` when the REST API refuses a key for its plan, and with `5` when an MCP tool does.

## Validating Tokens

You can validate a token to check its status and associated permissions:

```bash theme={"theme":"css-variables"}
curl -X GET "https://api.widgetic.com/v1/tokens/validate" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

Response:

```json theme={"theme":"css-variables"}
{
  "success": true,
  "data": {
    "valid": true,
    "tokenType": "api_key",
    "scopes": ["content:read", "content:write"],
    "userId": "123e4567-e89b-12d3-a456-426614174000",
    "expiresAt": null,
    "workspace": { "id": "5f1c1a6e-2f0c-4f3a-9d0f-6a2a3a1c9b7e", "name": "Studio" }
  }
}
```

`workspace` is the workspace the key works in. It is `null` for a credential that names none, such as a signed-in session. The answer does not say whether the key acts as a partner: for that, see [Check which key you hold](https://docs.widgetic.com/docs/api-keys.md#check-which-key-you-hold).

## Best Practices

> [accordion] Keep API Keys Secure
>
> * Never expose API keys in client-side code
> * Use environment variables to store keys
> * Rotate keys periodically
> * Use the token exchange flow for browser applications

> [accordion] Use Appropriate Key Types
>
> * Make one workspace key (`wdg_org_`) for each workspace you work in, and one for each application
> * Limit a key to what its application needs: Read only for a report, Content for a build server
> * For a partner integration, make the key in your partner's home workspace: it is a partner key (`wgt_prt_`) and acts as your partner. Make one for each integration (the checkout server, the support tool), named after it, so that you can switch off or delete one without touching the others

> [accordion] Handle Token Expiration
>
> * JWT tokens expire after a set period
> * Implement token refresh logic in your application
> * Use the SDK's async token provider for automatic handling

## Error Responses

When authentication fails, you'll receive one of these responses:

| Status | Code | Description |
| - | - | - |
| 401 | `AUTH_TOKEN_INVALID` | No key, or one that is not valid: mistyped, deleted or switched off |
| 403 | `AUTHZ_INSUFFICIENT_PERMISSIONS` | The key is valid, but this endpoint needs another kind of key, such as a partner key. See [API keys](https://docs.widgetic.com/docs/api-keys.md#when-a-call-is-refused) |
| 403 | `API_KEY_SCOPE_MISSING` | The key was limited when it was made, and this call is outside the limit. See [Limit what a key can do](#limit-what-a-key-can-do) |
| 403 | `WORKSPACE_LOCKED` | The key is valid, but its workspace has no plan. [Choose a plan](#keys-and-your-workspace-plan) and the same key works again |
| 403 | `AUTHZ_PLAN_RESTRICTION` | The key is valid, but its workspace's plan does not include this: it is in its free trial, or its payment is overdue |

Example error response:

```json theme={"theme":"css-variables"}
{
  "success": false,
  "error": {
    "code": "AUTHZ_INSUFFICIENT_PERMISSIONS",
    "message": "Insufficient permissions for this endpoint",
    "correlationId": "req_123e4567-e89b-12d3-a456-426614174000"
  }
}
```

## Next Steps

> [card] [Partner Authentication](https://docs.widgetic.com/docs/partners/overview.md)
>
> Learn about partner-specific authentication flows

> [card] [API Reference](https://docs.widgetic.com/api-reference/introduction.md)
>
> Explore all available endpoints


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.