← 开源

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
增长势头
+-124 小时新增 Star-0.1%
980
Star
20
Fork
+-1
本周
3
贡献者
创建于 2025-04-13 · 更新于 2026-12-04 · 今日第 28108 名
主要开发者
k3scatYoyo-514
README

One endpoint in front of a pool of API keys.
Rotation, rate limits, queueing, and failover for any HTTP API that authenticates with a key.

English · 中文 · 日本語

NyaProxy sits between your applications and an upstream API. Applications call it with a key you issue; it forwards each request with one of your upstream keys, chosen so that no key exceeds its quota. When every key is busy, requests wait in a queue instead of failing.

It forwards requests as they are, so it works with any HTTP API: OpenAI and OpenAI-compatible providers, Gemini, NovelAI, or an internal service. Use it only with credentials and traffic the upstream's terms allow.

  • Key pool. Spread traffic over many keys with one of five strategies.
  • Rate limits. Per upstream key, per API, per client IP, and per proxy key. A key can carry several windows at once, such as 40/m and 1000/d.
  • Queueing. Requests over quota wait for the next free key, in priority order, instead of returning an error.
  • Failover. Retry on the statuses you choose with the next key, and take a failing key out of rotation for a while.
  • Policy. Allow or block paths and methods, and rewrite JSON request bodies with conditional rules.
  • Live configuration. Edit settings in the browser; changes apply without a restart and without dropping requests in flight.
  • Visibility. A dashboard and a Prometheus /metrics endpoint.

Quick start

pip install nya-proxy
nyaproxy

The first run writes a starter config.yaml to the current directory and listens on http://127.0.0.1:8080. Open /config/ui to edit the configuration and /dashboard to watch traffic.

With Docker, put a config.yaml that sets server.api_key in ./data, then:

docker run -d -p 8080:8080 -v "$PWD/data:/app" --user "$(id -u):$(id -g)" k3scat/nya-proxy

See Deployment for Docker Compose, reverse proxies, and the security settings to review before exposing the service.

Configure an API

server:
  api_key:
    - admin-key  # the first key also opens the dashboard and config UI
    - app-key    # further keys are for proxy traffic only

apis:
  openai:
    name: OpenAI
    endpoint: https://api.openai.com/v1
    headers:
      Authorization: "Bearer ${{keys}}"
    variables:
      keys:
        - sk-first-upstream-key
        - sk-second-upstream-key
    rate_limit:
      enabled: true
      key_rate_limit: 60/m

A request to /api/openai/chat/completions is forwarded to https://api.openai.com/v1/chat/completions with one of the two keys. A client only changes its base URL and its key:

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8080/api/openai", api_key="app-key")

Complete examples for OpenAI-compatible providers, Gemini, and NovelAI are in configs/.

Documentation

Guide Covers
Configuration Every setting, how requests are routed, limits, retries, and error responses
Deployment Installing, Docker, authentication, reloading, monitoring, security
Body substitution Rules that set or remove fields in JSON request bodies

Project status

NyaProxy is feature-complete and in maintenance mode. It receives bug fixes, security fixes, and dependency updates; new features are not planned.

It is a transparent key-pool proxy and deliberately not an LLM gateway: token accounting, model routing, translation between provider formats, and multi-instance clustering are out of scope. Rate limits and queues live in memory, so run one instance per pool of keys.

Contributing

See CONTRIBUTING.md. Questions and bug reports go to the issue tracker or the Nya Foundation Discord.

License

MIT

排名相邻
同类项目

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载