Skip to content

Commit ca2708a

Browse files
fix(ai): allow Ollama Cloud API key in AI settings (#4262)
The Ollama detection matched any URL containing "ollama", which hides the API Key field for Ollama Cloud (ollama.com) and drops the key from the createOllama() client, so cloud requests go out unauthenticated. Narrow the rule to localhost-only Ollama and forward the API key as a Bearer header when provided. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f8a3561 commit ca2708a

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

apps/dokploy/components/dashboard/settings/handle-ai.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ export const HandleAi = ({ aiId }: Props) => {
131131
const apiUrl = form.watch("apiUrl");
132132
const apiKey = form.watch("apiKey");
133133

134-
const isOllama = apiUrl.includes(":11434") || apiUrl.includes("ollama");
134+
// Any Ollama instance on the default port 11434 is treated as no-auth
135+
// (covers localhost and self-hosted LAN deployments). Ollama Cloud
136+
// (ollama.com on 443) falls through and requires an API key.
137+
const isLocalOllama = apiUrl.includes(":11434");
135138
const {
136139
data: models,
137140
isFetching: isLoadingServerModels,
@@ -142,7 +145,7 @@ export const HandleAi = ({ aiId }: Props) => {
142145
apiKey: apiKey ?? "",
143146
},
144147
{
145-
enabled: !!apiUrl && (isOllama || !!apiKey),
148+
enabled: !!apiUrl && (isLocalOllama || !!apiKey),
146149
},
147150
);
148151

@@ -275,7 +278,7 @@ export const HandleAi = ({ aiId }: Props) => {
275278
)}
276279
/>
277280

278-
{!isOllama && (
281+
{!isLocalOllama && (
279282
<FormField
280283
control={form.control}
281284
name="apiKey"

packages/server/src/utils/ai/select-ai-provider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ export function selectAIProvider(config: { apiUrl: string; apiKey: string }) {
7474
});
7575
case "ollama":
7676
return createOllama({
77-
// optional settings, e.g.
7877
baseURL: config.apiUrl,
78+
headers: config.apiKey
79+
? { Authorization: `Bearer ${config.apiKey}` }
80+
: undefined,
7981
});
8082
case "deepinfra":
8183
return createDeepInfra({

0 commit comments

Comments
 (0)