Skip to content

Commit 8c428b5

Browse files
authored
feat(openai): Add Config Option to Overwrite OpenAI's API Base (#3066)
* feat(openai): Add Config Option to Overwrite OpenAI's API Base * feat(openai): Add option to use custom base URL for OpenAI native API
1 parent 14afaca commit 8c428b5

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

evals/packages/types/src/roo-code.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ export const providerSettingsSchema = z.object({
358358
googleGeminiBaseUrl: z.string().optional(),
359359
// OpenAI Native
360360
openAiNativeApiKey: z.string().optional(),
361+
openAiNativeBaseUrl: z.string().optional(),
361362
// XAI
362363
xaiApiKey: z.string().optional(),
363364
// Mistral
@@ -445,6 +446,7 @@ const providerSettingsRecord: ProviderSettingsRecord = {
445446
googleGeminiBaseUrl: undefined,
446447
// OpenAI Native
447448
openAiNativeApiKey: undefined,
449+
openAiNativeBaseUrl: undefined,
448450
// Mistral
449451
mistralApiKey: undefined,
450452
mistralCodestralUrl: undefined,

src/api/providers/openai-native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
2929
super()
3030
this.options = options
3131
const apiKey = this.options.openAiNativeApiKey ?? "not-provided"
32-
this.client = new OpenAI({ apiKey })
32+
this.client = new OpenAI({ baseURL: this.options.openAiNativeBaseUrl, apiKey })
3333
}
3434

3535
override async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type ProviderSettings = {
105105
geminiApiKey?: string | undefined
106106
googleGeminiBaseUrl?: string | undefined
107107
openAiNativeApiKey?: string | undefined
108+
openAiNativeBaseUrl?: string | undefined
108109
mistralApiKey?: string | undefined
109110
mistralCodestralUrl?: string | undefined
110111
deepSeekBaseUrl?: string | undefined

src/exports/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type ProviderSettings = {
106106
geminiApiKey?: string | undefined
107107
googleGeminiBaseUrl?: string | undefined
108108
openAiNativeApiKey?: string | undefined
109+
openAiNativeBaseUrl?: string | undefined
109110
mistralApiKey?: string | undefined
110111
mistralCodestralUrl?: string | undefined
111112
deepSeekBaseUrl?: string | undefined

src/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ export const providerSettingsSchema = z.object({
401401
googleGeminiBaseUrl: z.string().optional(),
402402
// OpenAI Native
403403
openAiNativeApiKey: z.string().optional(),
404+
openAiNativeBaseUrl: z.string().optional(),
404405
// Mistral
405406
mistralApiKey: z.string().optional(),
406407
mistralCodestralUrl: z.string().optional(),
@@ -492,6 +493,7 @@ const providerSettingsRecord: ProviderSettingsRecord = {
492493
googleGeminiBaseUrl: undefined,
493494
// OpenAI Native
494495
openAiNativeApiKey: undefined,
496+
openAiNativeBaseUrl: undefined,
495497
// Mistral
496498
mistralApiKey: undefined,
497499
mistralCodestralUrl: undefined,

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ const ApiOptions = ({
7575
const [openAiModels, setOpenAiModels] = useState<Record<string, ModelInfo> | null>(null)
7676

7777
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl)
78+
const [openAiNativeBaseUrlSelected, setOpenAiNativeBaseUrlSelected] = useState(
79+
!!apiConfiguration?.openAiNativeBaseUrl,
80+
)
7881
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
7982
const [openRouterBaseUrlSelected, setOpenRouterBaseUrlSelected] = useState(!!apiConfiguration?.openRouterBaseUrl)
8083
const [openAiHostHeaderSelected, setOpenAiHostHeaderSelected] = useState(!!apiConfiguration?.openAiHostHeader)
@@ -490,6 +493,28 @@ const ApiOptions = ({
490493

491494
{selectedProvider === "openai-native" && (
492495
<>
496+
<Checkbox
497+
checked={openAiNativeBaseUrlSelected}
498+
onChange={(checked: boolean) => {
499+
setOpenAiNativeBaseUrlSelected(checked)
500+
501+
if (!checked) {
502+
setApiConfigurationField("openAiNativeBaseUrl", "")
503+
}
504+
}}>
505+
{t("settings:providers.useCustomBaseUrl")}
506+
</Checkbox>
507+
{openAiNativeBaseUrlSelected && (
508+
<>
509+
<VSCodeTextField
510+
value={apiConfiguration?.openAiNativeBaseUrl || ""}
511+
type="url"
512+
onInput={handleInputChange("openAiNativeBaseUrl")}
513+
placeholder="https://api.openai.com/v1"
514+
className="w-full mt-1"
515+
/>
516+
</>
517+
)}
493518
<VSCodeTextField
494519
value={apiConfiguration?.openAiNativeApiKey || ""}
495520
type="password"

0 commit comments

Comments
 (0)