Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/openai-adapters/src/apis/OpenAI.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";

import { OpenAIApi } from "./OpenAI.js";

describe("OpenAIApi timeout conversion", () => {
const baseConfig = {
provider: "openai" as const,
apiKey: "test-key",
};

it("converts requestOptions.timeout from seconds to milliseconds", () => {
const api = new OpenAIApi({
...baseConfig,
requestOptions: { timeout: 300 },
});

expect(api.openai.timeout).toBe(300_000);
});

it("preserves an explicit zero timeout instead of falling back to the SDK default", () => {
const api = new OpenAIApi({
...baseConfig,
requestOptions: { timeout: 0 },
});

// The schema permits `timeout: 0`, and the SDK resolves its own default
// with `?? DEFAULT_TIMEOUT`, so 0 must survive as 0 rather than becoming
// undefined and silently turning into the 10-minute default.
expect(api.openai.timeout).toBe(0);
});

it("leaves the SDK default in place when no timeout is configured", () => {
const api = new OpenAIApi(baseConfig);

// 10 minutes — the OpenAI SDK's DEFAULT_TIMEOUT.
expect(api.openai.timeout).toBe(600_000);
});
});
9 changes: 8 additions & 1 deletion packages/openai-adapters/src/apis/OpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ export class OpenAIApi implements BaseLlmApi {
apiKey: config.apiKey ?? "",
baseURL: this.apiBase,
fetch: customFetch(config.requestOptions),
timeout: config?.requestOptions?.timeout || undefined,
// requestOptions.timeout is in seconds; the OpenAI SDK expects ms.
// Nullish rather than truthy: the schema permits `timeout: 0`, and both
// the SDK (`options.timeout ?? DEFAULT_TIMEOUT`) and our own
// getAgentOptions treat 0 as a real value, not as "unset".
timeout:
config?.requestOptions?.timeout != null
? config.requestOptions.timeout * 1000
: undefined,
});
}
modifyChatBody<T extends ChatCompletionCreateParams>(body: T): T {
Expand Down
Loading