![]() |
VOOZH | about |
dotnet add package OpenAI-DotNet-Proxy --version 8.8.6
NuGet\Install-Package OpenAI-DotNet-Proxy -Version 8.8.6
<PackageReference Include="OpenAI-DotNet-Proxy" Version="8.8.6" />
<PackageVersion Include="OpenAI-DotNet-Proxy" Version="8.8.6" />Directory.Packages.props
<PackageReference Include="OpenAI-DotNet-Proxy" />Project file
paket add OpenAI-DotNet-Proxy --version 8.8.6
#r "nuget: OpenAI-DotNet-Proxy, 8.8.6"
#:package OpenAI-DotNet-Proxy@8.8.6
#addin nuget:?package=OpenAI-DotNet-Proxy&version=8.8.6Install as a Cake Addin
#tool nuget:?package=OpenAI-DotNet-Proxy&version=8.8.6Install as a Cake Tool
👁 NuGet version (OpenAI-DotNet-Proxy)
A simple Proxy API gateway for OpenAI-DotNet to make authenticated requests from a front end application without exposing your API keys.
Install package OpenAI-DotNet-Proxy from Nuget. Here's how via command line:
Install-Package OpenAI-DotNet-Proxy
Using either the OpenAI-DotNet or com.openai.unity packages directly in your front-end app may expose your API keys and other sensitive information. To mitigate this risk, it is recommended to set up an intermediate API that makes requests to OpenAI on behalf of your front-end app. This library can be utilized for both front-end and intermediary host configurations, ensuring secure communication with the OpenAI API.
In the front end example, you will need to securely authenticate your users using your preferred OAuth provider. Once the user is authenticated, exchange your custom auth token with your API key on the backend.
Follow these steps:
OpenAIAuthentication object and pass in the custom token with the prefix sess-.OpenAISettings object and specify the domain where your intermediate API is located.auth and settings objects to the OpenAIClient constructor when you create the client instance.Here's an example of how to set up the front end:
var authToken = await LoginAsync();
var auth = new OpenAIAuthentication($"sess-{authToken}");
var settings = new OpenAISettings(domain: "api.your-custom-domain.com");
var api = new OpenAIClient(auth, settings);
This setup allows your front end application to securely communicate with your backend that will be using the OpenAI-DotNet-Proxy, which then forwards requests to the OpenAI API. This ensures that your OpenAI API keys and other sensitive information remain secure throughout the process.
In this example, we demonstrate how to set up and use OpenAIProxy in a new ASP.NET Core web app. The proxy server will handle authentication and forward requests to the OpenAI API, ensuring that your API keys and other sensitive information remain secure.
Install-Package OpenAI-DotNet-Proxydotnet add package OpenAI-DotNet-Proxy<PackageReference Include="OpenAI-DotNet-Proxy" />AbstractAuthenticationFilter and override the ValidateAuthentication method. This will implement the IAuthenticationFilter that you will use to check user session token against your internal server.Program.cs, create a new proxy web application by calling OpenAIProxy.CreateWebApplication method, passing your custom AuthenticationFilter as a type argument.OpenAIAuthentication and OpenAISettings as you would normally with your API keys, org id, or Azure settings.public partial class Program
{
private class AuthenticationFilter : AbstractAuthenticationFilter
{
public override async Task ValidateAuthenticationAsync(IHeaderDictionary request)
{
await Task.CompletedTask; // remote resource call to verify token
// You will need to implement your own class to properly test
// custom issued tokens you've setup for your end users.
if (!request.Authorization.ToString().Contains(TestUserToken))
{
throw new AuthenticationException("User is not authorized");
}
}
}
public static void Main(string[] args)
{
var auth = OpenAIAuthentication.LoadFromEnvironment();
var settings = new OpenAISettings(/* your custom settings if using Azure OpenAI */);
using var openAIClient = new OpenAIClient(auth, settings);
OpenAIProxy.CreateWebApplication<AuthenticationFilter>(args, openAIClient).Run();
}
}
Once you have set up your proxy server, your end users can now make authenticated requests to your proxy api instead of directly to the OpenAI API. The proxy server will handle authentication and forward requests to the OpenAI API, ensuring that your API keys and other sensitive information remain secure.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 8.8.6 | 1,117 | 11/5/2025 | |
| 8.8.2 | 350 | 10/3/2025 | |
| 8.8.0 | 452 | 7/2/2025 | |
| 8.7.4 | 235 | 7/1/2025 | |
| 8.7.0 | 398 | 6/15/2025 | |
| 8.4.0 | 895 | 11/15/2024 | |
| 8.2.0 | 475 | 8/18/2024 | |
| 8.1.1 | 329 | 6/30/2024 | |
| 7.7.10 | 314 | 5/9/2024 | |
| 7.7.9 | 238 | 5/9/2024 | |
| 7.7.8 | 284 | 5/4/2024 | |
| 7.7.7 | 574 | 5/2/2024 | |
| 7.2.0 | 1,055 | 11/9/2023 | |
| 6.4.1 | 2,896 | 3/24/2023 | |
| 6.4.0 | 408 | 3/23/2023 | |
| 6.3.0 | 637 | 3/22/2023 | 6.3.0 is deprecated because it has critical bugs. |
Version 8.8.6
- Fix unimplemented routePrefix in OpenAIProxyStartup.CreateWebApplication
Version 8.8.2
- Updated forwarded request headers
Version 8.8.0
- Removed Websocket handling from the proxy
Version 8.7.4
- Updated proxy support for the OpenAI-DotNet package
- Ensure we're returning the full response message body and content length to the clients
Version 8.7.0
- Fix Azure OpenAI api-version query parameter not being forwarded correctly
Version 8.4.0
- Added support for Realtime Websocket proxy forwarding
Version 8.2.0
- Deprecated ValidateAuthentication for ValidateAuthenticationAsync
Version 8.1.1
- Renamed OpenAIProxyStartup to OpenAIProxy
Version 7.7.10
- Updated EndpointRouteBuilder with optional route prefix parameter
Version 7.7.9
- Slight refactor of OpenAIProxyStartup to remove duplicate code
- Added OpenAI.Proxy.EndpointRouteBuilder
Version 7.7.8
- Added OpenAIProxyStartup.CreateWebApplication to create modern WebApplication
- Updated OpenAI-DotNet-Test-Proxy to use WebApplication implementation
Version 7.7.7
- Added ValidateAuthenticationAsync