OpenAI 列出项目 API 密钥
列出项目 API 密钥
get /organization/projects/{project_id}/api_keys
返回项目中的 API 密钥列表。
路径参数
project_id: string
项目 ID。
查询参数
after: optional string
分页游标。after 是标记列表位置的对象 ID。例如,列表请求返回100个对象,最后一个为 obj_foo;后续调用可传入 after=obj_foo,以获取下一页。
limit: optional integer (default: 20)
返回的对象数量上限。取值范围为1至100,默认值为20。
owner_project_access: optional "active" or "inactive" or "any"
按所有者当前是否对项目具有有效访问权限筛选 API 密钥。active 表示所有者有访问权限,inactive 表示所有者没有访问权限,any 表示所有已启用的项目 API 密钥。省略时,端点采用现有的基于成员身份的可见性规则,可能排除部分已启用的密钥。
"active"
"inactive"
"any"
返回值
data: array of ProjectAPIKey
id: string
标识符,可在 API 端点中引用。
created_at: integer
API 密钥创建时间的 Unix 时间戳,单位为秒。
format: unixtime
last_used_at: integer or null
API 密钥上次使用时间的 Unix 时间戳,单位为秒。
format: unixtime
name: string
API 密钥名称。
object: "organization.project.api_key"
对象类型,固定为 organization.project.api_key。
"organization.project.api_key"
owner: object { service_account, type, user }
service_account: optional object { id, created_at, name, role }
拥有项目 API 密钥的服务账户。
id: string
标识符,可在 API 端点中引用。
created_at: integer
服务账户创建时间的 Unix 时间戳,单位为秒。
format: unixtime
name: string
服务账户名称。
role: string
服务账户的项目角色。
type: optional "user" or "service_account"
user(用户)或 service_account(服务账户)。
"user"
"service_account"
user: optional object { id, created_at, email, 2 more }
拥有项目 API 密钥的用户。
id: string
标识符,可在 API 端点中引用。
created_at: integer
用户创建时间的 Unix 时间戳,单位为秒。
format: unixtime
email: string
用户的电子邮件地址。
name: string
用户名称。
role: string
用户的项目角色。
owner_project_access: "active" or "inactive"
API 密钥所有者当前是否对项目具有有效访问权限。
"active"
"inactive"
redacted_value: string
经过遮蔽的 API 密钥值。
expires_at: optional integer or null
API 密钥过期时间的 Unix 时间戳,单位为秒;不过期时为 null。
format: unixtime
has_more: boolean
object: "list"
"list"
first_id: optional string or null
last_id: optional string or null
示例
## 从环境变量读取管理员密钥;先把项目、资源 ID 和请求参数替换为实际值
curl "https://api.openai.com/v1/organization/projects/$PROJECT_ID/api_keys" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY"
200 — 示例
{
"data": [
{
"id": "id",
"created_at": 0,
"last_used_at": 0,
"name": "示例名称",
"object": "organization.project.api_key",
"owner": {
"service_account": {
"id": "id",
"created_at": 0,
"name": "示例名称",
"role": "role"
},
"type": "user",
"user": {
"id": "id",
"created_at": 0,
"email": "email",
"name": "示例名称",
"role": "role"
}
},
"owner_project_access": "active",
"redacted_value": "redacted_value",
"expires_at": 0
}
],
"has_more": true,
"object": "list",
"first_id": "first_id",
"last_id": "last_id"
}
示例
## 从环境变量读取管理员密钥;先把项目、资源 ID 和请求参数替换为实际值
curl "https://api.openai.com/v1/organization/projects/proj_abc/api_keys?after=key_abc&limit=20&owner_project_access=any" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
-H "Content-Type: application/json"
响应示例
{
"object": "list",
"data": [
{
"object": "organization.project.api_key",
"redacted_value": "sk-abc...def",
"name": "我的 API 密钥",
"created_at": 1711471533,
"last_used_at": 1711471534,
"id": "key_abc",
"owner_project_access": "active",
"owner": {
"type": "user",
"user": {
"id": "user_abc",
"name": "示例用户",
"email": "user@example.com",
"role": "owner",
"created_at": 1711471533
}
}
}
],
"first_id": "key_abc",
"last_id": "key_xyz",
"has_more": false
}
TRAE-AI编程


更多建议: