API 密钥
获取 API 密钥
get /v1/organizations/api_keys/{api_key_id}
获取 API 密钥
路径参数
-
api_key_id: stringAPI 密钥的 ID。
返回值
-
APIKey object { id, created_at, created_by, 6 more }-
id: stringAPI 密钥的 ID。
-
created_at: stringRFC 3339 日期时间字符串,表示 API 密钥的创建时间。
-
created_by: object { id, type }创建该 API 密钥的操作者的 ID 和类型。
-
id: string创建该对象的操作者的 ID。
-
type: string创建该对象的操作者的类型。
-
-
expires_at: stringRFC 3339 日期时间字符串,表示 API 密钥的过期时间,如果永不过期则为
null。 -
name: stringAPI 密钥的名称。
-
partial_key_hint: stringAPI 密钥的部分脱敏提示。
-
status: "active" or "inactive" or "archived" or "expired"API 密钥的状态。
-
"active" -
"inactive" -
"archived" -
"expired"
-
-
type: "api_key"对象类型。
对于 API 密钥,此值始终为
"api_key"。"api_key"
-
workspace_id: string与 API 密钥关联的工作区 ID,如果 API 密钥属于默认工作区则为
null。
-
示例
curl https://api.anthropic.com/v1/organizations/api_keys/$API_KEY_ID \
-H 'anthropic-version: 2023-06-01' \
-H "X-Api-Key: $ANTHROPIC_ADMIN_API_KEY"
响应
{
"id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
"created_at": "2024-10-30T23:58:27.427722Z",
"created_by": {
"id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
"type": "user"
},
"expires_at": "2024-10-30T23:58:27.427722Z",
"name": "Developer Key",
"partial_key_hint": "sk-ant-api03-R2D...igAA",
"status": "active",
"type": "api_key",
"workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
}
列出 API 密钥
get /v1/organizations/api_keys
列出 API 密钥
查询参数
-
after_id: optional string用作分页游标的对象 ID。提供后,返回该对象之后的结果页。
-
before_id: optional string用作分页游标的对象 ID。提供后,返回该对象之前的结果页。
-
created_by_user_id: optional string按创建对象的用户 ID 进行筛选。
-
limit: optional number每页返回的项目数量。
默认为
20。范围为1到1000。 -
status: optional "active" or "inactive" or "archived" or "expired"按 API 密钥状态进行筛选。
-
"active" -
"inactive" -
"archived" -
"expired"
-
-
workspace_id: optional string按工作区 ID 进行筛选。
返回值
-
data: array of APIKey-
id: stringAPI 密钥的 ID。
-
created_at: stringRFC 3339 日期时间字符串,表示 API 密钥的创建时间。
-
created_by: object { id, type }创建该 API 密钥的操作者的 ID 和类型。
-
id: string创建该对象的操作者的 ID。
-
type: string创建该对象的操作者的类型。
-
-
expires_at: stringRFC 3339 日期时间字符串,表示 API 密钥的过期时间,如果永不过期则为
null。 -
name: stringAPI 密钥的名称。
-
partial_key_hint: stringAPI 密钥的部分脱敏提示。
-
status: "active" or "inactive" or "archived" or "expired"API 密钥的状态。
-
"active" -
"inactive" -
"archived" -
"expired"
-
-
type: "api_key"对象类型。
对于 API 密钥,此值始终为
"api_key"。"api_key"
-
workspace_id: string与 API 密钥关联的工作区 ID,如果 API 密钥属于默认工作区则为
null。
-
-
first_id: stringdata列表中的第一个 ID。可用作上一页的before_id。 -
has_more: boolean指示在请求的页面方向上是否还有更多结果。
-
last_id: stringdata列表中的最后一个 ID。可用作下一页的after_id。
示例
curl https://api.anthropic.com/v1/organizations/api_keys \
-H 'anthropic-version: 2023-06-01' \
-H "X-Api-Key: $ANTHROPIC_ADMIN_API_KEY"
响应
{
"data": [
{
"id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
"created_at": "2024-10-30T23:58:27.427722Z",
"created_by": {
"id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
"type": "user"
},
"expires_at": "2024-10-30T23:58:27.427722Z",
"name": "Developer Key",
"partial_key_hint": "sk-ant-api03-R2D...igAA",
"status": "active",
"type": "api_key",
"workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
}
],
"first_id": "first_id",
"has_more": true,
"last_id": "last_id"
}
更新 API 密钥
post /v1/organizations/api_keys/{api_key_id}
更新 API 密钥
路径参数
-
api_key_id: stringAPI 密钥的 ID。
请求体参数
-
name: optional stringAPI 密钥的名称。
-
status: optional "active" or "inactive" or "archived"API 密钥的状态。
-
"active" -
"inactive" -
"archived"
-
返回值
-
APIKey object { id, created_at, created_by, 6 more }-
id: stringAPI 密钥的 ID。
-
created_at: stringRFC 3339 日期时间字符串,表示 API 密钥的创建时间。
-
created_by: object { id, type }创建该 API 密钥的操作者的 ID 和类型。
-
id: string创建该对象的操作者的 ID。
-
type: string创建该对象的操作者的类型。
-
-
expires_at: stringRFC 3339 日期时间字符串,表示 API 密钥的过期时间,如果永不过期则为
null。 -
name: stringAPI 密钥的名称。
-
partial_key_hint: stringAPI 密钥的部分脱敏提示。
-
status: "active" or "inactive" or "archived" or "expired"API 密钥的状态。
-
"active" -
"inactive" -
"archived" -
"expired"
-
-
type: "api_key"对象类型。
对于 API 密钥,此值始终为
"api_key"。"api_key"
-
workspace_id: string与 API 密钥关联的工作区 ID,如果 API 密钥属于默认工作区则为
null。
-
示例
curl https://api.anthropic.com/v1/organizations/api_keys/$API_KEY_ID \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-H "X-Api-Key: $ANTHROPIC_ADMIN_API_KEY" \
-d '{}'
响应
{
"id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
"created_at": "2024-10-30T23:58:27.427722Z",
"created_by": {
"id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
"type": "user"
},
"expires_at": "2024-10-30T23:58:27.427722Z",
"name": "Developer Key",
"partial_key_hint": "sk-ant-api03-R2D...igAA",
"status": "active",
"type": "api_key",
"workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
}