> ## Content Index
> Fetch the complete content index at: https://dev.tmlab.store/news/llms.txt
> Use this file to discover other available public pages before exploring further.

# 重试和备用模型：让调用成功率从 98% 到 99.9%
- URL: https://dev.tmlab.store/news/retry-fallback/
- Published: 2026-10-06T00:00:00.000Z
- Updated: 2026-10-13T08:55:54.000Z
- Description: 什么错误该重试、重试几次、什么时候换模型。附一份可以直接复制的封装。
- Author: Orbis News
- Tags: 实战教程, 把模型接进产品, #orbis-demo

{"version":1,"sourceTitle":"重试和备用模型：让调用成功率从 98% 到 99.9%","motif":"reroute","min":10,"demoAuthor":"陈墨","models":\["anthropic/claude-sonnet-5.5","openai/gpt-6.1-sol"\],"order":8,"topicOrder":2,"topicIndex":1}

## 先看结论

- 429 和 5xx 可以重试，400 不要重试。
- 指数退避加随机抖动，最多 3 次。
- 同一请求换备用模型前，要确认两个模型的输出格式兼容。

## 哪些错误可以重试

429 表示请求太频繁，5xx 表示上游暂时不可用，这两类可以重试。400 和 401 是请求本身的问题，重试不会成功。

```Python
for attempt in range(3):
    try:
        return call(model)
    except RateLimitError:
        time.sleep(2 ** attempt + random.random())
return call(fallback_model)
```

## 文中提到的模型

模型 ID 可以直接填进 model 参数，在 Orbis 用同一个 API Key 调用。

Claude Sonnet 5.5

anthropic/claude-sonnet-5.5

输入 ¥21.6 / 输出 ¥108每百万 tokens

[查看模型](https://dev.tmlab.store/?ref=dev.tmlab.store)

GPT-6.1 Sol

openai/gpt-6.1-sol

输入 ¥18 / 输出 ¥144每百万 tokens

[查看模型](https://dev.tmlab.store/?ref=dev.tmlab.store)