Skip to content

An AI-powered search engine with a generative UI

fix(registry): route openai-compatible provider through chat completions endpoint (#846)

Eliauk0383c9e973c2
diff --git a/bun.lock b/bun.lock
index 4636aa0a..a7aa02b3 100644
--- a/bun.lock
+++ b/bun.lock
@@ -9,6 +9,7 @@
"@ai-sdk/gateway": "^3.0.114",
"@ai-sdk/google": "^3.0.73",
"@ai-sdk/openai": "^3.0.63",
+ "@ai-sdk/openai-compatible": "^2.0.47",
"@ai-sdk/react": "^3.0.182",
"@aws-sdk/client-s3": "^3.850.0",
"@json-render/core": "^0.16.0",
@@ -105,6 +106,8 @@
"@ai-sdk/openai": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.10", "@ai-sdk/provider-utils": "4.0.27" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-4yY/m8a57MNNVoJCsXuNblKf6BO4yuAuLKRX4tzSNffBEBSp1FlcWdPE0Z4FkqUeS0AJhYSSqp0GIiA/cIcDNA=="],
+ "@ai-sdk/openai-compatible": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.10", "@ai-sdk/provider-utils": "4.0.27" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-Enm5UlL0zUCrW3792opk5h7hRWxZOZzDe6eQYVFqX9LUOGGCe1h8MZWAGim765nwzgnjlpeYOsuzZmLtRsTPlg=="],
+
"@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-Q3BZ27qfpYqnCYGvE3vt+Qi6LGOF9R5Nmzn+9JoM1lCRsD9mYaIhfJLkSunN48nfGXJ6n+XNV0J/XVpqGQl7Dw=="],
"@ai-sdk/provider-utils": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.10", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.8" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ubkAJ+xODouwtmN1tYlvTPphH1hPOBfZaEQe8U7skGvFAnIRs9PPpsq57bC2+Ky/MB4yzhd6YOsxTAx9sGpazw=="],
diff --git a/lib/utils/registry.ts b/lib/utils/registry.ts
index 36f32b67..d5b79e15 100644
--- a/lib/utils/registry.ts
+++ b/lib/utils/registry.ts
@@ -1,18 +1,30 @@
import { anthropic } from '@ai-sdk/anthropic'
import { createGateway } from '@ai-sdk/gateway'
import { google } from '@ai-sdk/google'
-import { createOpenAI, openai } from '@ai-sdk/openai'
+import { openai } from '@ai-sdk/openai'
+import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { createProviderRegistry, LanguageModel } from 'ai'
import { createOllama } from 'ai-sdk-ollama'
+// Strip a trailing /v1 from the configured base URL, then re-append it,
+// so both shapes work for OpenAI-compatible hosts:
+// OPENAI_COMPATIBLE_API_BASE_URL=https://api.deepseek.com
+// OPENAI_COMPATIBLE_API_BASE_URL=https://api.deepseek.com/v1
+function normalizeOpenAICompatibleBaseURL(raw: string): string {
+ return raw.replace(/\/+$/, '').replace(/\/v1$/, '') + '/v1'
+}
+
// Build providers object conditionally
const providers: Record<string, any> = {
openai,
anthropic,
google,
- 'openai-compatible': createOpenAI({
+ 'openai-compatible': createOpenAICompatible({
+ name: process.env.OPENAI_COMPATIBLE_PROVIDER_NAME || 'openai-compatible',
apiKey: process.env.OPENAI_COMPATIBLE_API_KEY,
- baseURL: process.env.OPENAI_COMPATIBLE_API_BASE_URL
+ baseURL: normalizeOpenAICompatibleBaseURL(
+ process.env.OPENAI_COMPATIBLE_API_BASE_URL || ''
+ )
}),
gateway: createGateway({
apiKey: process.env.AI_GATEWAY_API_KEY
diff --git a/package.json b/package.json
index 1128e1a1..39217156 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
"@ai-sdk/gateway": "^3.0.114",
"@ai-sdk/google": "^3.0.73",
"@ai-sdk/openai": "^3.0.63",
+ "@ai-sdk/openai-compatible": "^2.0.47",
"@ai-sdk/react": "^3.0.182",
"@aws-sdk/client-s3": "^3.850.0",
"@json-render/core": "^0.16.0",