Skip to content

Commit 9f3736c

Browse files
fix(ai): allow Ollama Cloud API key in AI settings
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) <[email protected]>
1 parent 98a5864 commit 9f3736c

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ 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+
// Only skip the API Key field for a local Ollama instance.
135+
// Ollama Cloud (ollama.com) still requires an API key.
136+
const isLocalOllama =
137+
apiUrl.includes("localhost:11434") ||
138+
apiUrl.includes("127.0.0.1:11434");
135139
const {
136140
data: models,
137141
isFetching: isLoadingServerModels,
@@ -142,7 +146,7 @@ export const HandleAi = ({ aiId }: Props) => {
142146
apiKey: apiKey ?? "",
143147
},
144148
{
145-
enabled: !!apiUrl && (isOllama || !!apiKey),
149+
enabled: !!apiUrl && (isLocalOllama || !!apiKey),
146150
},
147151
);
148152

@@ -275,7 +279,7 @@ export const HandleAi = ({ aiId }: Props) => {
275279
)}
276280
/>
277281

278-
{!isOllama && (
282+
{!isLocalOllama && (
279283
<FormField
280284
control={form.control}
281285
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)