Skip to content

Commit c35f43a

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

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cli/server.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy