OpenAI 为用户分配组织角色

2026-11-19 17:50 更新

为用户分配组织角色

post /organization/users/{user_id}/roles

为组织内的用户分配组织角色。

路径参数

  • user_id: string

要分配组织角色的用户 ID。

请求体参数

内容类型为 application/json。

  • role_id: string

要分配的角色 ID。

返回值

  • object: "user.role"

固定为 user.role。

  • "user.role"

  • role: Role

可通过公开 Roles API 分配的角色详情。

  • id: string

角色 ID。

  • description: string or null

角色的可选描述。

  • name: string

角色的唯一名称。

  • object: "role"

固定为 role。

  • "role"

  • permissions: array of string

角色授予的权限。

  • predefined_role: boolean

角色是否由 OpenAI 预定义并管理。

  • resource_type: string

角色绑定的资源类型,例如 api.organization 或 api.project。

  • user: OrganizationUser

表示组织内的一名用户。

  • id: string

可在 API 端点中引用的标识符。

  • added_at: integer

用户加入组织时的 Unix 时间戳,单位为秒。

format: unixtime

  • object: "organization.user"

对象类型,固定为 organization.user。

  • "organization.user"

  • api_key_last_used_at: optional integer or null

用户上次使用 API 密钥时的 Unix 时间戳,单位为秒。

format: unixtime

  • created: optional integer

用户创建时的 Unix 时间戳,单位为秒。

format: unixtime

  • developer_persona: optional string or null

用户的开发者画像元数据。

  • email: optional string or null

用户的电子邮件地址。

  • is_default: optional boolean

用户是否为组织的默认用户。

  • is_scale_tier_authorized_purchaser: optional boolean or null

用户是否为 Scale Tier 的授权购买者。

  • is_scim_managed: optional boolean

用户是否由 SCIM 管理。

  • is_service_account: optional boolean

用户是否为服务账户。

  • name: optional string or null

用户的姓名。

  • projects: optional object { data, object } or null

若响应包含此字段,则列出用户关联的项目。

  • data: array of object { id, name, role }

  • id: optional string or null

  • name: optional string or null

  • role: optional string or null

  • object: "list"

  • "list"

  • role: optional string or null

owner or reader

  • technical_level: optional string or null

用户的技术水平元数据。

  • user: optional object { id, object, banned, 5 more }

嵌套的用户详情。

  • id: string

  • object: "user"

  • "user"

  • banned: optional boolean or null

  • banned_at: optional integer or null

format: unixtime

  • email: optional string or null

  • enabled: optional boolean or null

  • name: optional string or null

  • picture: optional string or null

示例

## 从环境变量读取管理员密钥。确认要分配角色的用户和角色 ID
curl -X POST "https://api.openai.com/v1/organization/users/user_abc123/roles" \
  -H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "role_id": "role_01J1F8ROLE01"
  }'

响应示例

{
    "object": "user.role",
    "user": {
        "object": "organization.user",
        "id": "user_abc123",
        "name": "Ada Lovelace",
        "email": "ada@example.com",
        "role": "owner",
        "added_at": 1711470000
    },
    "role": {
        "object": "role",
        "id": "role_01J1F8ROLE01",
        "name": "API Group Manager",
        "description": "Allows managing organization groups",
        "permissions": [
            "api.groups.read",
            "api.groups.write"
        ],
        "resource_type": "api.organization",
        "predefined_role": false
    }
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号