← 开源
Nya-Foundation

NyaProxy

NyaProxy acts like a smart, central manager for accessing various online services (APIs) – think AI tools (like OpenAI, Gemini, Anthropic), image generators, or almost any web service that uses access keys. It helps you use these services more reliably, efficiently, and securely.

InfrastructureGatewayPython
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
986
Star
20
Fork
+0
本周
3
贡献者
创建于 2025-04-13 · 更新于 2026-10-12 · 今日第 12222 名
主要开发者
k3scatYoyo-514

Nya-Foundation/NyaProxy 排名第 12,222,有 986 个星标。

同类别比较

Nya-Foundation/NyaProxy 排名第 12,222,此处有 8 个同类条目;KenyonY/openai-forward 排名第 12,221。

同类别比较
名称排名指标
fencesandbox/fence12,184
语言:
Go
星标数:
992
分叉数:
44
简介:
Lightweight, container-free sandbox for running commands with network and filesystem restrictions
xing61/zzz-api12,208
星标数:
990
分叉数:
83
简介:
企业级稳定的OpenAI、Claude、Gemini等的API接口-For企业和开发者。OpenAI的api proxy,支持ChatGPT的API调用,支持Anthropic claude的官方接口形式,支持Google gemini的官方接口形式,支持:gpt-5,sora。不需要openai Key, 不需要买openai的账号,不需要美元的银行卡,通通不用的,直接调用就行,稳定好用!!智增增
senstella/parakeet-mlx12,220
语言:
Python
星标数:
987
分叉数:
62
简介:
An implementation of the Nvidia's Parakeet models for Apple Silicon using MLX.
KenyonY/openai-forward12,221
语言:
Python
星标数:
986
分叉数:
308
简介:
🚀 大语言模型高效转发服务 · An efficient forwarding service designed for LLMs. · OpenAI API Reverse Proxy
codeproject/CodeProject.AI-Server12,225
语言:
C#
星标数:
986
分叉数:
235
简介:
CodeProject.AI Server is a self contained service that software developers can include in, and distribute with, their applications in order to augment their apps with the power of AI.
anibali/docker-pytorch12,230
语言:
Dockerfile
星标数:
985
分叉数:
221
简介:
A Docker image for PyTorch
h2oai/sparkling-water12,247
语言:
Scala
星标数:
982
分叉数:
357
简介:
Sparkling Water provides H2O functionality inside Spark cluster
libxsmm/libxsmm12,255
语言:
C
星标数:
980
分叉数:
204
简介:
Library for specialized dense and sparse matrix operations, and deep learning primitives.
关键参数与规格
关键参数与规格
参数值
语言Python
类别Infrastructure
子类别Gateway
星标数986
分叉数20
贡献者3
创建日期2025-04-13
更新日期2026-10-12
1 天星标数0
7 天星标数0
排名12,222
上次排名12,146
排名变化-76
7 天星标排名13,321
上次 7 天星标排名13,333
7 天星标排名变化12
总星标排名11,268
上次总星标排名11,249
总星标排名变化-19
README 摘录

NyaProxy **A lightweight API gateway for services that authenticate with API keys, bearer tokens, or custom request headers. ** English | 简体中文 | 日本語 Centralize credential injection, quota-aware routing, rate limiting, retries, and observability for any HTTP API that uses keys or tokens. Overview NyaProxy sits between your applications and upstream APIs. Applications call NyaProxy with an internal proxy key; NyaProxy forwards each request to the configured upstream with the correct upstream credentials, rotating across a pool

of keys while enforcing rate limits, retries, and path policies. It is useful when a team needs one place to manage access to external or internal APIs such as AI providers, image generation APIs, SaaS APIs, data vendors, or private services. Use NyaProxy only with credentials and traffic patterns that are allowed by the upstream service terms. **Important:** the starter config has no , so authentication is disabled. This is safe only while bound to loopback. Set before using or otherwise

exposing the service. Pass to disable the file-watch supervisor for production setups where restarts should be explicit. Install From Source Docker Mount the **directory**, not itself. Saving from the UI writes a temporary file and renames it over the target, and that rename fails with against a bind-mounted file, so every save returns a 500. runs the container as you, since the image runs as uid 100 and could not otherwise write a directory you own. Docker Desktop

on macOS and Windows maps ownership for you, so you can drop that flag there. The directory holds and , which carries rate-limit windows and key cool-downs across restarts so a config change does not reset your quotas. Edit configuration on the host or through the UI; either way NyaProxy restarts itself to apply it. Settings under apply to every API; any API block can override them. Aliases are route segments such as , not paths such as . With the

config above, this proxy request: is forwarded to: with injected, chosen by the load balancer. Requests over the limit wait in a per-API queue (bounded by ) until quota frees up or passes; clients that exceed the IP/user quota get with a header. restricts which paths count against the limits (prefix match with a trailing ). If every attempt fails, the client receives ; upstream connection failures and timeouts surface as and respectively. Key Quarantine can temporarily remove a credential from

