Error code: 429 - {'error': {'message': 'GeminiException - {"error":{"message":"...
错误信息
openai.RateLimitError: Error code: 429 - {'error': {'message': 'GeminiException - {"error":{"message":"Resource has been exhausted (e.g. check quota). (request id: 20260703034920122914212UAVDHRA0)","type":"upstream_error","param":"","code":429}}Error happened to model=AWS-Gemini-3.1-Pro-Preview. Received Model Group=AWS-Gemini-3.1-Pro-Preview\nAvailable Model Group Fallbacks=None\nError doing the fallback: GeminiException - {"error":{"message":"Resource has been exhausted (e.g. check quota). (request id: 20260703034920122914212UAVDHRA0)","type":"upstream_error","param":"","code":429}}Error happened to model=AWS-Gemini-3.1-Pro-Preview', 'type': 'throttling_error', 'param': None, 'code': '429'}}
AI 解决方案
🔍 报错分析
1. 🌐 错误翻译
原文:openai.RateLimitError: Error code: 429 - {'error': {'message': 'GeminiException - {"error":{"message":"Resource has been exhausted (e.g. check quota). (request id: 20260703034920122914212UAVDHRA0)","type":"upstream_error","param":"","code":429}}Error happened to model=AWS-Gemini-3.1-Pro-Preview. Received Model Group=AWS-Gemini-3.1-Pro-Preview\nAvailable Model Group Fallbacks=None\nError doing the fallback: GeminiException - {"error":{"message":"Resource has been exhausted (e.g. check quota). (request id: 20260703034920122914212UAVDHRA0)","type":"upstream_error","param":"","code":429}}Error happened to model=AWS-Gemini-3.1-Pro-Preview', 'type': 'throttling_error', 'param': None, 'code': '429'}}
译文:openai.RateLimitError: 错误代码:429 - {'error': {'message': 'Gemini异常 - {"error":{"message":"资源已耗尽(例如检查配额)。(请求ID:20260703034920122914212UAVDHRA0)","type":"上游错误","param":"","code":429}}模型AWS-Gemini-3.1-Pro-Preview发生错误。接收到的模型组=AWS-Gemini-3.1-Pro-Preview\n可用的模型组回退方案=无\n执行回退时出错:Gemini异常 - {"error":{"message":"资源已耗尽(例如检查配额)。(请求ID:20260703034920122914212UAVDHRA0)","type":"上游错误","param":"","code":429}}模型AWS-Gemini-3.1-Pro-Preview发生错误', 'type': '限流错误', 'param': None, 'code': '429'}}
2. 🎯 原因分析
3. 💡 解决方案
方案1:添加请求重试与指数退避
import time
import openai
from openai.error import RateLimitError
def call_model_with_retry(max_retries=5, base_delay=1):
"""带指数退避的请求重试函数"""
for attempt in range(max_retries):
try:
# 替换为实际的模型调用逻辑
response = openai.ChatCompletion.create(
model="AWS-Gemini-3.1-Pro-Preview",
# ... 其他参数
)
return response
except RateLimitError as e:
if attempt == max_retries - 1:
raise # 最后一次重试失败,抛出原错误
delay = base_delay * (2 ** attempt) # 指数退避
print(f"触发限流,{delay}秒后第{attempt+1}次重试...")
time.sleep(delay)
方案2:检查并调整请求频率
方案3:申请配额提升