接入 Dots AI(小红书)+ 新增 api-key 鉴权样式
老板要求:「查看 https://dots.ai/platform/docs 文档,帮我在 ai 网关上配置 dots.ai 的 供应商」(API Key 由老板提供,落 data/.env,不入库、不写进任何提交内容)。 文档要点(通读):base https://note3-prev-api.askdiandian.com/v1;两条线 POST /v1/chat/completions(OpenAI 兼容)与 POST /v1/messages(Anthropic 兼容,需固定头 anthropic-version: 2023-06-01);**认证是自定义头 `api-key: <KEY>`**(既不是 Bearer 也不是 x-api-key);模型 dots3-note-prev 上下文窗口 512K(524,288)、当前免费体验; 官方限流按单个 Key 计 60 次/分钟、1,500,000 Tokens/分钟。 改动: - 新增鉴权样式 `api-key`(AUTH_STYLES 由 bearer/x-api-key/none 扩为四种):适配器 auth_headers() 按线发 `api-key: <token>`;静态头里残留的同名头一并剥掉再按线补; 解析期校验接受该值、乱写的(api_key 下划线)仍被拒。 - data/gateway.yaml 新增 dots 供应商:两条线各自声明 path/auth,messages 线带 anthropic-version;rate_limit_rps: 1.0(= 官方 60/分钟,按 Key);模型 dots3-note-prev (context_window 524288、vision: true、free: true、双协议线;官方未给最大输出上限→留空不猜)。 - 顺带补 Anthropic 口径的缓存统计:其 input_tokens 不含缓存部分,缓存命中在 cache_read_input_tokens、写缓存在 cache_creation_input_tokens(三者互斥)。_usage_detail() 改为分口径:OpenAI 的 prompt_tokens 已含缓存;Anthropic 三者相加为输入总量、缓存取 cache_read_input_tokens —— 否则 messages 线的缓存量永远记 0(接 Dots 时实测到)。 上线实测(重启后,两条线各一次瘦请求,均免费): POST /v1/chat/completions → 200 usage{prompt 17, completion 8} POST /v1/messages → 200 usage{input 17, output 8} /v1/models:42 个模型,dots3-note-prev 带 context_window 524288 / 双协议线 / free 指标:calls{dots3-note-prev: ok 1}、tokens{prompt 14, completion 4} 测试:新增「Dots 配置 + api-key 样式(含解析期拒绝非法值)」与「Anthropic 缓存口径」两条 回归;既有 test_load_config_providers 供应商集合更新为四家。206 → 208 全过。
This commit is contained in:
1 parent
7c3d5fad24
commit
ef6beead10
7 files changed
+203
-33
No files matched your search
+7
-3
@@ -56,8 +56,12 @@ PROTOCOLS: tuple[str, ...] = (PROTOCOL_CHAT, PROTOCOL_MESSAGES, PROTOCOL_RESPONS
|
||||
# 默认全支持等于把「没实测过的线」当成可用,用户打过去只会收到上游 500。
|
||||
DEFAULT_PROTOCOLS: tuple[str, ...] = (PROTOCOL_CHAT,)
|
||||
|
||||
# 出站鉴权方式:bearer(Authorization: Bearer xxx)/ x-api-key(Anthropic 系)/ none
|
||||
AUTH_STYLES: frozenset[str] = frozenset({"bearer", "x-api-key", "none"})
|
||||
# 出站鉴权方式:
|
||||
# bearer → Authorization: Bearer xxx
|
||||
# x-api-key → x-api-key: xxx(Anthropic 系)
|
||||
# api-key → api-key: xxx(第三十六轮新增:自定义头就叫 api-key,如 Dots AI)
|
||||
# none → 不带鉴权头
|
||||
AUTH_STYLES: frozenset[str] = frozenset({"bearer", "x-api-key", "api-key", "none"})
|
||||
|
||||
# ── 虚拟模型 id(别名,第三十一轮)───────────────────────────────────
|
||||
# 老板决策(2026-09-18):「设置一个 wjd 模型 id,路由到指定的模型上;在管理员的网关配置里
|
||||
@@ -96,7 +100,7 @@ class EndpointSpec:
|
||||
"""
|
||||
|
||||
path: str = "" # 相对 base_url 的路径,如 /chat/completions
|
||||
auth: str = "bearer" # bearer | x-api-key | none
|
||||
auth: str = "bearer" # bearer | x-api-key | api-key | none
|
||||
headers: dict[str, str] = field(default_factory=dict) # 该线固定附加头(如 anthropic-version)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user