OpenAI 列出组织与项目API密钥

2026-11-13 10:27 更新

列出所有组织和项目 API 密钥

get /organization/admin_api_keys

列出组织 API 密钥。

译注:官方标题提到“组织和项目 API 密钥”,正文说明为“组织 API 密钥”,返回结构为 AdminAPIKey,object 为 organization.admin_api_key。此处按原文保留,不据标题推断接口保证列出全部项目密钥。

查询参数

  • after: optional string or null

按分页顺序,返回 ID 位于此 ID 之后的密钥。

  • limit: optional integer (default: 20)

返回的密钥数量上限。

  • order: optional "asc" or "desc" (default: "asc")

按创建时间升序或降序排列结果。

  • "asc"

  • "desc"

返回值

译注:本节按官方字段说明保留 owner.object、owner.role、owner.type 的描述。官方列表页另一个响应示例使用 organization.service_account、member、service_account,与这些描述存在口径差异;不能据此将服务账户改写为用户,或将角色强制改为 owner。示例与协议值均保留原样。

  • data: array of AdminAPIKey

  • id: string

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

  • created_at: integer

API 密钥创建时的 Unix 时间戳,单位为秒。

format: unixtime

  • expires_at: integer or null

API 密钥过期时的 Unix 时间戳,单位为秒。

format: unixtime

  • object: "organization.admin_api_key"

对象类型,始终为 organization.admin_api_key。

  • "organization.admin_api_key"

  • owner: object { id, created_at, name, 3 more }

  • id: optional string

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

  • created_at: optional integer

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

format: unixtime

  • name: optional string

用户的名称。

  • object: optional string

对象类型,始终为 organization.user。

  • role: optional string

始终为 owner。

  • type: optional string

始终为 user。

  • redacted_value: string

API 密钥经遮蔽处理后的值。

  • last_used_at: optional integer or null

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

format: unixtime

  • name: optional string or null

API 密钥的名称。

  • has_more: boolean

  • object: "list"

  • "list"

  • first_id: optional string or null

  • last_id: optional string or null

示例

## 从环境变量 OPENAI_ADMIN_KEY 读取管理员密钥;运行前替换示例密钥 ID 和名称。
curl https://api.openai.com/v1/organization/admin_api_keys \
    -H "Authorization: Bearer $OPENAI_ADMIN_KEY"

200:示例

{
  "data": [
    {
      "id": "key_abc",
      "created_at": 1711471533,
      "expires_at": 1714063533,
      "object": "organization.admin_api_key",
      "owner": {
        "id": "sa_456",
        "created_at": 1711471533,
        "name": "示例服务账户",
        "object": "organization.user",
        "role": "owner",
        "type": "user"
      },
      "redacted_value": "sk-admin...def",
      "last_used_at": 1711471534,
      "name": "管理员密钥"
    }
  ],
  "has_more": false,
  "object": "list",
  "first_id": "key_abc",
  "last_id": "key_xyz"
}

示例

说明:下例为含查询参数的完整 URL 加上引号,避免 Shell 将 & 解释为后台运行符;这是对原文示例的可执行性修正。

## 从环境变量 OPENAI_ADMIN_KEY 读取管理员密钥;运行前替换示例密钥 ID 和名称。
curl 'https://api.openai.com/v1/organization/admin_api_keys?after=key_abc&limit=20' \
  -H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
  -H "Content-Type: application/json"

响应示例

{
  "object": "list",
  "data": [
    {
      "object": "organization.admin_api_key",
      "id": "key_abc",
      "name": "主要管理员密钥",
      "redacted_value": "sk-admin...def",
      "created_at": 1711471533,
      "expires_at": 1714063533,
      "last_used_at": 1711471534,
      "owner": {
        "type": "service_account",
        "object": "organization.service_account",
        "id": "sa_456",
        "name": "示例服务账户",
        "created_at": 1711471533,
        "role": "member"
      }
    }
  ],
  "first_id": "key_abc",
  "last_id": "key_abc",
  "has_more": false
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号