Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Shape the Future with Tooken!
import time import random def call_with_retry(client, max_retries=3, **kwargs): for attempt in range(max_retries): try: return client.chat.completions.create(**kwargs) except Exception as e: if "429" in str(e): # 指数退避 + 随机抖动 wait_time = (2 ** attempt) + random.uniform(0, 1) print(f"限流,{wait_time:.1f}秒后重试...") time.sleep(wait_time) elif "502" in str(e) or "503" in str(e): # 上游故障,快速重试 time.sleep(1) else: raise e raise Exception("超过最大重试次数")