diff --git a/src/api/providers/__tests__/lm-studio-timeout.spec.ts b/src/api/providers/__tests__/lm-studio-timeout.spec.ts index 659fcaaf67..10dbbb1af8 100644 --- a/src/api/providers/__tests__/lm-studio-timeout.spec.ts +++ b/src/api/providers/__tests__/lm-studio-timeout.spec.ts @@ -72,7 +72,7 @@ describe("LmStudioHandler timeout configuration", () => { ) }) - it("should handle zero timeout (no timeout)", () => { + it("should handle zero timeout (no timeout) by passing undefined to OpenAI client", () => { ;(getApiRequestTimeout as any).mockReturnValue(0) const options: ApiHandlerOptions = { @@ -84,7 +84,7 @@ describe("LmStudioHandler timeout configuration", () => { expect(mockOpenAIConstructor).toHaveBeenCalledWith( expect.objectContaining({ - timeout: 0, // No timeout + timeout: undefined, // OpenAI SDK expects undefined for no timeout, not 0 }), ) }) diff --git a/src/api/providers/__tests__/ollama-timeout.spec.ts b/src/api/providers/__tests__/ollama-timeout.spec.ts index db78f206c0..905a155a5f 100644 --- a/src/api/providers/__tests__/ollama-timeout.spec.ts +++ b/src/api/providers/__tests__/ollama-timeout.spec.ts @@ -71,7 +71,7 @@ describe("OllamaHandler timeout configuration", () => { ) }) - it("should handle zero timeout (no timeout)", () => { + it("should handle zero timeout (no timeout) by passing undefined to OpenAI client", () => { ;(getApiRequestTimeout as any).mockReturnValue(0) const options: ApiHandlerOptions = { @@ -84,7 +84,7 @@ describe("OllamaHandler timeout configuration", () => { expect(mockOpenAIConstructor).toHaveBeenCalledWith( expect.objectContaining({ - timeout: 0, // No timeout + timeout: undefined, // OpenAI SDK expects undefined for no timeout, not 0 }), ) }) diff --git a/src/api/providers/__tests__/openai-timeout.spec.ts b/src/api/providers/__tests__/openai-timeout.spec.ts index 2a09fd94ff..44d934ded8 100644 --- a/src/api/providers/__tests__/openai-timeout.spec.ts +++ b/src/api/providers/__tests__/openai-timeout.spec.ts @@ -125,7 +125,7 @@ describe("OpenAiHandler timeout configuration", () => { ) }) - it("should handle zero timeout (no timeout)", () => { + it("should handle zero timeout (no timeout) by passing undefined to OpenAI client", () => { ;(getApiRequestTimeout as any).mockReturnValue(0) const options: ApiHandlerOptions = { @@ -137,7 +137,7 @@ describe("OpenAiHandler timeout configuration", () => { expect(mockOpenAIConstructor).toHaveBeenCalledWith( expect.objectContaining({ - timeout: 0, // No timeout + timeout: undefined, // OpenAI SDK expects undefined for no timeout, not 0 }), ) }) diff --git a/src/api/providers/lm-studio.ts b/src/api/providers/lm-studio.ts index f3af46d1ce..1a08058f83 100644 --- a/src/api/providers/lm-studio.ts +++ b/src/api/providers/lm-studio.ts @@ -24,10 +24,12 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan super() this.options = options + const timeout = getApiRequestTimeout() this.client = new OpenAI({ baseURL: (this.options.lmStudioBaseUrl || "http://localhost:1234") + "/v1", apiKey: "noop", - timeout: getApiRequestTimeout(), + // OpenAI SDK expects undefined for no timeout, not 0 + timeout: timeout === 0 ? undefined : timeout, }) } diff --git a/src/api/providers/ollama.ts b/src/api/providers/ollama.ts index 54666be58d..4f8d2f213a 100644 --- a/src/api/providers/ollama.ts +++ b/src/api/providers/ollama.ts @@ -25,10 +25,12 @@ export class OllamaHandler extends BaseProvider implements SingleCompletionHandl super() this.options = options + const timeout = getApiRequestTimeout() this.client = new OpenAI({ baseURL: (this.options.ollamaBaseUrl || "http://localhost:11434") + "/v1", apiKey: "ollama", - timeout: getApiRequestTimeout(), + // OpenAI SDK expects undefined for no timeout, not 0 + timeout: timeout === 0 ? undefined : timeout, }) } diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index 36158d770c..527b549e57 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -48,6 +48,8 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl } const timeout = getApiRequestTimeout() + // OpenAI SDK expects undefined for no timeout, not 0 + const clientTimeout = timeout === 0 ? undefined : timeout if (isAzureAiInference) { // Azure AI Inference Service (e.g., for DeepSeek) uses a different path structure @@ -56,7 +58,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl apiKey, defaultHeaders: headers, defaultQuery: { "api-version": this.options.azureApiVersion || "2024-05-01-preview" }, - timeout, + timeout: clientTimeout, }) } else if (isAzureOpenAi) { // Azure API shape slightly differs from the core API shape: @@ -66,14 +68,14 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl apiKey, apiVersion: this.options.azureApiVersion || azureOpenAiDefaultApiVersion, defaultHeaders: headers, - timeout, + timeout: clientTimeout, }) } else { this.client = new OpenAI({ baseURL, apiKey, defaultHeaders: headers, - timeout, + timeout: clientTimeout, }) } }