From ce65d8f41612173b219bd7357e71bb9477f1ab54 Mon Sep 17 00:00:00 2001 From: Peter Marcu Date: Fri, 20 Jun 2025 15:24:31 -0700 Subject: [PATCH 1/2] Add instructions for using a custom base URL and API key in README.md --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 60eea27e..79c734d4 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,27 @@ Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}"); 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. + +### Using a custom base URL and API key + +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`: + +```csharp +using OpenAI.Chat; +using OpenAI; + +var client = new ChatClient( + model: CHAT_MODEL, + credential: new ApiKeyCredential(Environment.GetEnvironmentVariable("API_KEY") ?? ""), + options: new OpenAIClientOptions + { + Endpoint = new Uri(BASE_URL), + } +); +``` + +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. + ### Namespace organization The library is organized into namespaces by feature areas in the OpenAI REST API. Each namespace contains a corresponding client class. From 519570f700d61e4e9f7f7e678413b5f934de683d Mon Sep 17 00:00:00 2001 From: Jesse Squire Date: Sun, 22 Jun 2025 10:57:06 -0700 Subject: [PATCH 2/2] Remove extra blank --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 79c734d4..3af35e2d 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,6 @@ Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}"); 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. - ### Using a custom base URL and API key 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`: