Skip to content

Commit 14ef34e

Browse files
committed
feat: support provider/model slash format in model strings
resolveModelOption() now parses 'anthropic/claude-haiku' as provider 'anthropic' + model 'claude-haiku' when the prefix before the first slash matches a known provider in PROVIDER_DEFAULTS. OpenRouter model paths like 'meta-llama/llama-3.1-8b' are unaffected since 'meta-llama' is not a known provider ID.
1 parent 87c0509 commit 14ef34e

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/api/model.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,18 @@ export interface ModelOption {
258258
export function resolveModelOption(opts: ModelOption, task: TaskType = 'text'): ParsedModel {
259259
// 1. Explicit model string (backwards compat and direct override)
260260
if (opts.model) {
261-
// Legacy "provider:model" format
261+
// Canonical "provider:model" format
262262
if (opts.model.includes(':')) return parseModelString(opts.model);
263+
// Alternative "provider/model" format — check if the prefix before the
264+
// first "/" is a known provider ID. This avoids misinterpreting OpenRouter
265+
// model paths like "meta-llama/llama-3.1-8b" as provider "meta-llama".
266+
const slashIdx = opts.model.indexOf('/');
267+
if (slashIdx > 0) {
268+
const maybeProvider = opts.model.slice(0, slashIdx);
269+
if (PROVIDER_DEFAULTS[maybeProvider]) {
270+
return { providerId: maybeProvider, modelId: opts.model.slice(slashIdx + 1) };
271+
}
272+
}
263273
// Plain model name with explicit provider
264274
if (opts.provider) return { providerId: opts.provider, modelId: opts.model };
265275
// Plain model name — try auto-detect for provider

0 commit comments

Comments
 (0)