# Create a token

Source: https://langbot.ai/docs/api/account/create-token

`POST /v1/tokens`

Create an API token. The token is shown once.

**Auth.** An API token: `Authorization: Bearer lb_…` ([create one](https://langbot.ai/app/tokens)). Signed-in web sessions work too.

**Limits.** Each token counts toward your plan's API tokens (5, 20 or 100).

## Parameters

### Body

| Name | Type | Required | Description |
|---|---|---|---|
| `name` | string | no | A name you will recognise, for example `laptop`. Default `default`. |
| `scopes` | array of string | no | Scopes; default `read`, `stream` and `subscribe`. |
| `agent` | object | no | The agent this token belongs to, `{name, version}`; deliveries and attestations then carry it. |

## Request

**curl**

```bash
curl -X POST "https://api.langbot.ai/v1/tokens" \
  -H "Authorization: Bearer $LANGBOT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "laptop", "agent": {"name": "mention-sniper", "version": "1.4.0"}}'
```

**Python**

```python
from langbot import LangbotClient

async with LangbotClient() as lb:  # reads LANGBOT_API_TOKEN
    token = await lb.create_token("laptop")  # the lb_… string
```

**TypeScript**

```ts
import { LangbotClient } from "@langbotai/sdk";

const lb = new LangbotClient(); // reads LANGBOT_API_TOKEN
const token = await lb.createToken("laptop");
console.log(token.id);
```

## Response

`201 Created`

```json
{ "id": "tok_01J9…", "name": "laptop", "scopes": ["read", "stream", "subscribe"], "agent": { "name": "mention-sniper", "version": "1.4.0" }, "created_at": 1760050000000, "last_used_at": null, "token": "lb_…" }
```

## Errors

| Status | `code` | When |
|---|---|---|
| 401 | `auth_required` | No token was sent. |
| 401 | `token_invalid` | The token was not recognised (mistyped, revoked or expired). |
| 422 | `validation_error` | A parameter failed validation; `detail[].loc` names it. |
| 402 | `quota_exceeded` | Your plan's API tokens are all in use; revoke one or move up a plan. |
| 429 | `rate_limited` | Over your request budget; wait `Retry-After` seconds. |

Every error body is `{"detail": …, "code": "…"}`; branch on `code`. All codes: [Errors](https://langbot.ai/docs/api#errors).
