Spaces:
Sleeping
Sleeping
Commit
·
b48b3d2
1
Parent(s):
f3a5a1f
Reduce rotator slot
Browse files- utils/api/rotator.py +3 -3
utils/api/rotator.py
CHANGED
|
@@ -12,12 +12,12 @@ logger = get_logger("ROTATOR", __name__)
|
|
| 12 |
class APIKeyRotator:
|
| 13 |
"""
|
| 14 |
Round-robin API key rotator.
|
| 15 |
-
- Loads keys from env vars with given prefix (e.g., GEMINI_API_1..
|
| 16 |
- get_key() returns current key
|
| 17 |
- rotate() moves to next key
|
| 18 |
- on HTTP 401/429/5xx you should call rotate() and retry (bounded)
|
| 19 |
"""
|
| 20 |
-
def __init__(self, prefix: str, max_slots: int =
|
| 21 |
self.keys = []
|
| 22 |
for i in range(1, max_slots + 1):
|
| 23 |
v = os.getenv(f"{prefix}{i}")
|
|
@@ -39,7 +39,7 @@ class APIKeyRotator:
|
|
| 39 |
return self.current
|
| 40 |
|
| 41 |
|
| 42 |
-
async def robust_post_json(url: str, headers: dict, payload: dict, rotator: APIKeyRotator, max_retries: int =
|
| 43 |
"""
|
| 44 |
POST JSON with simple retry+rotate on 401/403/429/5xx.
|
| 45 |
Returns json response.
|
|
|
|
| 12 |
class APIKeyRotator:
|
| 13 |
"""
|
| 14 |
Round-robin API key rotator.
|
| 15 |
+
- Loads keys from env vars with given prefix (e.g., GEMINI_API_1..6)
|
| 16 |
- get_key() returns current key
|
| 17 |
- rotate() moves to next key
|
| 18 |
- on HTTP 401/429/5xx you should call rotate() and retry (bounded)
|
| 19 |
"""
|
| 20 |
+
def __init__(self, prefix: str, max_slots: int = 6):
|
| 21 |
self.keys = []
|
| 22 |
for i in range(1, max_slots + 1):
|
| 23 |
v = os.getenv(f"{prefix}{i}")
|
|
|
|
| 39 |
return self.current
|
| 40 |
|
| 41 |
|
| 42 |
+
async def robust_post_json(url: str, headers: dict, payload: dict, rotator: APIKeyRotator, max_retries: int = 6):
|
| 43 |
"""
|
| 44 |
POST JSON with simple retry+rotate on 401/403/429/5xx.
|
| 45 |
Returns json response.
|