ToAPIsToAPIs
API Key

获取 API Key 详情

读取自有普通模型 Key 的元数据

GET
/api/v1/api-keys/{api_key_id}

国内用户请注意: 中国大陆用户请使用 https://api.toapis.cn 作为接口地址 (Base URL). 文档示例中的 https://api.toapis.com 请替换为 https://api.toapis.cn.

鉴权, 分页与错误处理见接入方式.

使用说明

返回指定 Key 的元数据, 用于查看名称, 状态, 额度, 到期时间和模型限制等配置. 已软删除的 Key 也可以读取, 此时 status=deleted. 完整密钥只在创建和轮换响应中返回, 本接口不返回 key 字段. 属于他人或不存在的 Key 统一返回 404.

鉴权

Authorizationstring请求头必填

使用系统访问令牌, 格式为 Bearer YOUR_SYSTEM_ACCESS_TOKEN. 模型 API Key 不能用于此接口, 无需 X-User-Id.

请求参数

api_key_idstring路径必填

自身模型 API Key 的十进制 ID 字符串. 不属于自己时返回 404, 已删除 Key 仍可用于查询自身历史用量.

约束: pattern=^[1-9][0-9]*$.

请求示例

请求示例

curl --request GET \
  --url 'https://api.toapis.com/api/v1/api-keys/42' \
  --header 'Authorization: Bearer YOUR_SYSTEM_ACCESS_TOKEN'
import requests

response = requests.get(
    "https://api.toapis.com/api/v1/api-keys/42",
    headers={"Authorization": "Bearer YOUR_SYSTEM_ACCESS_TOKEN"},
    timeout=30,
)
response.raise_for_status()
print(response.json())
const url = new URL("https://api.toapis.com/api/v1/api-keys/42");

const response = await fetch(url, {
  headers: { Authorization: "Bearer YOUR_SYSTEM_ACCESS_TOKEN" },
  signal: AbortSignal.timeout(30_000),
});

if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(await response.json());

响应字段

示例使用虚构数据. 金额样例假设 credits_per_usd="100", 实际换算以响应为准.

codeinteger

业务状态码, 成功时为 0.

messagestring

响应消息, 成功时为空字符串. 错误消息会按请求语言返回.

dataobject

本次查询的结果对象.

data.idstring

模型 API Key 的 ID, 不是 Key 原文. 以十进制 ID 字符串返回.

data.namestring

API Key 的名称.

data.key_hintstring | null

固定遮罩和 Key 末 4 位, 不返回完整密钥. Key 过短时为 null.

data.statusstring

API Key 当前状态. 详情可返回自身已软删除 Key 的元数据. 可选值: enabled, disabled, expired, exhausted, deleted, unknown.

data.created_atstring | null

创建时间. 时间格式为带时区的 RFC 3339. 无法确认或不适用时为 null.

data.expires_atstring | null

Key 过期时间, 未设置过期时间时为 null. 时间格式为带时区的 RFC 3339.

data.unlimitedboolean

Key 是否为无限额度. 为 true 时 remaining_credits=null.

data.remaining_creditsstring | null

剩余额度, 单位为 credits. API Key 无限额时为 null. 以十进制字符串返回以保持精度.

data.daily_limit_creditsstring | null

每日额度上限, 单位为 credits, 无限制时为 null. 以十进制字符串返回以保持精度.

data.monthly_limit_creditsstring | null

每月额度上限, 单位为 credits, 无限制时为 null. 以十进制字符串返回以保持精度.

data.model_limitsstring[]

模型白名单字符串数组, 无限制为 [], 不返回 null.

data.allow_ipsstring[]

该 Key 的有效 IP 白名单, 按字典序返回字符串数组; [] 表示不限制. 不影响同账号其他 Key 或系统访问令牌. 来源 IP 不匹配时, 模型调用返回 403. 配置修改沿用现有缓存及在途请求的生效边界.

响应示例

响应示例

{
  "code": 0,
  "message": "",
  "data": {
    "id": "42",
    "name": "Example Key",
    "key_hint": "****abcd",
    "status": "enabled",
    "created_at": "2026-10-01T00:00:00Z",
    "expires_at": null,
    "unlimited": false,
    "remaining_credits": "500",
    "daily_limit_credits": "100",
    "monthly_limit_credits": null,
    "model_limits": [],
    "allow_ips": []
  }
}