selection when the upstream returns any configured HTTP error status. It is disabled by default; a common setup enables it for and so an expired or revoked credential is not selected again for . This policy is independent of retries: add the same status to only when the current request should also fail over to another credential. API Examples Generic Bearer Token API Custom Header API OpenAI-Compatible API Streaming responses (SSE and chunked transfer) are forwarded transparently, so OpenAI-style

requests work as-is. The log file rotates at 10 MB with the last 5 files retained. logs request/response

常见问题

记录了多少星标和分叉?

Nya-Foundation/NyaProxy 有 986 个星标和 20 个分叉。

仓库排名是多少?

Nya-Foundation/NyaProxy 排名第 12,222。

记录的语言和类别是什么?

Nya-Foundation/NyaProxy 有 986 个星标,语言为 Python,类别为 Infrastructure。

哪个仓库排名最接近?

Nya-Foundation/NyaProxy 与 KenyonY/openai-forward 比较,后者排名第 12,221,有 986 个星标。

README

NyaProxy

A lightweight API gateway for services that authenticate with API keys, bearer tokens, or custom request headers.

English | 简体中文 | 日本語

Centralize credential injection, quota-aware routing, rate limiting, retries, and observability for any HTTP API that uses keys or tokens.

[![License](https://img.shields.io/github/license/Nya-Foundation/nyaproxy.svg)](https://github.com/Nya-Foundation/nyaproxy/blob/main/LICENSE)
[![PyPI version](https://img.shields.io/pypi/v/nya-proxy.svg)](https://pypi.org/project/nya-proxy/)
[![Python versions](https://img.shields.io/pypi/pyversions/nya-proxy.svg)](https://pypi.org/project/nya-proxy/)
[![PyPI Downloads](https://static.pepy.tech/badge/nya-proxy)](https://pepy.tech/projects/nya-proxy)
[![Docker Pulls](https://img.shields.io/docker/pulls/k3scat/nya-proxy)](https://hub.docker.com/r/k3scat/nya-proxy)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Nya-Foundation/NyaProxy)





[![Code Coverage](https://codecov.io/gh/Nya-Foundation/nyaproxy/branch/main/graph/badge.svg)](https://codecov.io/gh/Nya-Foundation/nyaproxy)
[![CodeQL & Dependencies Scan](https://github.com/nya-foundation/nyaproxy/actions/workflows/scan.yml/badge.svg)](https://github.com/nya-foundation/nyaproxy/actions/workflows/scan.yml)
[![CI/CD Builds](https://github.com/Nya-Foundation/nyaproxy/actions/workflows/publish.yml/badge.svg)](https://github.com/Nya-Foundation/nyaproxy/actions/workflows/publish.yml)

Overview

NyaProxy sits between your applications and upstream APIs. Applications call NyaProxy with an internal proxy key; NyaProxy forwards each request to the configured upstream with the correct upstream credentials, rotating across a pool of keys while enforcing rate limits, retries, and path policies.

It is useful when a team needs one place to manage access to external or internal APIs such as AI providers, image generation APIs, SaaS APIs, data vendors, or private services.

Use NyaProxy only with credentials and traffic patterns that are allowed by the upstream service terms.

Features

Feature Description Config
Credential injection Add upstream credentials through headers without exposing them to clients headers, variables
Credential pooling Route traffic across multiple upstream keys or tokens variables.
Load balancing round_robin, random, least_requests, fastest_response, and weighted selection load_balancing_strategy, key_weights
Rate limiting Endpoint, upstream key, client IP, and proxy user limits rate_limit
Queueing Hold requests until configured quota becomes available queue
Retry and failover Retry selected status codes, cool down the failing key, and rotate to the next one retry
Key quarantine Temporarily remove credentials that return configured upstream error statuses key_blocking
Request policy Allow or block paths and methods before forwarding allowed_paths, allowed_methods
Body transformation Set or remove JSON fields with conditional JMESPath rules request_body_substitution
Observability Web dashboard plus a Prometheus /metrics endpoint dashboard
Outbound proxy Send upstream traffic through an optional HTTP/SOCKS proxy server.proxy

Quick Start

Install From PyPI

pip install nya-proxy
nyaproxy

On first run, NyaProxy creates a starter config.yaml in the current directory and listens on 127.0.0.1:8080.

Important: the starter config has no server.api_key, so authentication is disabled. This is safe only while bound to loopback. Set server.api_key before using --host 0.0.0.0 or otherwise exposing the service.

Then open:

  • http://:8080/config — configuration UI with validation
  • http://:8080/dashboard — metrics, request history, and queue status
  • http://:8080/info — configured API list and service status

Run With Your Own Config

nyaproxy --config config.yaml

Config changes made through the /config UI (or to the file, once you re-save through the UI) trigger an automatic restart so they take effect immediately. Pass --no-reload to disable the file-watch supervisor for production setups where restarts should be explicit.

Install From Source

git clone https://github.com/Nya-Foundation/nyaproxy.git
cd nyaproxy
pip install -e .
nyaproxy          # or: python -m nya

Docker

mkdir -p data
cp configs/openai.yaml data/config.yaml  # then replace every placeholder key

docker run -d \
  -p 8080:8080 \
  -v ${PWD}/data:/app \
  --user "$(id -u):$(id -g)" \
  k3scat/nya-proxy:latest --config /app/config.yaml --host 0.0.0.0

Mount the directory, not config.yaml itself. Saving from the /config UI writes a temporary file and renames it over the target, and that rename fails with EBUSY against a bind-mounted file, so every save returns a 500. The mount must also be writable — a read-only mount blocks saves for the same reason.

--user runs the container as you, since the image runs as uid 100 and could not otherwise write a directory you own. Docker Desktop on macOS and Windows maps ownership for you, so you can drop that flag there.

The directory holds config.yaml and .nya_state.json, which carries rate-limit windows and key cool-downs across restarts so a config change does not reset your quotas. Edit configuration on the host or through the /config UI; either way NyaProxy restarts itself to apply it. Do not publish the port until server.api_key is set.

CLI Reference

Flag Description
--config, -c Path to the configuration file
--host, -H / --port, -p Bind address and port (defaults: 127.0.0.1 / 8080; environment: SERVER_HOST / SERVER_PORT)
--no-reload Disable the config file-watch supervisor; config changes then require a manual restart
--check-config Validate schema and cross-field configuration, then exit
--remote-url, -r / --remote-api-key, -k / --remote-app-name, -a Pull configuration from a remote config server instead of a local file (disables the local /config UI)
--version Print the version and exit

Configuration

NyaProxy is configured with a single YAML file, validated against a bundled JSON schema. Ready-made examples live in configs/.

Settings under default_settings apply to every API; any API block can override them. For IDE autocomplete and inline validation, keep this modeline as the first line of your config (the shipped examples already include it):

# yaml-language-server: $schema=https://raw.githubusercontent.com/Nya-Foundation/NyaProxy/main/nya/schema.json

A minimal working config:

server:
  api_key:
    - your_admin_proxy_key        # first key = master key (dashboard + config UI)
    - your_application_proxy_key  # additional keys for regular proxy traffic
  logging:
    enabled: true
    level: info
    log_file: app.log
  dashboard:
    enabled: true

default_settings:
  key_variable: keys
  load_balancing_strategy: round_robin
  queue:
    max_size: 200
    max_workers: 10
    expiry_seconds: 300
  rate_limit:
    enabled: true
    endpoint_rate_limit: 1000/h
    key_rate_limit: 60/m
    ip_rate_limit: 5000/d
    user_rate_limit: 5000/d
  retry:
    enabled: true
    attempts: 3
    retry_after_seconds: 1
    retry_status_codes: [429, 500, 502, 503, 504]
  key_blocking:
    enabled: true
    status_codes: [401, 403]
    duration_seconds: 300
  timeouts:
    request_timeout_seconds: 300

apis:
  example_service:
    name: Example Service
    endpoint: https://api.example.com/v1
    aliases:
      - example
    key_variable: keys
    headers:
      Authorization: "Bearer ${{keys}}"
    variables:
      keys:
        - upstream_key_1
        - upstream_key_2

Request Format

Requests are forwarded through /api// — or /api// for an alias. Aliases are route segments such as example, not paths such as /example.

With the config above, this proxy request:

POST http://localhost:8080/api/example_service/messages

is forwarded to:

POST https://api.example.com/v1/messages

with Authorization: Bearer injected, chosen by the load balancer.

Load Balancing

Five strategies are available per API via load_balancing_strategy:

  • round_robin (default) — cycle through keys in order
  • random — pick a key at random
  • least_requests — pick the key that has served the fewest requests
  • fastest_response — pick the key with the lowest average response time
  • weighted — distribute according to key_weights

For weighted, weights align with the order of the key list:

apis:
  example_service:
    load_balancing_strategy: weighted
    key_weights: [3, 1, 1]   # first key gets 3x the traffic of the others
    variables:
      keys: [key_a, key_b, key_c]

Rate Limiting

Four independent limiter scopes:

  • endpoint_rate_limit — total request rate for one upstream API
  • key_rate_limit — request rate for each upstream credential
  • ip_rate_limit — request rate per client IP
  • user_rate_limit — request rate per proxy API key

Formats: 10/s, 60/m, 1000/h, 5000/d, 1/15s (one request per 15 seconds), or "0" for unlimited. Requests over the limit wait in a per-API queue (bounded by queue.max_size) until quota frees up or queue.expiry_seconds passes; clients that exceed the IP/user quota get 429 with a Retry-After header. rate_limit_paths restricts which paths count against the limits (prefix match with a trailing *).

Retries and Failover

When an upstream response matches retry_status_codes (and the method is in retry_request_methods), NyaProxy cools the failing key down for retry_after_seconds, rotates to the next available key, and retries up to attempts times — without blocking other traffic on the same API. If every attempt fails, the client receives 429; upstream connection failures and timeouts surface as 502 and 504 respectively.

Key Quarantine

key_blocking can temporarily remove a credential from selection when the upstream returns any configured HTTP error status. It is disabled by default; a common setup enables it for 401 and 403 so an expired or revoked credential is not selected again for duration_seconds. This policy is independent of retries: add the same status to retry.retry_status_codes only when the current request should also fail over to another credential.

API Examples

Generic Bearer Token API

apis:
  data_vendor:
    name: Data Vendor API
    endpoint: https://api.vendor.example/v2
    key_variable: tokens
    headers:
      Authorization: "Bearer ${{tokens}}"
    variables:
      tokens:
        - vendor_token_1
        - vendor_token_2
    rate_limit:
      enabled: true
      endpoint_rate_limit: 5000/d
      key_rate_limit: 60/m

Custom Header API

apis:
  internal_service:
    name: Internal Service
    endpoint: https://internal.example.com
    key_variable: service_tokens
    headers:
      X-Service-Token: "${{service_tokens}}"
      X-Client-Name: "nyaproxy"
    variables:
      service_tokens:
        - service_token_1
        - service_token_2

OpenAI-Compatible API

apis:
  openai_compatible:
    name: OpenAI-Compatible Provider
    endpoint: https://api.provider.example/v1
    key_variable: keys
    headers:
      Authorization: "Bearer ${{keys}}"
    variables:
      keys:
        - provider_key_1
        - provider_key_2
    allowed_paths:
      enabled: true
      mode: whitelist
      paths:
        - "/chat/*"
        - "/images/*"
    request_body_substitution:
      enabled: true
      rules:
        - name: "Remove unsupported field"
          operation: remove
          path: "frequency_penalty"
          conditions:
            - field: "frequency_penalty"
              operator: "exists"

Streaming responses (SSE and chunked transfer) are forwarded transparently, so OpenAI-style stream: true requests work as-is.

Request Body Substitution

Substitution rules can set or remove JSON fields before forwarding — useful for provider compatibility, default values, and policy enforcement:

request_body_substitution:
  enabled: true
  rules:
    - name: "Cap temperature"
      operation: set
      path: "temperature"
      value: 0.7
      conditions:
        - field: "temperature"
          operator: "gt"
          value: 0.7

See Request Body Substitution for the full rule syntax.

Endpoints

Endpoint Auth Purpose
/api// proxy key Proxy requests to configured upstream APIs
/config master key Edit and validate configuration in the browser
/dashboard master key Metrics, request history, key usage, and queue state; queues can be cleared and metrics reset
/health none Liveness check for load balancers and orchestrators
/info none Configured API list and service status
/metrics none Prometheus exposition endpoint

Operations

  • Logging — configured under server.logging; enabled: false disables both console and file sinks. The log file rotates at 10 MB with the last 5 files retained. debug logs request/response metadata (with secrets redacted).
  • Config reload — a config change triggers a full process restart via the file-watch supervisor. In-flight requests are dropped and in-memory state (queues, rate-limit windows, metrics) resets. Use --no-reload if you'd rather restart explicitly.
  • State — all rate limiting, queueing, and metrics state is in-memory and per-process. Run a single instance per credential pool; running replicas would give each its own independent limits.

Security Notes

  • If server.api_key is not set, authentication is disabled entirely — every endpoint (including the config UI) is open to anyone who can reach the port. The default bind is loopback; always set a key before selecting a public bind with --host or SERVER_HOST.
  • server.trusted_proxies controls which proxy IPs or CIDR networks may supply client-IP forwarding headers. Leave it empty unless NyaProxy is behind a proxy you control.
  • The first key in server.api_key is the master key, required for the dashboard and configuration UI. Additional keys can be handed to applications for proxy traffic only.
  • Do not share upstream provider credentials with clients — keep them in the NyaProxy config or your deployment's secret manager.
  • Restrict server.cors.allow_origins to trusted origins when browsers call the proxy with credentials.
  • Use allowed_paths and allowed_methods to limit what clients can call.

Deployment Guides

Project Status

NyaProxy is in active development. Configuration and behavior may change between releases. Pin a tested version for production deployments and review the changelog before upgrading.

Community

License

NyaProxy is released under the MIT License.

排名相邻
同类项目