架构说明
本系统采用认证与资源分离的架构:
- API Key:仅用于身份认证,证明你有权使用服务
- Token 池:所有 refresh_token 组成一个共享池,系统按轮询策略自动选择可用账号
这意味着你可以为不同客户端分配不同的 API Key,但它们背后共享同一组智谱账号资源。
OpenAI SDK 调用示例
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://your-domain/v1"
)
response = client.chat.completions.create(
model="glm-4.7",
messages=[{"role": "user", "content": "你好"}],
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="")
curl 直接调用
curl -X POST "https://your-domain/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{"model":"glm-4.7","messages":[{"role":"user","content":"你好"}]}'
管理接口示例
curl -X POST "https://your-domain/admin/apikey" \
-H "X-Admin-Key: your-admin-key" \
-d '{"api_key":"sk-mykey"}'
curl -X GET "https://your-domain/admin/apikey" \
-H "X-Admin-Key: your-admin-key"
curl -X DELETE "https://your-domain/admin/apikey" \
-H "X-Admin-Key: your-admin-key" \
-d '{"api_key":"sk-mykey"}'
curl -X POST "https://your-domain/admin/token" \
-H "X-Admin-Key: your-admin-key" \
-d '{"refresh_token":"eyJ..."}'
curl -X GET "https://your-domain/admin/token" \
-H "X-Admin-Key: your-admin-key"
curl -X DELETE "https://your-domain/admin/token" \
-H "X-Admin-Key: your-admin-key" \
-d '{"id":"tk_xxx"}'