[Bug] 调度快照投影裁掉 openai_capabilities / base_url,Seedance 账号选号恒为 capability_mismatch
版本
Sub2API 0.2.10 (commit 2f3fed2fd)
现象
按 Seedance 的要求配置了 OpenAI API Key 账号,满足以下全部条件:
platform = openai,type = apikeycredentials.base_url不为空(方舟兼容上游)credentials.openai_capabilities = ["seedance"](后台勾选「Seedance (Ark)」)- 账号
active、可调度,已加入 Key 所属的 OpenAI 分组,分组已开「允许当前分组生图」
但 POST /api/v3/contents/generations/tasks 始终返回:
{"error":{"message":"No eligible Seedance accounts","type":"seedance_no_eligible_account"}}服务端日志:
grok_media.account_select_failed endpoint=seedance_create
error="no available OpenAI accounts supporting model: <model> (pool=1, filtered: capability_mismatch=1)"数据库里账号的 credentials 完全正确,修改或重新保存账号、等待快照重建都没有用。直接请求上游方舟兼容接口是正常的。
根因
backend/internal/repository/scheduler_cache.go 的 filterSchedulerCredentials 是白名单式裁剪:
keys := []string{"model_mapping", "compact_model_mapping", "api_key", "project_id", "oauth_type", "plan_type", "account_scheduling_threshold"}白名单里没有 openai_capabilities,也没有 base_url。
而选号阶段(ListSchedulableAccounts → 候选过滤 openai_gateway_scheduling.go 中的 SupportsOpenAIEndpointCapability(requiredCapability))用的正是这份 sched:meta:<id> 精简投影。Seedance 的判定(internal/service/account.go SupportsOpenAIEndpointCapability)是:
if capability == OpenAIEndpointCapabilitySeedance {
configured, _ := a.openAIEndpointCapabilitySet()
return configured["seedance"] && a.Platform == PlatformOpenAI && a.Type == AccountTypeAPIKey &&
strings.TrimSpace(a.GetCredential("base_url")) != ""
}两个输入在投影里都被裁掉了,所以只要走调度快照,任何 Seedance 账号在选号阶段都恒为 capability_mismatch,导致 Seedance 功能在正常网关路径下完全不可用。
chat_completions / embeddings 没暴露这个问题,是因为「未配置能力集 = 不限制」(openAIEndpointCapabilitySet 返回 found=false → true)。而 Seedance 必须显式开启,只有它会被投影裁剪卡死。
副作用
同样的原因下,只配置了 openai_capabilities = ["embeddings"] 的 API Key 账号,在投影里变成了「未配置能力集」,选号阶段 SupportsOpenAIEndpointCapability(chat_completions) 会返回 true,不会被 chat 请求的候选过滤排除,能力限制在选号阶段失效。
复现
- 建一个 OpenAI API Key 账号,填写
base_url,openai_capabilities = ["seedance"],加入 OpenAI 分组并开启分组生图; - 确保调度快照生效(正常网关请求路径);
POST /api/v3/contents/generations/tasks,body 为{"model":"<model>","content":[{"type":"text","text":"..."}]}。
预期:选中该账号并转发到上游。
实际:503 seedance_no_eligible_account,日志 filtered: capability_mismatch=1。
对照检查(payload 的 JSON 字段为 PascalCase):
redis-cli GET sched:acc:<id> # Credentials 里有 openai_capabilities / base_url
redis-cli GET sched:meta:<id> # Credentials 里没有最小单测复现(放在 internal/repository/scheduler_cache_test.go,当前代码下失败):
func TestSchedulerMetadataAccountKeepsOpenAIEndpointCapabilities(t *testing.T) {
seedance := buildSchedulerMetadataAccount(service.Account{
ID: 25,
Platform: service.PlatformOpenAI,
Type: service.AccountTypeAPIKey,
Credentials: map[string]any{
"api_key": "sk-upstream",
"base_url": "https://ark.example.com",
"openai_capabilities": []any{"seedance"},
},
})
require.True(t, seedance.SupportsOpenAIEndpointCapability(service.OpenAIEndpointCapabilitySeedance))
embeddingsOnly := buildSchedulerMetadataAccount(service.Account{
ID: 26,
Platform: service.PlatformOpenAI,
Type: service.AccountTypeAPIKey,
Credentials: map[string]any{
"api_key": "sk-upstream",
"openai_capabilities": []any{"embeddings"},
},
})
require.False(t, embeddingsOnly.SupportsOpenAIEndpointCapability(service.OpenAIEndpointCapabilityChatCompletions))
}建议修复
把 openai_capabilities 和 base_url 加进 filterSchedulerCredentials 的白名单。服务启动时会执行 runInitialRebuild,部署后快照会自动带上新字段。
与 #6457(投影裁掉 openai_passthrough)属于同一类问题:任何参与选号判定的 credentials / extra 键,都必须出现在投影白名单里。 建议补一条回归测试,断言投影往返后 SupportsOpenAIEndpointCapability 的结果不变,而不只是断言键存在。
Source: Wei-Shaw/sub2api