From 8ef602977da4e4c2295d8e3b79f8327b19647f39 Mon Sep 17 00:00:00 2001 From: pozii Date: Tue, 23 Jun 2026 01:41:00 +0300 Subject: [PATCH] Add Mistral & TogetherAI OpenAI-compatible support Add OpenAI-compatible support for @ai-sdk/mistral and @ai-sdk/togetherai. Updates include: - core/src/session/runner/model.ts: map aisdk packages @ai-sdk/togetherai and @ai-sdk/mistral to OpenAICompatibleChat.route, include auth handling, and add packages to the supported check. - llm/src/providers/openai-compatible-profile.ts: add mistral profile with base URL. - llm/src/providers/openai-compatible.ts: export mistral provider. - llm/test/provider/openai-compatible-chat.test.ts: include mistral in providerFamilies. This enables using Mistral and TogetherAI as OpenAI-compatible providers within the runtime and test suite. --- packages/core/src/session/runner/model.ts | 16 ++++++++++++++++ .../src/providers/openai-compatible-profile.ts | 1 + packages/llm/src/providers/openai-compatible.ts | 1 + .../test/provider/openai-compatible-chat.test.ts | 1 + 4 files changed, 19 insertions(+) diff --git a/packages/core/src/session/runner/model.ts b/packages/core/src/session/runner/model.ts index 968933a6b52a..9970c7072fc2 100644 --- a/packages/core/src/session/runner/model.ts +++ b/packages/core/src/session/runner/model.ts @@ -146,6 +146,20 @@ export const fromCatalogModel = ( .model({ id: resolved.api.id }), ) } + if (resolved.api.type === "aisdk" && resolved.api.package === "@ai-sdk/togetherai" && resolved.api.url) { + return Effect.succeed( + withDefaults(resolved, OpenAICompatibleChat.route) + .with({ auth: key === undefined ? Auth.none : Auth.bearer(key) }) + .model({ id: resolved.api.id }), + ) + } + if (resolved.api.type === "aisdk" && resolved.api.package === "@ai-sdk/mistral" && resolved.api.url) { + return Effect.succeed( + withDefaults(resolved, OpenAICompatibleChat.route) + .with({ auth: key === undefined ? Auth.none : Auth.bearer(key) }) + .model({ id: resolved.api.id }), + ) + } return Effect.fail( new UnsupportedApiError({ providerID: resolved.providerID, @@ -169,6 +183,8 @@ export const supported = (model: ModelV2.Info) => model.api.type === "aisdk" && (model.api.package === "@ai-sdk/openai" || model.api.package === "@ai-sdk/anthropic" || + model.api.package === "@ai-sdk/togetherai" || + model.api.package === "@ai-sdk/mistral" || (model.api.package === "@ai-sdk/openai-compatible" && model.api.url !== undefined)) /** Resolves models from the catalog belonging to the current Location runtime. */ diff --git a/packages/llm/src/providers/openai-compatible-profile.ts b/packages/llm/src/providers/openai-compatible-profile.ts index 30770c9671cd..26c36e233aca 100644 --- a/packages/llm/src/providers/openai-compatible-profile.ts +++ b/packages/llm/src/providers/openai-compatible-profile.ts @@ -11,6 +11,7 @@ export const profiles = { fireworks: { provider: "fireworks", baseURL: "https://api.fireworks.ai/inference/v1" }, groq: { provider: "groq", baseURL: "https://api.groq.com/openai/v1" }, openrouter: { provider: "openrouter", baseURL: "https://openrouter.ai/api/v1" }, + mistral: { provider: "mistral", baseURL: "https://api.mistral.ai/v1" }, togetherai: { provider: "togetherai", baseURL: "https://api.together.xyz/v1" }, xai: { provider: "xai", baseURL: "https://api.x.ai/v1" }, } as const satisfies Record diff --git a/packages/llm/src/providers/openai-compatible.ts b/packages/llm/src/providers/openai-compatible.ts index a79f65f6dfe0..20d75c908a4e 100644 --- a/packages/llm/src/providers/openai-compatible.ts +++ b/packages/llm/src/providers/openai-compatible.ts @@ -62,4 +62,5 @@ export const deepinfra = define(profiles.deepinfra) export const deepseek = define(profiles.deepseek) export const fireworks = define(profiles.fireworks) export const groq = define(profiles.groq) +export const mistral = define(profiles.mistral) export const togetherai = define(profiles.togetherai) diff --git a/packages/llm/test/provider/openai-compatible-chat.test.ts b/packages/llm/test/provider/openai-compatible-chat.test.ts index 43ae283e9f7c..f3b38b382417 100644 --- a/packages/llm/test/provider/openai-compatible-chat.test.ts +++ b/packages/llm/test/provider/openai-compatible-chat.test.ts @@ -46,6 +46,7 @@ const providerFamilies = [ ["deepinfra", OpenAICompatible.deepinfra, "https://api.deepinfra.com/v1/openai"], ["deepseek", OpenAICompatible.deepseek, "https://api.deepseek.com/v1"], ["fireworks", OpenAICompatible.fireworks, "https://api.fireworks.ai/inference/v1"], + ["mistral", OpenAICompatible.mistral, "https://api.mistral.ai/v1"], ["togetherai", OpenAICompatible.togetherai, "https://api.together.xyz/v1"], ] as const