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

# 签发 API token

> 创建长期 API token。

```http theme={null}
POST /api/v1/auth/tokens
```

创建形如 `ms_<prefix>_<secret>` 的长期 token。明文 token **仅返回一次**，请立即保存。

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST http://localhost:5080/api/v1/auth/tokens \
    -H "authorization: Bearer $MS_JWT" \
    -H 'content-type: application/json' \
    -d '{
      "name": "collector-production",
      "role_id": "<organization-role-id>",
      "expires_in_days": 90
    }'
  ```
</RequestExample>

`role_id` 可省略，默认使用组织的 API-token 默认角色。所选角色不能授予调用者原本不具备的权限。省略
`expires_in_days` 表示永不过期；显式值会限制在 1–1825 天。创建 token 需要
`api_tokens.manage`。

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "<token-id>",
    "prefix": "a1b2c3",
    "token": "ms_a1b2c3_d4e5f6g7h8i9...",
    "role_id": "<organization-role-id>",
    "role_key": "viewer",
    "role_name": "Viewer",
    "expires_at_micros": 1735689600000000,
    "created_at_micros": 1727913600000000
  }
  ```
</ResponseExample>
