Skip to content

Commit 4610f75

Browse files
committed
document OpenAI-compatible base URL configuration
1 parent 7c4859e commit 4610f75

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Readme.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ var openAIService = new OpenAIService(new OpenAIOptions()
5959
});
6060
```
6161

62+
To use an OpenAI-compatible endpoint in different environments, set
63+
`BaseDomain` from an environment variable. `BaseDomain` should be the root URL
64+
and should not include the API version path because `ApiVersion` is appended by
65+
the SDK.
66+
67+
```csharp
68+
var openAIService = new OpenAIService(new OpenAIOptions()
69+
{
70+
ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY"),
71+
BaseDomain = Environment.GetEnvironmentVariable("OPENAI_BASE_URL") ?? "https://api.openai.com/"
72+
});
73+
```
74+
6275
### Using Dependency Injection
6376

6477
#### secrets.json
@@ -82,6 +95,14 @@ serviceCollection.AddOpenAIService();
8295
serviceCollection.AddOpenAIService(settings => { settings.ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY"); });
8396
```
8497

98+
```csharp
99+
serviceCollection.AddOpenAIService(settings =>
100+
{
101+
settings.ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY");
102+
settings.BaseDomain = Environment.GetEnvironmentVariable("OPENAI_BASE_URL") ?? "https://api.openai.com/";
103+
});
104+
```
105+
85106
After injecting your service, you can retrieve it from the service provider:
86107
```csharp
87108
var openAiService = serviceProvider.GetRequiredService<IOpenAIService>();

0 commit comments

Comments
 (0)