Skip to content

Commit ce65d8f

Browse files
committed
Add instructions for using a custom base URL and API key in README.md
1 parent e36659e commit ce65d8f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}");
6868

6969
While you can pass your API key directly as a string, it is highly recommended that you keep it in a secure location and instead access it via an environment variable or configuration file as shown above to avoid storing it in source control.
7070

71+
72+
### Using a custom base URL and API key
73+
74+
If you need to connect to an alternative API endpoint (for example, a proxy or self-hosted OpenAI-compatible LLM), you can specify a custom base URL and API key using the `ApiKeyCredential` and `OpenAIClientOptions`:
75+
76+
```csharp
77+
using OpenAI.Chat;
78+
using OpenAI;
79+
80+
var client = new ChatClient(
81+
model: CHAT_MODEL,
82+
credential: new ApiKeyCredential(Environment.GetEnvironmentVariable("API_KEY") ?? ""),
83+
options: new OpenAIClientOptions
84+
{
85+
Endpoint = new Uri(BASE_URL),
86+
}
87+
);
88+
```
89+
90+
Replace `CHAT_MODEL` with your model name and `BASE_URL` with your endpoint URI. This is useful when working with OpenAI-compatible APIs or custom deployments.
91+
7192
### Namespace organization
7293

7394
The library is organized into namespaces by feature areas in the OpenAI REST API. Each namespace contains a corresponding client class.

0 commit comments

Comments
 (0)