Skip to content

Commit 6512a50

Browse files
committed
fix(api): strip date suffix when remapping anthropic models to OpenRouter fallback
1 parent b243011 commit 6512a50

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/api/model.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,15 @@ export function resolveProvider(
142142
if (providerId === 'anthropic' && !apiKey) {
143143
const orKey = process.env['OPENROUTER_API_KEY'];
144144
if (orKey) {
145+
// Anthropic's native API takes dated model IDs (e.g. "claude-haiku-4-5-20251001").
146+
// OpenRouter exposes Anthropic models under dateless slugs (e.g. "anthropic/claude-haiku-4-5").
147+
// Strip a trailing -YYYYMMDD release-date suffix when remapping so the OR call resolves.
148+
const orModelId = modelId.replace(/-\d{8}$/, '');
145149
console.warn(
146-
`[AgentOS] ANTHROPIC_API_KEY not set — falling back to OpenRouter for model "${modelId}". ` +
147-
`Set ANTHROPIC_API_KEY for direct access.`
150+
`[AgentOS] ANTHROPIC_API_KEY not set — falling back to OpenRouter for model "${modelId}" ` +
151+
`(routed as "anthropic/${orModelId}"). Set ANTHROPIC_API_KEY for direct access.`
148152
);
149-
return { providerId: 'openrouter', modelId: `anthropic/${modelId}`, apiKey: orKey };
153+
return { providerId: 'openrouter', modelId: `anthropic/${orModelId}`, apiKey: orKey };
150154
}
151155
throw new Error(`No API key for anthropic. Set ANTHROPIC_API_KEY or OPENROUTER_API_KEY.`);
152156
}

0 commit comments

Comments
 (0)