nya-proxy 0.4.0__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/PKG-INFO +59 -49
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/README.md +58 -47
- nya_proxy-0.4.2/nya/_version.py +1 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/common/constants.py +1 -1
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/common/exceptions.py +1 -1
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/common/models.py +12 -11
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/config/manager.py +28 -36
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/config.yaml +31 -22
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/core/control.py +64 -31
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/core/handler.py +48 -11
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/core/proxy.py +23 -13
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/core/queue.py +20 -16
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/core/request.py +15 -13
- nya_proxy-0.4.2/nya/core/streaming.py +141 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/dashboard/api.py +56 -20
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/schema.json +49 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/server/app.py +3 -4
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/server/auth.py +7 -55
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/services/lb.py +56 -38
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/services/metrics.py +1 -3
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/utils/helper.py +1 -91
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya_proxy.egg-info/PKG-INFO +59 -49
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya_proxy.egg-info/requires.txt +0 -1
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/pyproject.toml +1 -2
- nya_proxy-0.4.0/nya/_version.py +0 -1
- nya_proxy-0.4.0/nya/core/streaming.py +0 -145
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/LICENSE +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/common/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/config/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/core/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/dashboard/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/html/favicon.ico +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/html/index.html +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/html/login.html +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/html/static/css/styles.css +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/html/static/js/dashboard.js +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/html/static/logo.svg +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/server/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/services/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/services/limit.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/utils/__init__.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya/utils/header.py +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya_proxy.egg-info/SOURCES.txt +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya_proxy.egg-info/dependency_links.txt +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya_proxy.egg-info/entry_points.txt +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/nya_proxy.egg-info/top_level.txt +0 -0
- {nya_proxy-0.4.0 → nya_proxy-0.4.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nya-proxy
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: A lightweight, flexible API proxy with dynamic token rotation, load balancing, and rate limiting capabilities.
|
|
5
5
|
Author-email: "Nya Foundation Team (k3scat)" <k3scat@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -23,7 +23,6 @@ Requires-Dist: httpx-socks>=0.10.0
|
|
|
23
23
|
Requires-Dist: jinja2>=3.1.2
|
|
24
24
|
Requires-Dist: setuptools>=42.0.0
|
|
25
25
|
Requires-Dist: watchfiles>=0.18.0
|
|
26
|
-
Requires-Dist: brotli>=1.0.9
|
|
27
26
|
Requires-Dist: jmespath>=1.0.1
|
|
28
27
|
Requires-Dist: orjson<4,>=3.10
|
|
29
28
|
Requires-Dist: loguru>=0.7.0
|
|
@@ -188,7 +187,6 @@ docker run -d \
|
|
|
188
187
|
Configuration reference can be found under [Configs folder](configs/) folder
|
|
189
188
|
|
|
190
189
|
```yaml
|
|
191
|
-
# Basic config.yaml example for OpenAI API Compatible Endpoints
|
|
192
190
|
# NyaProxy Configuration File
|
|
193
191
|
# This file contains server settings and API endpoint configurations
|
|
194
192
|
|
|
@@ -213,9 +211,16 @@ server:
|
|
|
213
211
|
# Default configuration applied to all API endpoints unless overridden
|
|
214
212
|
default_settings:
|
|
215
213
|
key_variable: keys
|
|
216
|
-
key_concurrency: true #
|
|
217
|
-
randomness: 0.0 # Random delay of (0.0-x)s to introduce variability in request timing and avoid detection
|
|
214
|
+
key_concurrency: true # mark it as true if each key can handle multiple concurrent requests, otherwise the key will be locked until the request completes
|
|
215
|
+
randomness: 0.0 # Random delay of (0.0-x)s to introduce variability in request timing and avoid detection due to consistent request patterns due to rate limits
|
|
218
216
|
load_balancing_strategy: round_robin
|
|
217
|
+
# Path and method filtering
|
|
218
|
+
allowed_paths:
|
|
219
|
+
enabled: false # Set to true to enable request path filtering
|
|
220
|
+
mode: whitelist # if "whitelist", only allow listed paths; if "blacklist", block listed paths
|
|
221
|
+
paths:
|
|
222
|
+
- "*"
|
|
223
|
+
allowed_methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"] # Allowed HTTP methods for the API
|
|
219
224
|
queue:
|
|
220
225
|
max_size: 200
|
|
221
226
|
expiry_seconds: 300
|
|
@@ -237,26 +242,9 @@ default_settings:
|
|
|
237
242
|
timeouts:
|
|
238
243
|
request_timeout_seconds: 300
|
|
239
244
|
|
|
240
|
-
# Request body substitution settings
|
|
241
|
-
request_body_substitution:
|
|
242
|
-
enabled: false
|
|
243
|
-
# Substitution rules for request body with JMEPath
|
|
244
|
-
rules:
|
|
245
|
-
- name: "Remove frequency_penalty"
|
|
246
|
-
operation: remove
|
|
247
|
-
path: "frequency_penalty"
|
|
248
|
-
conditions:
|
|
249
|
-
- field: "frequency_penalty"
|
|
250
|
-
operator: "exists"
|
|
251
|
-
- name: "Remove presence_penalty"
|
|
252
|
-
operation: remove
|
|
253
|
-
path: "presence_penalty"
|
|
254
|
-
conditions:
|
|
255
|
-
- field: "presence_penalty"
|
|
256
|
-
operator: "exists"
|
|
257
245
|
apis:
|
|
258
246
|
gemini:
|
|
259
|
-
# OpenAI-compatible API endpoint
|
|
247
|
+
# Example for OpenAI-compatible API endpoint
|
|
260
248
|
name: Google Gemini API
|
|
261
249
|
# Supported endpoints:
|
|
262
250
|
# Gemini: https://generativelanguage.googleapis.com/v1beta/openai
|
|
@@ -281,7 +269,7 @@ apis:
|
|
|
281
269
|
rate_limit:
|
|
282
270
|
enabled: true
|
|
283
271
|
# For Gemini-2.5-pro-exp-03-25, rate limits per key are 5 RPM and 25 RPD
|
|
284
|
-
# Endpoint rate limit should be n ×
|
|
272
|
+
# Endpoint rate limit should be n × per-key-RPD, where n is the number of keys
|
|
285
273
|
endpoint_rate_limit: 75/d
|
|
286
274
|
key_rate_limit: 5/m
|
|
287
275
|
# Paths to apply rate limits (regex supported) - defaults to all paths "*"
|
|
@@ -289,6 +277,25 @@ apis:
|
|
|
289
277
|
- "/chat/*"
|
|
290
278
|
- "/images/*"
|
|
291
279
|
|
|
280
|
+
# Request body substitution settings
|
|
281
|
+
request_body_substitution:
|
|
282
|
+
enabled: false
|
|
283
|
+
# Substitution rules for request body with JMEPath
|
|
284
|
+
rules:
|
|
285
|
+
# Since Gemini API doesn't support frequency_penalty and presence_penalty, we remove them with these rules
|
|
286
|
+
- name: "Remove frequency_penalty"
|
|
287
|
+
operation: remove
|
|
288
|
+
path: "frequency_penalty"
|
|
289
|
+
conditions:
|
|
290
|
+
- field: "frequency_penalty"
|
|
291
|
+
operator: "exists"
|
|
292
|
+
- name: "Remove presence_penalty"
|
|
293
|
+
operation: remove
|
|
294
|
+
path: "presence_penalty"
|
|
295
|
+
conditions:
|
|
296
|
+
- field: "presence_penalty"
|
|
297
|
+
operator: "exists"
|
|
298
|
+
|
|
292
299
|
test:
|
|
293
300
|
name: Test API
|
|
294
301
|
endpoint: http://127.0.0.1:8082
|
|
@@ -296,7 +303,7 @@ apis:
|
|
|
296
303
|
randomness: 5
|
|
297
304
|
headers:
|
|
298
305
|
Authorization: 'Bearer ${{keys}}'
|
|
299
|
-
User-Agent: ${{agents}}
|
|
306
|
+
User-Agent: ${{agents}} # flexible headers customization with template variables supported
|
|
300
307
|
variables:
|
|
301
308
|
keys:
|
|
302
309
|
- your_test_key_1
|
|
@@ -397,7 +404,32 @@ server:
|
|
|
397
404
|
|
|
398
405
|
## Advanced Features
|
|
399
406
|
|
|
400
|
-
###
|
|
407
|
+
### 🚦 Rate Limiting Capabilities
|
|
408
|
+
|
|
409
|
+
NyaProxy provides comprehensive rate limiting at multiple levels to protect your APIs and ensure fair usage:
|
|
410
|
+
|
|
411
|
+
**Multi-Level Rate Limiting:**
|
|
412
|
+
- **Endpoint Rate Limit**: Controls total requests across all keys for an API endpoint
|
|
413
|
+
- **Key Rate Limit**: Limits requests per individual API key to respect provider restrictions
|
|
414
|
+
- **IP Rate Limit**: Prevents abuse by limiting requests per client IP address
|
|
415
|
+
- **User Rate Limit**: Controls usage per NyaProxy API key for multi-tenant scenarios
|
|
416
|
+
|
|
417
|
+
**Flexible Rate Limit Formats:**
|
|
418
|
+
- Per second: `1/15s` (1 requests per 15 second)
|
|
419
|
+
- Per minute: `5/m` (5 requests per minute)
|
|
420
|
+
- Per hour: `100/h` (100 requests per hour)
|
|
421
|
+
- Per day: `1000/d` (1000 requests per day)
|
|
422
|
+
|
|
423
|
+
**Path-Specific Limiting:**
|
|
424
|
+
Apply rate limits only to specific endpoints using regex patterns:
|
|
425
|
+
```yaml
|
|
426
|
+
rate_limit_paths:
|
|
427
|
+
- "/chat/*" # Only limit chat endpoints
|
|
428
|
+
- "/images/*" # Only limit image generation
|
|
429
|
+
- "/v1/models" # Limit specific endpoint
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### 🔄 Dynamic Header Substitution
|
|
401
433
|
|
|
402
434
|
NyaProxy's powerful templating system allows you to create dynamic headers with variable substitution:
|
|
403
435
|
|
|
@@ -424,7 +456,7 @@ Use cases include:
|
|
|
424
456
|
- Cycling through user agents to avoid detection
|
|
425
457
|
- Alternating between different account identifiers
|
|
426
458
|
|
|
427
|
-
### Request Body Substitution
|
|
459
|
+
### 🔧 Request Body Substitution
|
|
428
460
|
Dynamically transform JSON payloads using JMESPath expressions to add, replace, or remove fields:
|
|
429
461
|
|
|
430
462
|
```yaml
|
|
@@ -463,28 +495,6 @@ Manage at `http://localhost:8080/config`:
|
|
|
463
495
|
- Rate limit adjustments
|
|
464
496
|
- Auto reload on save
|
|
465
497
|
|
|
466
|
-
## 🛡️ Reference Architecture
|
|
467
|
-
```mermaid
|
|
468
|
-
graph TD
|
|
469
|
-
A[Client] --> B[Nginx]
|
|
470
|
-
B --> C[NyaProxyAuth]
|
|
471
|
-
C --> D[NyaProxyApp]
|
|
472
|
-
D --> E[API Providers]
|
|
473
|
-
F[Monitoring] --> D
|
|
474
|
-
```
|
|
475
|
-
|
|
476
|
-
## 🌌 Future Roadmap
|
|
477
|
-
|
|
478
|
-
```mermaid
|
|
479
|
-
graph LR
|
|
480
|
-
A[Q1 2025] --> B[📡 Documentation Enhancement ]
|
|
481
|
-
A --> C[🔄 Border Test Coverage ]
|
|
482
|
-
B --> D[📈 API Key Usage/Balance Tracking]
|
|
483
|
-
C --> E[📊 UI/UX Enhancement ]
|
|
484
|
-
F[Q2 2025] --> G[🧩 Plugin System]
|
|
485
|
-
F --> H[🔍 Custom Metrics API]
|
|
486
|
-
```
|
|
487
|
-
|
|
488
498
|
## ❤️ Community
|
|
489
499
|
|
|
490
500
|
[](https://discord.gg/jXAxVPSs7K)
|
|
@@ -146,7 +146,6 @@ docker run -d \
|
|
|
146
146
|
Configuration reference can be found under [Configs folder](configs/) folder
|
|
147
147
|
|
|
148
148
|
```yaml
|
|
149
|
-
# Basic config.yaml example for OpenAI API Compatible Endpoints
|
|
150
149
|
# NyaProxy Configuration File
|
|
151
150
|
# This file contains server settings and API endpoint configurations
|
|
152
151
|
|
|
@@ -171,9 +170,16 @@ server:
|
|
|
171
170
|
# Default configuration applied to all API endpoints unless overridden
|
|
172
171
|
default_settings:
|
|
173
172
|
key_variable: keys
|
|
174
|
-
key_concurrency: true #
|
|
175
|
-
randomness: 0.0 # Random delay of (0.0-x)s to introduce variability in request timing and avoid detection
|
|
173
|
+
key_concurrency: true # mark it as true if each key can handle multiple concurrent requests, otherwise the key will be locked until the request completes
|
|
174
|
+
randomness: 0.0 # Random delay of (0.0-x)s to introduce variability in request timing and avoid detection due to consistent request patterns due to rate limits
|
|
176
175
|
load_balancing_strategy: round_robin
|
|
176
|
+
# Path and method filtering
|
|
177
|
+
allowed_paths:
|
|
178
|
+
enabled: false # Set to true to enable request path filtering
|
|
179
|
+
mode: whitelist # if "whitelist", only allow listed paths; if "blacklist", block listed paths
|
|
180
|
+
paths:
|
|
181
|
+
- "*"
|
|
182
|
+
allowed_methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"] # Allowed HTTP methods for the API
|
|
177
183
|
queue:
|
|
178
184
|
max_size: 200
|
|
179
185
|
expiry_seconds: 300
|
|
@@ -195,26 +201,9 @@ default_settings:
|
|
|
195
201
|
timeouts:
|
|
196
202
|
request_timeout_seconds: 300
|
|
197
203
|
|
|
198
|
-
# Request body substitution settings
|
|
199
|
-
request_body_substitution:
|
|
200
|
-
enabled: false
|
|
201
|
-
# Substitution rules for request body with JMEPath
|
|
202
|
-
rules:
|
|
203
|
-
- name: "Remove frequency_penalty"
|
|
204
|
-
operation: remove
|
|
205
|
-
path: "frequency_penalty"
|
|
206
|
-
conditions:
|
|
207
|
-
- field: "frequency_penalty"
|
|
208
|
-
operator: "exists"
|
|
209
|
-
- name: "Remove presence_penalty"
|
|
210
|
-
operation: remove
|
|
211
|
-
path: "presence_penalty"
|
|
212
|
-
conditions:
|
|
213
|
-
- field: "presence_penalty"
|
|
214
|
-
operator: "exists"
|
|
215
204
|
apis:
|
|
216
205
|
gemini:
|
|
217
|
-
# OpenAI-compatible API endpoint
|
|
206
|
+
# Example for OpenAI-compatible API endpoint
|
|
218
207
|
name: Google Gemini API
|
|
219
208
|
# Supported endpoints:
|
|
220
209
|
# Gemini: https://generativelanguage.googleapis.com/v1beta/openai
|
|
@@ -239,7 +228,7 @@ apis:
|
|
|
239
228
|
rate_limit:
|
|
240
229
|
enabled: true
|
|
241
230
|
# For Gemini-2.5-pro-exp-03-25, rate limits per key are 5 RPM and 25 RPD
|
|
242
|
-
# Endpoint rate limit should be n ×
|
|
231
|
+
# Endpoint rate limit should be n × per-key-RPD, where n is the number of keys
|
|
243
232
|
endpoint_rate_limit: 75/d
|
|
244
233
|
key_rate_limit: 5/m
|
|
245
234
|
# Paths to apply rate limits (regex supported) - defaults to all paths "*"
|
|
@@ -247,6 +236,25 @@ apis:
|
|
|
247
236
|
- "/chat/*"
|
|
248
237
|
- "/images/*"
|
|
249
238
|
|
|
239
|
+
# Request body substitution settings
|
|
240
|
+
request_body_substitution:
|
|
241
|
+
enabled: false
|
|
242
|
+
# Substitution rules for request body with JMEPath
|
|
243
|
+
rules:
|
|
244
|
+
# Since Gemini API doesn't support frequency_penalty and presence_penalty, we remove them with these rules
|
|
245
|
+
- name: "Remove frequency_penalty"
|
|
246
|
+
operation: remove
|
|
247
|
+
path: "frequency_penalty"
|
|
248
|
+
conditions:
|
|
249
|
+
- field: "frequency_penalty"
|
|
250
|
+
operator: "exists"
|
|
251
|
+
- name: "Remove presence_penalty"
|
|
252
|
+
operation: remove
|
|
253
|
+
path: "presence_penalty"
|
|
254
|
+
conditions:
|
|
255
|
+
- field: "presence_penalty"
|
|
256
|
+
operator: "exists"
|
|
257
|
+
|
|
250
258
|
test:
|
|
251
259
|
name: Test API
|
|
252
260
|
endpoint: http://127.0.0.1:8082
|
|
@@ -254,7 +262,7 @@ apis:
|
|
|
254
262
|
randomness: 5
|
|
255
263
|
headers:
|
|
256
264
|
Authorization: 'Bearer ${{keys}}'
|
|
257
|
-
User-Agent: ${{agents}}
|
|
265
|
+
User-Agent: ${{agents}} # flexible headers customization with template variables supported
|
|
258
266
|
variables:
|
|
259
267
|
keys:
|
|
260
268
|
- your_test_key_1
|
|
@@ -355,7 +363,32 @@ server:
|
|
|
355
363
|
|
|
356
364
|
## Advanced Features
|
|
357
365
|
|
|
358
|
-
###
|
|
366
|
+
### 🚦 Rate Limiting Capabilities
|
|
367
|
+
|
|
368
|
+
NyaProxy provides comprehensive rate limiting at multiple levels to protect your APIs and ensure fair usage:
|
|
369
|
+
|
|
370
|
+
**Multi-Level Rate Limiting:**
|
|
371
|
+
- **Endpoint Rate Limit**: Controls total requests across all keys for an API endpoint
|
|
372
|
+
- **Key Rate Limit**: Limits requests per individual API key to respect provider restrictions
|
|
373
|
+
- **IP Rate Limit**: Prevents abuse by limiting requests per client IP address
|
|
374
|
+
- **User Rate Limit**: Controls usage per NyaProxy API key for multi-tenant scenarios
|
|
375
|
+
|
|
376
|
+
**Flexible Rate Limit Formats:**
|
|
377
|
+
- Per second: `1/15s` (1 requests per 15 second)
|
|
378
|
+
- Per minute: `5/m` (5 requests per minute)
|
|
379
|
+
- Per hour: `100/h` (100 requests per hour)
|
|
380
|
+
- Per day: `1000/d` (1000 requests per day)
|
|
381
|
+
|
|
382
|
+
**Path-Specific Limiting:**
|
|
383
|
+
Apply rate limits only to specific endpoints using regex patterns:
|
|
384
|
+
```yaml
|
|
385
|
+
rate_limit_paths:
|
|
386
|
+
- "/chat/*" # Only limit chat endpoints
|
|
387
|
+
- "/images/*" # Only limit image generation
|
|
388
|
+
- "/v1/models" # Limit specific endpoint
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### 🔄 Dynamic Header Substitution
|
|
359
392
|
|
|
360
393
|
NyaProxy's powerful templating system allows you to create dynamic headers with variable substitution:
|
|
361
394
|
|
|
@@ -382,7 +415,7 @@ Use cases include:
|
|
|
382
415
|
- Cycling through user agents to avoid detection
|
|
383
416
|
- Alternating between different account identifiers
|
|
384
417
|
|
|
385
|
-
### Request Body Substitution
|
|
418
|
+
### 🔧 Request Body Substitution
|
|
386
419
|
Dynamically transform JSON payloads using JMESPath expressions to add, replace, or remove fields:
|
|
387
420
|
|
|
388
421
|
```yaml
|
|
@@ -421,28 +454,6 @@ Manage at `http://localhost:8080/config`:
|
|
|
421
454
|
- Rate limit adjustments
|
|
422
455
|
- Auto reload on save
|
|
423
456
|
|
|
424
|
-
## 🛡️ Reference Architecture
|
|
425
|
-
```mermaid
|
|
426
|
-
graph TD
|
|
427
|
-
A[Client] --> B[Nginx]
|
|
428
|
-
B --> C[NyaProxyAuth]
|
|
429
|
-
C --> D[NyaProxyApp]
|
|
430
|
-
D --> E[API Providers]
|
|
431
|
-
F[Monitoring] --> D
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
## 🌌 Future Roadmap
|
|
435
|
-
|
|
436
|
-
```mermaid
|
|
437
|
-
graph LR
|
|
438
|
-
A[Q1 2025] --> B[📡 Documentation Enhancement ]
|
|
439
|
-
A --> C[🔄 Border Test Coverage ]
|
|
440
|
-
B --> D[📈 API Key Usage/Balance Tracking]
|
|
441
|
-
C --> E[📊 UI/UX Enhancement ]
|
|
442
|
-
F[Q2 2025] --> G[🧩 Plugin System]
|
|
443
|
-
F --> H[🔍 Custom Metrics API]
|
|
444
|
-
```
|
|
445
|
-
|
|
446
457
|
## ❤️ Community
|
|
447
458
|
|
|
448
459
|
[](https://discord.gg/jXAxVPSs7K)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.2"
|
|
@@ -29,33 +29,34 @@ class ProxyRequest:
|
|
|
29
29
|
content: Optional[bytes],
|
|
30
30
|
ip: str = None,
|
|
31
31
|
):
|
|
32
|
-
self.method = method
|
|
32
|
+
self.method: str = method
|
|
33
33
|
|
|
34
34
|
# Lower number = higher priority (1=retry, 2=priority, 3=normal)
|
|
35
|
-
self.priority = 3
|
|
35
|
+
self.priority: int = 3
|
|
36
36
|
|
|
37
37
|
# original url from the proxy request
|
|
38
|
-
self._url = _url
|
|
38
|
+
self._url: "URL" = _url
|
|
39
39
|
|
|
40
40
|
# final url to be requested, will be set later
|
|
41
|
-
self.url = None
|
|
41
|
+
self.url: Optional[str] = None
|
|
42
42
|
|
|
43
|
-
self.headers = headers
|
|
44
|
-
self.content = content
|
|
43
|
+
self.headers: Headers = headers
|
|
44
|
+
self.content: Optional[bytes] = content
|
|
45
45
|
|
|
46
46
|
# API Related metadata
|
|
47
|
-
self.api_name: str =
|
|
47
|
+
self.api_name: str = None
|
|
48
48
|
self.api_key: Optional[str] = None
|
|
49
49
|
|
|
50
|
+
self.ip: str = ip
|
|
50
51
|
self.user: Optional[str] = None
|
|
51
|
-
self.ip = ip
|
|
52
52
|
|
|
53
53
|
# Number of attempts made for this request
|
|
54
|
-
self.attempts = 0
|
|
54
|
+
self.attempts: int = 0
|
|
55
55
|
# Timestamp when added to queue
|
|
56
|
-
self.added_at = time.time()
|
|
56
|
+
self.added_at: float = time.time()
|
|
57
|
+
|
|
57
58
|
# Whether to apply rate limiting for this request
|
|
58
|
-
self._rate_limited = False
|
|
59
|
+
self._rate_limited: bool = False
|
|
59
60
|
|
|
60
61
|
self.future: Optional[asyncio.Future] = None
|
|
61
62
|
|
|
@@ -16,21 +16,9 @@ T = TypeVar("T")
|
|
|
16
16
|
|
|
17
17
|
class ConfigManager:
|
|
18
18
|
"""
|
|
19
|
-
Manages configuration for NyaProxy using NekoConf.
|
|
20
|
-
Implements the singleton pattern to ensure only one instance exists.
|
|
19
|
+
Manages configuration for NyaProxy using NekoConf (singleton pattern).
|
|
21
20
|
"""
|
|
22
21
|
|
|
23
|
-
_instance = None
|
|
24
|
-
_initialized = False
|
|
25
|
-
|
|
26
|
-
def __new__(cls, *args, **kwargs):
|
|
27
|
-
"""
|
|
28
|
-
Create a singleton instance.
|
|
29
|
-
"""
|
|
30
|
-
if cls._instance is None:
|
|
31
|
-
cls._instance = super(ConfigManager, cls).__new__(cls)
|
|
32
|
-
return cls._instance
|
|
33
|
-
|
|
34
22
|
def __init__(
|
|
35
23
|
self,
|
|
36
24
|
config_path: Optional[str] = None,
|
|
@@ -51,9 +39,6 @@ class ConfigManager:
|
|
|
51
39
|
remote_app_name: Name of the application for remote configuration (optional)
|
|
52
40
|
callback: Callback function to call after configuraiton is updated (optional)
|
|
53
41
|
"""
|
|
54
|
-
# Skip initialization if already initialized
|
|
55
|
-
if self._initialized:
|
|
56
|
-
return
|
|
57
42
|
|
|
58
43
|
self.config: NekoConf = None
|
|
59
44
|
self.server: NekoConfOrchestrator = None
|
|
@@ -72,26 +57,6 @@ class ConfigManager:
|
|
|
72
57
|
self.config = self.init_config_client()
|
|
73
58
|
self.server = self.init_config_server()
|
|
74
59
|
|
|
75
|
-
# Mark as initialized
|
|
76
|
-
ConfigManager._initialized = True
|
|
77
|
-
|
|
78
|
-
@classmethod
|
|
79
|
-
def reset(cls):
|
|
80
|
-
"""
|
|
81
|
-
Reset the singleton instance (useful for testing).
|
|
82
|
-
"""
|
|
83
|
-
cls._instance = None
|
|
84
|
-
cls._initialized = False
|
|
85
|
-
|
|
86
|
-
@classmethod
|
|
87
|
-
def get_instance(cls) -> "ConfigManager":
|
|
88
|
-
"""
|
|
89
|
-
Get the singleton instance, creating it if needed.
|
|
90
|
-
"""
|
|
91
|
-
if cls._instance is None:
|
|
92
|
-
cls._instance = ConfigManager()
|
|
93
|
-
return cls._instance
|
|
94
|
-
|
|
95
60
|
def init_config_client(self) -> NekoConf:
|
|
96
61
|
"""
|
|
97
62
|
Initialize the NekoConf.
|
|
@@ -137,6 +102,9 @@ class ConfigManager:
|
|
|
137
102
|
return client
|
|
138
103
|
|
|
139
104
|
def init_config_server(self) -> NekoConfOrchestrator:
|
|
105
|
+
"""
|
|
106
|
+
Initialize the NekoConfOrchestrator WebUI for the server.
|
|
107
|
+
"""
|
|
140
108
|
|
|
141
109
|
if self.remote_url is not None:
|
|
142
110
|
logger.warning(
|
|
@@ -379,6 +347,30 @@ class ConfigManager:
|
|
|
379
347
|
"""
|
|
380
348
|
return self.get_api_setting(api_name, "load_balancing_strategy", "str")
|
|
381
349
|
|
|
350
|
+
def get_api_allowed_paths(self, api_name: str) -> List[str]:
|
|
351
|
+
"""
|
|
352
|
+
Get the list of allowed paths for the API.
|
|
353
|
+
"""
|
|
354
|
+
return self.get_api_setting(api_name, "allowed_paths.paths", "list")
|
|
355
|
+
|
|
356
|
+
def get_api_allowed_paths_enabled(self, api_name: str) -> bool:
|
|
357
|
+
"""
|
|
358
|
+
Check if allowed paths are enabled for the API.
|
|
359
|
+
"""
|
|
360
|
+
return self.get_api_setting(api_name, "allowed_paths.enabled", "bool")
|
|
361
|
+
|
|
362
|
+
def get_api_allowed_paths_mode(self, api_name: str) -> str:
|
|
363
|
+
"""
|
|
364
|
+
Get the mode for allowed paths for the API (whitelist/blacklist).
|
|
365
|
+
"""
|
|
366
|
+
return self.get_api_setting(api_name, "allowed_paths.mode", "str")
|
|
367
|
+
|
|
368
|
+
def get_api_allowed_methods(self, api_name: str) -> List[str]:
|
|
369
|
+
"""
|
|
370
|
+
Get the list of allowed methods for the API.
|
|
371
|
+
"""
|
|
372
|
+
return self.get_api_setting(api_name, "allowed_methods", "list")
|
|
373
|
+
|
|
382
374
|
def get_api_queue_size(self, api_name: str) -> int:
|
|
383
375
|
"""
|
|
384
376
|
Get the queue size for the API.
|
|
@@ -22,9 +22,16 @@ server:
|
|
|
22
22
|
# Default configuration applied to all API endpoints unless overridden
|
|
23
23
|
default_settings:
|
|
24
24
|
key_variable: keys
|
|
25
|
-
key_concurrency: true #
|
|
26
|
-
randomness: 0.0 # Random delay of (0.0-x)s to introduce variability in request timing and avoid detection
|
|
25
|
+
key_concurrency: true # mark it as true if each key can handle multiple concurrent requests, otherwise the key will be locked until the request completes
|
|
26
|
+
randomness: 0.0 # Random delay of (0.0-x)s to introduce variability in request timing and avoid detection due to consistent request patterns due to rate limits
|
|
27
27
|
load_balancing_strategy: round_robin
|
|
28
|
+
# Path and method filtering
|
|
29
|
+
allowed_paths:
|
|
30
|
+
enabled: false # Set to true to enable request path filtering
|
|
31
|
+
mode: whitelist # if "whitelist", only allow listed paths; if "blacklist", block listed paths
|
|
32
|
+
paths:
|
|
33
|
+
- "*"
|
|
34
|
+
allowed_methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"] # Allowed HTTP methods for the API
|
|
28
35
|
queue:
|
|
29
36
|
max_size: 200
|
|
30
37
|
expiry_seconds: 300
|
|
@@ -46,26 +53,9 @@ default_settings:
|
|
|
46
53
|
timeouts:
|
|
47
54
|
request_timeout_seconds: 300
|
|
48
55
|
|
|
49
|
-
# Request body substitution settings
|
|
50
|
-
request_body_substitution:
|
|
51
|
-
enabled: false
|
|
52
|
-
# Substitution rules for request body with JMEPath
|
|
53
|
-
rules:
|
|
54
|
-
- name: "Remove frequency_penalty"
|
|
55
|
-
operation: remove
|
|
56
|
-
path: "frequency_penalty"
|
|
57
|
-
conditions:
|
|
58
|
-
- field: "frequency_penalty"
|
|
59
|
-
operator: "exists"
|
|
60
|
-
- name: "Remove presence_penalty"
|
|
61
|
-
operation: remove
|
|
62
|
-
path: "presence_penalty"
|
|
63
|
-
conditions:
|
|
64
|
-
- field: "presence_penalty"
|
|
65
|
-
operator: "exists"
|
|
66
56
|
apis:
|
|
67
57
|
gemini:
|
|
68
|
-
# OpenAI-compatible API endpoint
|
|
58
|
+
# Example for OpenAI-compatible API endpoint
|
|
69
59
|
name: Google Gemini API
|
|
70
60
|
# Supported endpoints:
|
|
71
61
|
# Gemini: https://generativelanguage.googleapis.com/v1beta/openai
|
|
@@ -90,7 +80,7 @@ apis:
|
|
|
90
80
|
rate_limit:
|
|
91
81
|
enabled: true
|
|
92
82
|
# For Gemini-2.5-pro-exp-03-25, rate limits per key are 5 RPM and 25 RPD
|
|
93
|
-
# Endpoint rate limit should be n ×
|
|
83
|
+
# Endpoint rate limit should be n × per-key-RPD, where n is the number of keys
|
|
94
84
|
endpoint_rate_limit: 75/d
|
|
95
85
|
key_rate_limit: 5/m
|
|
96
86
|
# Paths to apply rate limits (regex supported) - defaults to all paths "*"
|
|
@@ -98,6 +88,25 @@ apis:
|
|
|
98
88
|
- "/chat/*"
|
|
99
89
|
- "/images/*"
|
|
100
90
|
|
|
91
|
+
# Request body substitution settings
|
|
92
|
+
request_body_substitution:
|
|
93
|
+
enabled: false
|
|
94
|
+
# Substitution rules for request body with JMEPath
|
|
95
|
+
rules:
|
|
96
|
+
# Since Gemini API doesn't support frequency_penalty and presence_penalty, we remove them with these rules
|
|
97
|
+
- name: "Remove frequency_penalty"
|
|
98
|
+
operation: remove
|
|
99
|
+
path: "frequency_penalty"
|
|
100
|
+
conditions:
|
|
101
|
+
- field: "frequency_penalty"
|
|
102
|
+
operator: "exists"
|
|
103
|
+
- name: "Remove presence_penalty"
|
|
104
|
+
operation: remove
|
|
105
|
+
path: "presence_penalty"
|
|
106
|
+
conditions:
|
|
107
|
+
- field: "presence_penalty"
|
|
108
|
+
operator: "exists"
|
|
109
|
+
|
|
101
110
|
test:
|
|
102
111
|
name: Test API
|
|
103
112
|
endpoint: http://127.0.0.1:8082
|
|
@@ -105,7 +114,7 @@ apis:
|
|
|
105
114
|
randomness: 5
|
|
106
115
|
headers:
|
|
107
116
|
Authorization: 'Bearer ${{keys}}'
|
|
108
|
-
User-Agent: ${{agents}}
|
|
117
|
+
User-Agent: ${{agents}} # flexible headers customization with template variables supported
|
|
109
118
|
variables:
|
|
110
119
|
keys:
|
|
111
120
|
- your_test_key_1
|