认证与调用
Base URL
Section titled “Base URL”网关统一入口为 https://{gateway-host}(本地默认 http://localhost:8080)。OpenAI 兼容端点以 /v1 开头,Anthropic 兼容端点以 /anthropic/v1 开头。
注意:Anthropic 端点带
/anthropic前缀,即/anthropic/v1/messages,而非/v1/messages。
调用方持有 sk- 开头的网关 API Key,支持两种 Header(二选一,均被 ApiKeyAuthInterceptor 接受):
| Header | 适用协议 | 示例 |
|---|---|---|
Authorization: Bearer <key> | OpenAI 兼容 | Authorization: Bearer sk-xxx |
x-api-key: <key> | Anthropic 兼容 | x-api-key: sk-xxx |
Anthropic 端点另需携带 anthropic-version: 2023-06-01。
- 拦截器从 Header 提取 API Key
AuthenticationDomainService.authenticateUser(apiKey)校验 Key 有效性- 返回
Identity(userId, role, credentialId, applicationId),存入请求上下文 - 路由链依据
applicationId过滤该应用授权的渠道
API Key 关联到应用,应用决定可见渠道集合。未授权渠道下的模型不可调用。详见 应用管理。
获取 API Key
Section titled “获取 API Key”- 登录控制台,进入 ApiKeys 或 Quickstart 模块
- 创建 Key(明文仅此一次返回,请妥善保存)
- Key 创建时绑定用户与应用;模型可见范围由应用-渠道授权决定(详见 调用方密钥管理)
基础调用示例
Section titled “基础调用示例”OpenAI 兼容
Section titled “OpenAI 兼容”curl https://{gateway-host}/v1/chat/completions \ -H "Authorization: Bearer sk-xxx" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}'Anthropic 兼容
Section titled “Anthropic 兼容”curl https://{gateway-host}/anthropic/v1/messages \ -H "x-api-key: sk-xxx" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{"model":"claude-sonnet-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":"Hello"}]}'