Skip to content

Commit 195e201

Browse files
Petermarcujsquire
andauthored
Add instructions for using a custom base URL and API key in README.md (#467)
* Add instructions for using a custom base URL and API key in README.md * Remove extra blank --------- Co-authored-by: Jesse Squire <[email protected]>
1 parent 9ea9e27 commit 195e201

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ 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+
### Using a custom base URL and API key
72+
73+
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`:
74+
75+
```csharp
76+
using OpenAI.Chat;
77+
using OpenAI;
78+
79+
var client = new ChatClient(
80+
model: CHAT_MODEL,
81+
credential: new ApiKeyCredential(Environment.GetEnvironmentVariable("API_KEY") ?? ""),
82+
options: new OpenAIClientOptions
83+
{
84+
Endpoint = new Uri(BASE_URL),
85+
}
86+
);
87+
```
88+
89+
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.
90+
7191
### Namespace organization
7292

7393
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)