# Create an API token for an agent with the owner's passkey (or an emailed code); its value is shown once and every owner is emailed

`POST` `/api/v1/workspaces/{workspace}/tokens`

`createToken`

Who can call it: A signed-in owner of this workspace (session cookie). API tokens are always refused (owner_session_required), whatever their scopes. Refused (402 workspace_inactive) once the workspace's plan has lapsed.

**Scopes:** None. A person session is required; API tokens are refused.

The value is shown only once. This placeholder is not a credential; drafts scope manages future schedules; no token scope grants approval or immediate-posting authority. Add expires_in_days for a token that stops working by itself. Every owner is emailed. Illustrative WebAuthn JSON only: these placeholders cannot authenticate or authorize anything. Only the owner, interacting with their passkey in the product's browser ceremony, can produce the response to the matching fresh challenge. API tokens and agents can manage future schedules, but cannot approve, post immediately or start a waiting job.

**Parameters**

| Name | In | Required | Type and constraints | Description / example |
| --- | --- | --- | --- | --- |
| `workspace` | path | Yes | `string`; pattern: `"^ws_[a-z0-9]{16}$"` |  Example: `"ws_aaaaaaaaaaaaaaaa"` |

**JSON body**

| Field | Required | Type and constraints | Description |
| --- | --- | --- | --- |
| `name` | Yes | `string`; minLength: `1`; maxLength: `80` |  |
| `scopes` | Yes | array of `string`; enum: `["read","drafts","media","request-approval","cancel","connections","billing","webhooks","calendar","inbox"]`; minItems: `1` | request-approval and drafts can schedule posts. No scope can approve, post right now or connect accounts. |
| `expires_in_days` | No | `integer`; minimum: `1`; maximum: `366` | The token stops working this many days from now. Omit it for one that never expires. |
| `challenge_id` | No | `string` |  |
| `response` | No | `object` | Your passkey's assertion over the challenge from startToken. |
| `proof_token` | No | `string` | Instead of challenge_id and response, for an account with no passkey: what verifying the emailed code (purpose token) returned. |

**Request example**

```http
POST https://app.flaghand.com/api/v1/workspaces/ws_aaaaaaaaaaaaaaaa/tokens
Cookie: <your person session cookie>
Origin: https://app.flaghand.com
Content-Type: application/json

{
  "name": "Drafting assistant",
  "scopes": [
    "read",
    "drafts",
    "media",
    "request-approval"
  ],
  "challenge_id": "chl_llllllllllllllll",
  "response": {
    "id": "<owner-passkey-credential-id>",
    "rawId": "<base64url-credential-id>",
    "type": "public-key",
    "response": {
      "authenticatorData": "<browser-generated-authenticator-data>",
      "clientDataJSON": "<browser-generated-client-data>",
      "signature": "<owner-passkey-signature>",
      "userHandle": null
    },
    "clientExtensionResults": {},
    "authenticatorAttachment": "platform"
  }
}
```

**Response example**

```json
{
  "id": "tkn_cccccccccccccccc",
  "name": "Drafting assistant",
  "prefix": "tok_syntheti",
  "scopes": [
    "read",
    "drafts",
    "media",
    "request-approval"
  ],
  "created_by": "usr_bbbbbbbbbbbbbbbb",
  "created_at": "2026-10-25T16:00:00Z",
  "last_used_at": null,
  "expires_at": null,
  "revoked_at": null,
  "oauth": null,
  "token": "tok_SYNTHETIC_DO_NOT_USE"
}
```

Success: HTTP 201. Content-Type: application/json.

**Errors:** `invalid_request` (400), `internal` (500), `unauthorized` (401), `invalid_token` (401), `session_expired` (401), `bad_origin` (403), `owner_session_required` (403), `invalid_json` (400), `not_found` (404), `workspace_inactive` (402), `step_up_required` (403), `passkey_failed` (403). See the [error codes](https://app.flaghand.com/docs/errors.md) for meanings and the shared default error response. Other domain errors from that catalog may apply; the response's code and message are authoritative.

**CLI:** `flaghand tokens create`

Discovery only: this command refuses API tokens. **MCP:** not exposed; this operation requires a person using a passkey in the desk. Agents must never perform the approval, scheduling or posting ceremony.

Base URL: `https://app.flaghand.com/api/v1`. Part of the [API reference](https://app.flaghand.com/docs/api.md); every error code is in [errors](https://app.flaghand.com/docs/errors.md).
