指南 3个标注团队操作手册:提升标注速度与质量

访问令牌

Label Studio提供个人访问令牌和旧版令牌。用户可用的选项在组织级别设置。请参阅下方的组织访问设置

个人访问令牌 旧版令牌
  • 具有可在组织级别设置的TTL(仅限Label Studio Enterprise)
  • 对用户仅可见一次
  • 可手动撤销
  • 与HTTP API一起使用时需要额外步骤
  • 使用SDK时只需设置一次
  • 不会过期
  • 在您的账户设置中保持列出和可用
  • 可手动撤销
  • 与HTTP API一起使用时无需刷新
  • 使用SDK时只需设置一次

个人访问令牌与API

SDK

个人访问令牌可以像设置旧版令牌一样在Python SDK中使用:

# Define the URL where Label Studio is accessible and the API key for your user account
LABEL_STUDIO_URL = 'http://localhost:8080'
# API key is available at the Account & Settings > Access Tokens page in Label Studio UI
API_KEY = 'd6f8a2622d39e9d89ff0dfef1a80ad877f4ee9e3'

# Import the SDK and the client module
from label_studio_sdk.client import LabelStudio

# Connect to the Label Studio API and check the connection
ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=API_KEY)

HTTP API

如果您直接通过HTTP进行交互,个人访问令牌将作为JWT刷新令牌使用。

您必须使用个人访问令牌(刷新令牌)来生成短期有效的访问令牌。该访问令牌随后将用于API身份验证。

要生成此访问令牌,请在JSON请求体中使用您的个人访问令牌发起POST请求。例如:

curl -X POST <your-label-studio-url>/api/token/refresh \
-H "Content-Type: application/json" \
-d '{"refresh": "your-personal-access-token"}'

作为响应,您将收到类似以下的JSON数据:

{
    "access": "your-new-access-token"
}

在API请求中通过Authorization头部包含此访问令牌来使用它:

Authorization: Bearer your-new-access-token

当访问令牌过期后(约5分钟),您将收到401响应,需要再次使用个人访问令牌获取新的令牌。这增加了额外的安全层。

您还可以使用以下脚本检查令牌何时到期:

# pip install pyjwt
from datetime import datetime, timezone
import jwt

decoded = jwt.decode(token)
exp = decoded.get("exp")
token_is_expired = (exp <= datetime.now(timezone.utc).timestamp())

组织机构的访问令牌设置

用户可用的选项取决于组织级别所选的选项。

组织页面中,点击右上角的访问令牌设置

从这里您可以启用和禁用令牌类型。

  • 当某种令牌类型被禁用时,现有的令牌将无法验证登录Label Studio平台。

  • 使用个人访问令牌的有效期设置功能来为个人访问令牌设定过期日期。此功能仅适用于Label Studio Enterprise用户。

Screenshot of Access Token window

查找您的访问令牌

您可以在账户与设置页面创建/管理访问令牌(在Label Studio右上角点击您的用户名)。