AetherGate.Core 1.0.0

dotnet add package AetherGate.Core --version 1.0.0
                    
NuGet\Install-Package AetherGate.Core -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AetherGate.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AetherGate.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AetherGate.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AetherGate.Core --version 1.0.0
                    
#r "nuget: AetherGate.Core, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AetherGate.Core@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AetherGate.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AetherGate.Core&version=1.0.0
                    
Install as a Cake Tool

AetherGate.Core

AetherGate苍穹网关)是连接多模型生态的统一 AI 智能网关。AetherGate.Core 是其核心类库,负责注册网关服务、绑定和校验配置,并提供 OpenAI、Anthropic 和可选 Ollama 兼容接口的代理能力。

代码集成

在 ASP.NET Core 应用中注册服务并启用网关:

using AetherGate.Core.Configuration;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAetherGate(options =>
{
	options.Providers["default"] = new ProviderOptions
	{
		BaseUrl = "https://api.example.com",
		ApiKey = "your-upstream-key"
	};
});

var app = builder.Build();
app.UseAetherGate();
app.Run();

如果配置全部来自 appsettings.json 或环境变量,可以直接使用:

builder.Services.AddAetherGate();

AddAetherGate 会绑定 AetherGate 配置节,并注册上游代理、Ollama 兼容服务、默认模型转换、转发头和网络策略等服务。UseAetherGate 会注册网关路由及 IP 白名单、代理 API Key 鉴权中间件。

配置约定

配置根节点为 AetherGate

  • Upstream:默认 Provider、默认模型、上游 API Key 和超时设置。
  • Providers:以一个上游 BaseUrl 为单位配置 Provider。同一个 Provider 可以同时处理 OpenAI 和 Anthropic 协议以及多个模型。
  • Proxy:客户端 API Key、IP/CIDR 白名单、可信代理和 JSON 请求体大小限制。
  • Olloma:Olloma 兼容层开关、匿名访问和默认模型参数。

Provider 的 BaseUrl 必须是不包含 /v1、查询字符串或片段的 HTTP/HTTPS 服务根地址:

{
	"AetherGate": {
		"Upstream": {
			"DefaultProvider": "default",
			"OpenAIDefaultModel": "gpt-5-mini",
			"AnthropicDefaultModel": "claude-sonnet-model"
		},
		"Providers": {
			"default": {
				"BaseUrl": "https://api.example.com",
				"ApiKey": "your-upstream-key",
				"AnthropicVersion": "2023-06-01"
			}
		},
		"Ollama": {
			"Enabled": true,
			"AllowUnauthenticatedAccess": false
		}
	}
}

应用启动时会校验 Provider、BaseUrl、默认 Provider 的 API Key、超时和网络规则。敏感信息建议使用环境变量或其他安全配置源注入,不要直接提交到代码仓库。

路由

启用 UseAetherGate 后提供以下接口:

方法 路径 说明
GET /health 健康检查,不要求代理 API Key。
GET /v1/models 透传上游模型列表。
POST /v1/embeddings 透传 OpenAI Embeddings 请求。
POST /v1/chat/completions 透传普通或 SSE 流式对话请求。
POST /v1/responses 透传 OpenAI Responses 请求。
GET/POST/DELETE /v1/responses/* 透传 Responses 查询、取消、compact 等子路径。
POST /v1/messages 透传 Anthropic Messages 请求。
POST /v1/messages/count_tokens 透传 Anthropic token 计数请求。
GET/POST/DELETE /v1/messages/* 透传其他 Messages 子路径。
GET /api/version 返回 Ollama 兼容服务版本。
GET /api/tags 返回可供 Ollama 客户端选择的模型列表。
POST /api/show 返回模型上下文和工具能力。
POST /api/chat 将 Ollama 普通或流式聊天转换为 OpenAI Chat Completions。

其中 /api/* 路由仅在 AetherGate:Ollama:Enabled=true 时注册。

配置 AetherGate:Proxy:ApiKey 后,/v1/*/api/* 会检查客户端的 Bearer 或 x-api-key。只有显式配置 AetherGate:Ollama:AllowUnauthenticatedAccess=true 时,Ollama 路由才允许匿名访问;同时启用 Ollama 和匿名访问时,还会额外放行 POST /v1/chat/completions,以兼容无法发送 Key 的 Ollama 客户端。

AetherGate:Proxy:AllowedNetworks 配置的 IP/CIDR 白名单始终应用于 /v1/*/api/*,不受 Ollama 匿名访问设置影响;/health 不检查 IP 白名单和代理 API Key。

/v1/* 支持通过 X-Provider 选择已配置的 Provider,并通过 X-Provider-Api-Key 覆盖当前请求的上游 API Key。两者仅适用于 OpenAI/Anthropic 代理,不会转发到上游。

Ollama /api/* 始终使用服务端配置的默认 Provider,不读取请求级 Provider 或 API Key。

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 88 8/26/2026