Skip to content

Commit e3499d4

Browse files
committed
fix(coderd/ai): support overriding base URL for OpenAI provider, required for OpenRouter
1 parent b57fbd5 commit e3499d4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cli/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,7 @@ func ReadAIProvidersFromEnv(environ []string) ([]codersdk.AIProviderConfig, erro
26802680
case "BASE_URL":
26812681
provider.BaseURL = v.Value
26822682
case "MODELS":
2683-
provider.Models = strings.Split(v.Value, " ")
2683+
provider.Models = strings.Split(v.Value, ",")
26842684
}
26852685
providers[providerNum] = provider
26862686
}

coderd/ai/ai.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ func ModelsFromConfig(ctx context.Context, configs []codersdk.AIProviderConfig)
4040

4141
switch config.Type {
4242
case "openai":
43-
client := openai.NewClient(openaioption.WithAPIKey(config.APIKey))
43+
opts := []openaioption.RequestOption{
44+
openaioption.WithAPIKey(config.APIKey),
45+
}
46+
if config.BaseURL != "" {
47+
opts = append(opts, openaioption.WithBaseURL(config.BaseURL))
48+
}
49+
client := openai.NewClient(opts...)
4450
streamFunc = func(ctx context.Context, options StreamOptions) (aisdk.DataStream, error) {
4551
openaiMessages, err := aisdk.MessagesToOpenAI(options.Messages)
4652
if err != nil {

0 commit comments

Comments
 (0)