Skip to content

Commit ce8a33d

Browse files
committed
fix(api): autoDetectProvider prioritizes openrouter over openai
AUTO_DETECT_ORDER listed openai before openrouter, but both the function's documented priority comment and the provider-defaults.test assertion "prefers openrouter over openai when both are set" pin the opposite order. The probe array had drifted from the stated design, so any call site that auto-detected a provider with both keys present silently picked openai and never went through the OpenRouter aggregator the user configured. Fix: move the OPENROUTER_API_KEY probe to the head of the array. Matches the // Priority: openrouter → openai → anthropic → … comment directly above the function definition. Aligns with user intent — keys for an aggregator plus a direct provider usually mean "route through the aggregator for failover / cost / pooling". Also fixes one of two pre-existing CI failures on the AgentOS test suite. 19/19 provider-defaults tests now pass. Second pre-existing failure (generateImage Replicate body.version resolution) left to a dedicated session — deeper trace through the image-provider chain.
1 parent cf6f081 commit ce8a33d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/api/runtime/provider-defaults.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,15 @@ type AutoDetectProbe =
116116
* the requested task type, so the order matters most for the default (text) case.
117117
*/
118118
const AUTO_DETECT_ORDER: AutoDetectProbe[] = [
119+
// OpenRouter first: users who set OPENROUTER_API_KEY alongside a
120+
// direct-provider key typically intend the OpenRouter aggregator
121+
// to mediate (failover, cost routing, etc.). Matches the documented
122+
// priority comment below and the provider-defaults.test.ts pin that
123+
// "openrouter wins when both OPENROUTER_API_KEY and OPENAI_API_KEY
124+
// are set".
125+
{ envKey: 'OPENROUTER_API_KEY', provider: 'openrouter' },
119126
{ envKey: 'OPENAI_API_KEY', provider: 'openai' },
120127
{ envKey: 'ANTHROPIC_API_KEY', provider: 'anthropic' },
121-
{ envKey: 'OPENROUTER_API_KEY', provider: 'openrouter' },
122128
{ envKey: 'GEMINI_API_KEY', provider: 'gemini' },
123129
{ envKey: 'GROQ_API_KEY', provider: 'groq' },
124130
{ envKey: 'TOGETHER_API_KEY', provider: 'together' },

0 commit comments

Comments
 (0)