mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-29 15:35:11 +00:00
后端: - 协议凭证维度 credentials[api_protocol] ∈ chat_completions(默认)/anthropic/responses(deepseek) - /v1/messages 零转换直通原生 Anthropic 端点(kimi/zhipu/deepseek),CC/Responses 入站交叉组合走 apicompat 双向转换链(responses/chat_completions anthropic-native 转发器) - count_tokens:anthropic 协议透传原生端点;其余 CN 协议本地 tiktoken 估算 - Coding Plan 额度探测(5h/weekly 滚动窗口)+ payg 余额探测(kimi/deepseek), deepseek 双币种 CNY+USD 明细,任一币种达标不停调 - 周期任务 [CNBalance] 并发探测 + 预算随工作量放大;响应式 429 冷却到最早窗口 重置点;余额不足可恢复临时停调;智谱 CREDIT_LIMIT 不污染窗口解析 - CC→anthropic 流式客户端断开后继续排水上游保住 usage 计量 前端: - 创建/编辑弹窗 account_mode + api_protocol + base_url 联动预设(含 watcher 竞态防护) - 用量单元格:kimi/zhipu coding 显示 5h/weekly 窗口,kimi/deepseek payg 显示余额, 多币种并列展示;探测失败保留快照;挂载自动探测 5min 去抖 - 调度阈值设置面板补 kimi/zhipu 平台(对齐后端 AllowedSchedulingThresholdPlatforms)
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
anthropicAPIKeyAuthSchemeExtraKey = "anthropic_apikey_auth_scheme"
|
|
|
|
AnthropicAPIKeyAuthSchemeXAPIKey = "x_api_key"
|
|
AnthropicAPIKeyAuthSchemeAuthorizationBearer = "authorization_bearer"
|
|
)
|
|
|
|
// GetAnthropicAPIKeyAuthScheme returns the upstream authentication scheme for
|
|
// Anthropic API-key accounts. Missing or invalid values keep the historical
|
|
// x-api-key behavior. CN providers using their native Anthropic endpoints
|
|
// (api_protocol=anthropic) share the same override knob — Kimi/DeepSeek default
|
|
// to x-api-key, Zhipu can opt into Authorization: Bearer.
|
|
func (a *Account) GetAnthropicAPIKeyAuthScheme() string {
|
|
if a == nil || a.Type != AccountTypeAPIKey {
|
|
return AnthropicAPIKeyAuthSchemeXAPIKey
|
|
}
|
|
if a.Platform != PlatformAnthropic && !a.IsCNProvider() {
|
|
return AnthropicAPIKeyAuthSchemeXAPIKey
|
|
}
|
|
|
|
switch strings.TrimSpace(a.GetExtraString(anthropicAPIKeyAuthSchemeExtraKey)) {
|
|
case AnthropicAPIKeyAuthSchemeAuthorizationBearer:
|
|
return AnthropicAPIKeyAuthSchemeAuthorizationBearer
|
|
default:
|
|
return AnthropicAPIKeyAuthSchemeXAPIKey
|
|
}
|
|
}
|
|
|
|
func setAnthropicAPIKeyAuthHeader(header http.Header, account *Account, token string) {
|
|
if account.GetAnthropicAPIKeyAuthScheme() == AnthropicAPIKeyAuthSchemeAuthorizationBearer {
|
|
header.Set("Authorization", "Bearer "+token)
|
|
return
|
|
}
|
|
header.Set("x-api-key", token)
|
|
}
|