子用户独立页面与临时链接
其他产品可以通过后端签发带有效期的 UUID 链接,让子用户在免登录的独立页面中完成账户充值、查看已到账充值记录或查看余额与消耗明细。页面无平台导航,适配手机和电脑,且全程不在 URL 中暴露子用户的真实 API Key。
1. 使用组织密钥生成临时链接
由业务后端使用组织管理密钥(sk-org-…)调用 POST /api/v1/org/access-links,传入目标页面类型 type 与子用户的 api_key(sk-io-…):
curl -X POST "$PLATFORM_ORIGIN/api/v1/org/access-links" \
-H "Authorization: Bearer $ORG_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "usage",
"api_key": "sk-io-...",
"locale": "zh"
}'
请求参数
| 字段 | 必填 | 说明 |
|---|---|---|
type | 是 | 页面类型:usage(消耗明细)、recharges(充值记录)、recharge(独立充值页) |
api_key | 是 | 子用户 API Key(sk-io-…),服务端按哈希反查并校验归属当前组织,防止跨组织越权 |
locale | 否 | 页面语言(如 zh、en、zh-hant),默认跟随站点默认语言 |
expires_in | 否 | 有效期(秒),默认 1800(30 分钟),允许范围 60–86400 |
响应示例(HTTP 201)
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"token": "550e8400-e29b-41d4-a716-446655440000",
"type": "usage",
"url": "<PLATFORM_ORIGIN>/zh/statement/550e8400-e29b-41d4-a716-446655440000",
"expires_at": "2026-11-24T09:30:00.000Z"
}
严格一对一权限与有效期规则
type | 生成的独立页面地址 | 允许访问的数据接口 |
|---|---|---|
usage | /{locale}/statement/{uuid} | 仅 GET /api/v1/me/statement |
recharges | /{locale}/recharges/{uuid} | 仅 GET /api/v1/me/recharges |
recharge | /{locale}/recharge/{uuid} | 仅 /api/v1/me/recharge-portal 及 /api/v1/me/recharge-portal/{orderId} |
- 严格一对一:每个 UUID 只能访问签发时指定的单一页面及对应接口,跨页面使用返回 401
UNAUTHORIZED。 - 默认 30 分钟过期:超时后页面与接口均返回 401,需由业务后端重新生成链接。
- 不接受直接传 API Key:上述独立页面与
/api/v1/me/*门户接口均不再接受直接传入sk-io-…。 - 即时失效:删除或停用子用户、删除组织时,其名下所有未过期 UUID 链接立即失效。
在控制台的子用户列表中,点击「充值」「查看充值记录」「查看用户明细」三个图标按钮同样走此逻辑,自动签发 30 分钟有效期的 UUID 链接并在新标签页打开。
2. 消耗明细接口(type = "usage")
curl "$PLATFORM_ORIGIN/api/v1/me/statement?limit=20" \
-H "Authorization: Bearer $USAGE_LINK_UUID"
HTTP 200 响应:
{
"balance": "9.500000",
"currency": "CNY",
"expires_at": "2026-11-24T09:30:00.000Z",
"rows": [
{
"id": "<request_uuid>",
"created_at": "2026-11-24T01:00:00Z",
"model": "gpt-4.1-mini",
"model_name": "GPT-4.1 Mini",
"model_icon_key": "openai",
"amount": "0.030000",
"billing_status": "settled"
}
],
"page": 1,
"limit": 20,
"has_next": false,
"next_cursor": null,
"from": "2026-11-23T02:00:00.000Z",
"to": "2026-11-24T02:00:00.000Z"
}
- 筛选与分页参数:
from(包含,ISO 8601)、to(不包含,默认近 24 小时,最大跨度 93 天)、limit(默认 20,最大 100)、page、cursor。翻页时保留首次返回的from/to,携带上页next_cursor并递增page。 - 计费状态:
settled(已结算,零消耗保留为0)、pending(待结算,amount=null)、error(计费错误,amount=null)、unavailable(历史金额不可用,amount=null)。
3. 充值记录接口(type = "recharges")
仅返回已到账的充值记录,按时间倒序分页。
curl "$PLATFORM_ORIGIN/api/v1/me/recharges?limit=20" \
-H "Authorization: Bearer $RECHARGES_LINK_UUID"
HTTP 200 响应:
{
"balance": "30.000000",
"currency": "CNY",
"expires_at": "2026-11-24T09:30:00.000Z",
"rows": [
{
"id": "<transaction_uuid>",
"created_at": "2026-11-24T02:00:00Z",
"amount": "20.000000",
"balance_after": "30.000000",
"currency": "CNY",
"provider": "alipay"
}
],
"page": 1,
"limit": 20,
"has_next": false,
"next_cursor": null,
"from": null,
"to": null
}
- 筛选与分页参数:可选
from、to(不传则返回全部已到账记录),limit(默认 20,最大 100)、page、cursor(游标分页)。 provider可能为wechat、alipay、stripe或null。
4. 独立充值页接口(type = "recharge")
独立充值页 /{locale}/recharge/{uuid} 内部调用以下三个免登录接口(均使用 recharge 类型的 UUID 作为 Bearer 凭据):
查询余额与币种
curl "$PLATFORM_ORIGIN/api/v1/me/recharge-portal" \
-H "Authorization: Bearer $RECHARGE_LINK_UUID"
返回 {"balance":"9.500000","currency":"CNY","user_name":"Alice","expires_at":"2026-11-24T09:30:00.000Z"}。
创建充值订单
curl -X POST "$PLATFORM_ORIGIN/api/v1/me/recharge-portal" \
-H "Authorization: Bearer $RECHARGE_LINK_UUID" \
-H "Content-Type: application/json" \
-d '{"provider":"wechat","amount":50,"locale":"zh"}'
CNY站点支持wechat(返回codeUrl二维码内容)和alipay(返回checkoutUrl);USD站点支持stripe(返回checkoutUrl)。- 支付宝和 Stripe 支付完成后会自动回跳至当前免登录独立充值页
/{locale}/recharge/{uuid}?payment=pending&order={orderId},不会跳转到登录页。
查询订单状态
curl "$PLATFORM_ORIGIN/api/v1/me/recharge-portal/$ORDER_ID" \
-H "Authorization: Bearer $RECHARGE_LINK_UUID"
返回订单状态(pending / completed 等)与最新 current_balance。所有余额、链接与订单响应均禁止缓存(Cache-Control: no-store)。