diff --git a/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.availability.http.test.ts b/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.availability.http.test.ts index c619b839b..30bf9b939 100644 --- a/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.availability.http.test.ts +++ b/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.availability.http.test.ts @@ -129,6 +129,17 @@ describe('model availability through real HTTP', () => { meteringEnforcement: { subscriptions: false }, } as never); }, 120000); + it('serves qualified chat model names through HTTP', async () => { + const response = await fetch( + new URL('/puterai/chat/models', env.apiOrigin), + ); + expect(response.status).toBe(200); + const { models } = (await response.json()) as { models: string[] }; + expect(models).toContain('openrouter:vendor/availability-test'); + expect(models.every((id) => /^[^:/]+:[^/]+\/.+/.test(id))).toBe(true); + expect(models).not.toContain('vendor/availability-test'); + }); + afterAll(async () => { await env?.shutdown(); upstream?.closeAllConnections(); diff --git a/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.test.ts b/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.test.ts index 4ae22f75d..e0e25f47e 100644 --- a/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.test.ts +++ b/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.test.ts @@ -207,6 +207,48 @@ describe('ChatCompletionDriver model map', () => { d.onServerShutdown(); }); + it('lists qualified model ids without publishing aliases as models', async () => { + const ids = [ + 'kimi/kimi-3', + 'ollama:plain-model', + 'ollama:vendor/qualified', + ]; + vi.spyOn(OllamaChatProvider.prototype, 'models').mockResolvedValue( + ids.map((id) => ({ + id, + aliases: ['legacy-' + id], + costs_currency: 'usd-cents', + costs: {}, + max_tokens: 8192, + })), + ); + const d = newDriver({ ollama: {} }); + await d.onServerStart(); + try { + expect( + (await d.list()).filter( + (id) => !['abuse', 'costly', 'fake'].includes(id), + ), + ).toEqual([ + 'ollama:kimi/kimi-3', + 'ollama:ollama/plain-model', + 'ollama:vendor/qualified', + ]); + const models = (await d.models()).filter( + (model) => model.provider === 'ollama', + ); + expect(models.map((model) => model.id).sort()).toEqual( + [...ids].sort(), + ); + for (const model of models) { + expect(model.aliases).toContain(model.puterId); + expect(model.aliases).toContain('legacy-' + model.id); + } + } finally { + d.onServerShutdown(); + } + }); + it('lists the catalog to a caller that asks while it is still loading', async () => { const d = newDriver({ ollama: { enabled: false } }); d.onServerStart(); diff --git a/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.ts b/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.ts index 05c1d9d41..34b16b4da 100644 --- a/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.ts +++ b/src/backend/drivers/ai/interfaces/chat/ChatCompletionDriver.ts @@ -2086,14 +2086,35 @@ export class ChatCompletionDriver extends PuterDriver { // instance, so they are read and never written: normalizing // the id or appending puterId in place would accumulate across // instantiations. The bucket gets its own copy instead. - const aliases = - entry.puterId && - !(entry.aliases ?? []).includes(entry.puterId) - ? [...(entry.aliases ?? []), entry.puterId] - : entry.aliases; + // Keep upstream ids for provider calls and publish a qualified + // routing name even when a catalog omits its vendor namespace. + const publicId = entry.puterId || entry.id; + const serviceSeparator = publicId.indexOf(':'); + const service = + serviceSeparator < 0 + ? providerName + : publicId.slice(0, serviceSeparator); + const modelPath = + serviceSeparator < 0 + ? publicId + : publicId.slice(serviceSeparator + 1); + const puterId = + providerName === 'fake-chat' + ? entry.puterId + : `${service}:${modelPath.includes('/') ? modelPath : `${service}/${modelPath}`}`; + const aliases = puterId + ? [ + ...new Set([ + ...(entry.aliases ?? []), + ...(entry.puterId ? [entry.puterId] : []), + puterId, + ]), + ] + : entry.aliases; const model = { ...entry, id: normalizeModelKey(entry.id), + ...(puterId ? { puterId } : {}), }; // Assigned only when the entry has names to carry: models() // is serialized to the API, and an entry that declared no diff --git a/src/docs/src/AI/listModels.md b/src/docs/src/AI/listModels.md index 3fdca0e67..d0af8836f 100644 --- a/src/docs/src/AI/listModels.md +++ b/src/docs/src/AI/listModels.md @@ -22,12 +22,15 @@ A string containing the provider you want to list the models for. Resolves to an array of model objects. Each object always contains `id` and `provider`, and may include fields such as `name`, `aliases`, `context`, `max_tokens`, and a `cost` object (`currency`, `tokens`, `input` and `output` costs in cents). Additional provider-specific capability fields may also be present. +The `puterId` field contains the qualified model name in `:/` form. Pass this name as the `model` option to [`puter.ai.chat()`](/AI/chat/). The `id` field and aliases also remain accepted model names. When an upstream catalog supplies no provider namespace, the qualified name uses the service name as its namespace. + Example model entry: ```json [ { "id": "claude-opus-4-8", + "puterId": "anthropic:anthropic/claude-opus-4-8", "provider": "claude", "name": "Claude Opus 4.8", "aliases": ["claude-opus-4-8-latest"],