Skip to content
Closed
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
17 changes: 15 additions & 2 deletions src/api/providers/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
}

const isGrokXAI = this._isGrokXAI(this.options.openAiBaseUrl)
const isNvidiaApi = this._isNvidiaApi(this.options.openAiBaseUrl)

const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
model: modelId,
temperature: this.options.modelTemperature ?? (deepseekReasoner ? DEEP_SEEK_DEFAULT_TEMPERATURE : 0),
messages: convertedMessages,
stream: true as const,
...(isGrokXAI ? {} : { stream_options: { include_usage: true } }),
...(isGrokXAI || isNvidiaApi ? {} : { stream_options: { include_usage: true } }),
...(reasoning && reasoning),
}

Expand Down Expand Up @@ -317,6 +318,8 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
if (this.options.openAiStreamingEnabled ?? true) {
const isGrokXAI = this._isGrokXAI(this.options.openAiBaseUrl)

const isNvidiaApi = this._isNvidiaApi(this.options.openAiBaseUrl)

const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
model: modelId,
messages: [
Expand All @@ -327,7 +330,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
...convertToOpenAiMessages(messages),
],
stream: true,
...(isGrokXAI ? {} : { stream_options: { include_usage: true } }),
...(isGrokXAI || isNvidiaApi ? {} : { stream_options: { include_usage: true } }),
reasoning_effort: modelInfo.reasoningEffort as "low" | "medium" | "high" | undefined,
temperature: undefined,
}
Expand Down Expand Up @@ -423,6 +426,16 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
return urlHost.endsWith(".services.ai.azure.com")
}

private _isNvidiaApi(baseUrl?: string): boolean {
const urlHost = this._getUrlHost(baseUrl)
// NVIDIA API endpoints for AI models
return (
urlHost === "integrate.api.nvidia.com" ||
urlHost === "build.nvidia.com" ||
urlHost.endsWith(".api.nvidia.com")
)
}
Comment on lines +429 to +437
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new NVIDIA API detection functionality lacks test coverage. Similar to the existing Grok xAI tests (lines 527-565 in the test file), this change should include tests that verify: (1) _isNvidiaApi() correctly identifies NVIDIA endpoints, (2) stream_options is excluded when using NVIDIA API in both streaming and non-streaming modes, and (3) the behavior works correctly with O3 family models. Without tests, future changes could inadvertently break this compatibility fix.


/**
* Adds max_completion_tokens to the request body if needed based on provider configuration
* Note: max_tokens is deprecated in favor of max_completion_tokens as per OpenAI documentation
Expand Down