openai / openai-dotnet

The official .NET library for the OpenAI API
https://www.nuget.org/packages/OpenAI
MIT License
707 stars 60 forks source link

Is it possible to use a Proxy-Server? #74

Closed aurora closed 1 week ago

aurora commented 1 week ago

I wonder if there is an easy way to use a proxy server for connecting to the API. In Azure.AI.OpenAI, it is possible via HttpClientTransport in Azure.Core.Pipeline, and other libraries (such as Semantic Kernel) allow specifying a custom HttpClient instance. But I can't find a way to use a similar method with this library.

trrwilson commented 1 week ago

Hello, @aurora!

System.ClientModel has a very similar pipeline concept and you can supply a custom HttpClient/transport via the client options instance:

OpenAIClientOptions options = new()
{
    Transport = new HttpClientPipelineTransport(myHttpClient),
};
OpenAIClient client = new(options);
aurora commented 1 week ago

Hi @trrwilson,

Oh, I somehow overlooked this option. It works perfectly. Many thanks for your quick reply and help!