> ## Documentation Index
> Fetch the complete documentation index at: https://weights.fyi/run/llms.txt

# POST /v1/tokens

```text
POST https://weights.fyi/run/v1/tokens
Authorization: Bearer <token>                    scope: manage
Content-Type: application/json
{"name": "...", "scopes": [...], "expires_at": "...", "daily_cap_usd": "..."}
```

**Available since:** 2026-10-08, when the service went live on weights.fyi/run. Implemented 2026-10-09: the cap holds training, and panel sessions expire.

**Answer time:** synchronous: the token is made and returned in the answer.

Makes an API token and returns it once: the service keeps only a digest and the visible prefix, so a lost answer means making another. The first token is made on your panel, [/app](/run/app); later ones there or with this call. A token can do what its scopes allow ([Start here](/run/docs/start.md#1-an-account-and-a-key)); without `scopes` it gets `submit` and `read`, and it can never get a scope the calling token lacks (`403 scope_escalation`), so a narrow token stays narrow.

New tokens are `weights_`, 43 random letters and digits, an underscore and a six-character checksum that lets a scanner recognise them; older `weights_` tokens of 43 characters stay valid. The call takes no `Idempotency-Key`: after a lost answer, list [GET /v1/tokens](/run/docs/reference/tokens-list.md) and revoke the token you never saw.

## Request

| Name | Where | Required | Meaning |
|---|---|---|---|
| `Authorization` | header | yes | `Bearer` and a token with `manage`; or a panel session sending its CSRF token in `X-CSRF-Token`, as the customer journey script does. A panel session ends 720 h after signing in or 10,080 minutes idle (merged 2026-10-09), then answers `401 unauthorized`; tokens do not end with it. |
| `Content-Type` | header | yes | `application/json`, at most 65,536 bytes. |
| `name` | body | no | A name of your choice, shown in lists. Without one the token is called `token`. |
| `scopes` | body | no | A list of `submit`, `read` and `manage`, at least one of them, each held by the token making the call. The default is `submit` and `read`. |
| `expires_at` | body | no | When the token stops working: ISO 8601 with a time zone, in the future, such as `2026-12-31T23:00:00Z`. Leave it out for no expiry. |
| `daily_cap_usd` | body | no | The spend cap per UTC day in US dollars, a string or number above zero such as `"25"` or `12.5`: new work that would pass it, counting today's charges and the waiting pages at their price, answers `402 token_daily_cap` until 00:00 UTC; since the merge of 2026-10-09 it also holds open training ([Prices and billing](/run/docs/prices.md#spend-caps-and-options)). Changeable later on the panel only. |

## Return value

**201 Created** with the new token.

| Field | Meaning |
|---|---|
| `id` | The token's number in your account, used to revoke it. |
| `token` | The token itself. It is shown in this answer only. |
| `prefix` | The token's first characters, as lists will show it. |
| `name` | The name it was given. |
| `scopes` | Its scopes, in alphabetical order. |
| `created_at` | When it was made. |
| `expires_at` | When it stops working, or `null`. |
| `daily_cap_usd_micros` | Its spend cap per UTC day in micro-dollars, or `null`. |
| `issued_by` | The person who issued it: the person behind the calling credential (the signed-in person, or the person who issued the calling token), or `null` when that credential names none. |
| `note` | A reminder that the token is shown once. |

## Errors

| Status | Code | When it happens | What to do |
|---|---|---|---|
| `400` | `invalid_body`, `invalid_json` | The body is not a JSON object. | Send an object, `{}` at the least. |
| `400` | `invalid_scopes`, `no_scopes`, `unknown_scope` | `scopes` is not a list of strings, is empty, or names a scope that does not exist. | Name some of `submit`, `read`, `manage`. |
| `400` | `invalid_expiry`, `expiry_needs_time_zone`, `expiry_in_the_past` | `expires_at` cannot be read, has no time zone, or is not in the future. | Send a future time with `Z` or an offset. |
| `400` | `invalid_amount` | `daily_cap_usd` is not an amount above zero. | Send dollars, such as `"25"`. |
| `400` | `invalid_name` | `name` is not a string. | Send text, or leave it out. |
| `401` | `unauthorized`, `invalid_token`, `token_revoked`, `token_expired` | No token, or one that does not work (any more). | Use a valid token. |
| `403` | `scope_required` | The calling token lacks `manage`. | Use a token with `manage`, or the panel. |
| `403` | `scope_escalation` | The new token would hold a scope the calling token does not; `asked` and `granted` list both. | Ask for less, or make it from a token or panel session that holds the scope. |
| `403` | `csrf_required` | A panel session made the call without `X-CSRF-Token`. | Send the panel's CSRF token, or use an API token. |
| `413` | `body_too_large` | The body is larger than `limit_bytes`. | Send only the fields above. |

## Examples

A batch runner that may send work and read results, capped at $25 a day (made on a test service; its checksum replaced with `x`):

```sh
curl -s https://weights.fyi/run/v1/tokens \
  -H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/json" \
  -d '{"name": "batch runner", "scopes": ["submit", "read"], "daily_cap_usd": "25"}'
```

```json
{
  "id": 2,
  "token": "weights_tcYQQluQhy9HxNfOiqWDGmzXAT2a3ryMNT43Ic6TWr3_xxxxxx",
  "prefix": "weights_tcYQQluQ",
  "name": "batch runner",
  "scopes": ["read", "submit"],
  "created_at": "2026-10-09T08:28:09.778Z",
  "expires_at": null,
  "daily_cap_usd_micros": 25000000,
  "issued_by": 12,
  "note": "The token is shown once. Keep it somewhere safe."
}
```

## Patterns

### One token per program

Give each program or person a token of its own with only the scopes it needs and a cap that fits its day; when one leaks, revoke it with [DELETE /v1/tokens/{token_id}](/run/docs/reference/tokens-revoke.md) and nothing else stops. Keep one `manage` token, ideally without `submit`, for making the others.

## History

- 2026-10-08: live with scopes, expiry, the daily cap and the rule that a token gives no more than it holds; checksummed tokens.
- 2026-10-09 (merged): the cap holds open training; panel sessions expire.
- 2026-11-16 (built, live with the deploy that carries it): `issued_by` in the answer.

## See also

[GET /v1/tokens](/run/docs/reference/tokens-list.md), [Errors and limits](/run/docs/errors.md#limits).
