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: 20260703031141926121933Xf5xvjqe)","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: 20260703031141926121933Xf5xvjqe)","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: 20260703031141926121933Xf5xvjqe)","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: 20260703031141926121933Xf5xvjqe)","type":"upstream_error","param":"","code":429}}Error happened to model=AWS-Gemini-3.1-Pro-Preview', 'type': 'throttling_error', 'param': None, 'code': '429'}}
译文:openai.速率限制错误:错误代码:429 - {'error': {'message': 'Gemini异常 - {"error":{"message":"资源已耗尽(例如检查配额)。(请求id:20260703031141926121933Xf5xvjqe)","type":"上游错误","param":"","code":429}}模型AWS-Gemini-3.1-Pro-Preview发生错误。接收的模型组=AWS-Gemini-3.1-Pro-Preview\n可用的模型组回退=无\n回退时出错:Gemini异常 - {"error":{"message":"资源已耗尽(例如检查配额)。(请求id:20260703031141926121933Xf5xvjqe)","type":"上游错误","param":"","code":429}}模型AWS-Gemini-3.1-Pro-Preview发生错误', 'type': '限流错误', 'param': None, 'code': '429'}}
2. 🎯 原因分析
这是API速率限制错误,根本原因是当前使用的
AWS-Gemini-3.1-Pro-Preview 模型接口资源已耗尽。错误代码429表示请求频率超过API服务端允许的阈值,且配置的模型组无可用回退方案,导致请求失败。3. 💡 解决方案
核心解决思路是降低请求频率或升级服务配额,可按以下步骤操作:
AWS-Gemini-3.1-Pro-Preview模型的调用配额以添加指数退避重试为例,修复后的请求代码(Python)参考:
import time
import openai
from openai import RateLimitError
def call_gemini_with_retry(prompt, max_retries=5):
client = openai.OpenAI()
base_delay = 1 # 初始延迟(秒)
for retry in range(max_retries):
try:
response = client.chat.completions.create(
model="AWS-Gemini-3.1-Pro-Preview",
messages=[{"role": "user", "content": prompt}]
)
return response
except RateLimitError as e:
if retry == max_retries - 1:
raise e
# 指数退避:延迟时间 = 基础延迟 * 2^重试次数
delay = base_delay * (2 ** retry)
time.sleep(delay)