refusals-and-fallback changedbuild-with-claude/refusals-and-fallback
Nearest release: v2.1.332, published 6 hours after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+161added
Lines−3removed
From line
654
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits40to this page, all time
## Fallback for fast mode requests ### With server-side fallback ### With the SDK middleware ### With a manual retry ### Claude Models on Google Cloud (Google managed) and Microsoft Foundry ### Which speed ran
The whole hunk
from line 654, old and new numbered
/
from line 654
654654* Entries are tried in order. Each must be distinct from the other entries and from the requested model.
655655* Each entry must be one of the requested model’s permitted targets. With the beta header set, that list is published as `allowed_fallback_models` on the [model’s entry in the Models API](https://platform.claude.com/docs/en/api/beta/models/list).
656656* Each entry names a `model` and can override `max_tokens`, `thinking`, `output_config`, and `speed` for that attempt only.
657* The request must be valid as a direct request to every model named. If a fallback model does not support a feature the request uses, the API rejects the request up front. Under the `2026-07-01` header, `thinking: {"type": "between_tools"}` is the exception: when a Claude Sonnet 5.5 request falls back to Claude Sonnet 5, the fallback attempt runs with `thinking: {"type": "disabled"}` and `display: "omitted"`. Under `2026-06-01`, set `thinking` on the Claude Sonnet 5 entry, or the request is rejected up front.
657* The request must be valid as a direct request to every model named, or the API rejects it up front. Under the `server-side-fallback-2026-07-01` header, the request’s `speed`, `output_config.effort`, `output_config.task_budget`, and `thinking` type are the exceptions. Where a fallback model doesn’t support one of those values, its attempt uses the model’s default.
658* When a Claude Sonnet 5.5 request with [`thinking: {"type": "between_tools"}`](https://platform.claude.com/docs/en/build-with-claude/thinking#turning-thinking-off) falls back to Claude Sonnet 5 under that header, the attempt runs with `thinking: {"type": "disabled"}` and `display: "omitted"` instead.
659* Under the `server-side-fallback-2026-06-01` header, a fallback model that doesn’t support the request’s `speed: "fast"` runs at standard speed. For an unsupported `thinking` or `output_config` value, set that whole field on the model’s entry.
658660* As with the default mode, only a safety classifier decline triggers the fallback. A rate limit, overload, or server error on the requested model is returned to you as-is.
659* If a fallback model is rate limited or overloaded, the fallback attempt is not made and the preceding refusal is returned instead. The refusal’s `stop_details.recommended_model` then names a model to retry directly. Size the fallback model’s rate limits for the refusal volume you expect, or fallbacks degrade to refusals under load.
661* If a fallback model is rate limited or overloaded, the API returns the preceding refusal and tries no later entries. At a fast mode limit, the attempt can [run at standard speed](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#with-server-side-fallback) instead. The refusal’s `stop_details.recommended_model` names a model to retry directly. Size the fallback model’s rate limits for the refusals you expect.
660662
661663The response has the same shape in both modes: the model that served the turn appears in the top-level `model` field, a `fallback` content block marks the handoff, and `usage.iterations` records each attempt.
662664
from line 1133
11311133 ```
11321134</CodeGroup>
11331135
1136For fast mode requests, use `null` (python: `None`; go: `ExtraFields: map[string]any{"speed": nil}`; java: `Optional.empty()`; ruby: `nil`) for `speed` on each fallback entry, as [Fallback for fast mode requests](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#falling-back-from-fast-mode) shows.
1137
11341138### How it behaves
11351139
11361140* Retries walk your fallback list in order. A fallback model that itself refuses passes the request to the next entry.
from line 1160
11561160 Send the same request with `model` set to a fallback model, such as Claude Opus 4.8. If the refused request sent `thinking: {"type": "between_tools"}`, change `thinking` first: only Claude Sonnet 5.5 accepts that value, so omit `thinking` or set a value the fallback model accepts. [Server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback) under the `2026-07-01` header makes this change for you when it falls back to Claude Sonnet 5. Another model can normally serve a request that Claude Fable 5.2, Claude Fable 5.1, or Claude Fable 5 declines. How you handle the conversation history depends on whether you redeem a [fallback credit](https://platform.claude.com/docs/en/build-with-claude/fallback-credit):
11571161
11581162 * **Not redeeming a credit:** you can leave the earlier `thinking` and `redacted_thinking` blocks in place or strip them to save input tokens. The fallback model normally can’t use them either way. Apart from Claude Mythos 5.2, no other model reads Claude Fable 5.2 blocks. Claude Fable 5.1 and Claude Mythos 5.1 [read Claude Fable 5.1 blocks](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#switching-models), and so do Claude Fable 5.2 and Claude Mythos 5.2 on the Claude API and Claude Models on Google Cloud (Google managed). No other model reads them. Only those four models, Claude Fable 5, and Claude Mythos 5 read Claude Fable 5 blocks. The API drops any of these blocks that the fallback model can’t read. It also drops any Claude Opus 5.5 or Claude Sonnet 5.5 block that the fallback model can’t read (see [Switching models mid-conversation](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking#switching-models)). A retry after a Claude Haiku 5.5 refusal is always in this case. On the Claude API and Claude Models on Google Cloud (Google managed), Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.2, and Claude Mythos 5.2 read Claude Haiku 5.5 blocks, so leave those blocks in place when you fall back to one of those models there. For a fallback model that can’t read them, the API drops them without billing them.
1159 * **Redeeming a credit:** send the body unchanged, because redemption requires an exact match. The server handles the earlier model’s thinking blocks on a redemption, so do not strip them (see [Fields that must match the refused request](https://platform.claude.com/docs/en/build-with-claude/fallback-credit#reference)).
1163 * **Redeeming a credit:** change only what [Fields that must match the refused request](https://platform.claude.com/docs/en/build-with-claude/fallback-credit#reference) allows, because redemption compares the two requests. Deleting `speed` keeps the credit. The server handles the earlier model’s thinking blocks on a redemption, so do not strip them.
1164
1165 Delete `speed` if it’s `"fast"`, as [With a manual retry](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#with-a-manual-retry) explains.
11601166 </Step>
11611167
11621168 <Step title="Stay on the fallback model">
from line 1171
11651171</Steps>
11661172
11671173A manual retry writes the fallback model’s prompt cache in full, which costs more than reading an existing cache. [Fallback credit](https://platform.claude.com/docs/en/build-with-claude/fallback-credit) refunds that cost; redeem it on every retry you build yourself. A Claude Haiku 5.5 refusal carries no fallback credit, so a retry after one pays the full cost of writing the fallback model’s prompt cache.
1174
1175## Fallback for fast mode requests
1176
1177Which speed a fallback runs at, and what you set for [`speed`](https://platform.claude.com/docs/en/api/beta/messages/create#create.speed), depend on how you fall back.
1178
1179### With server-side fallback
1180
1181When fast mode requests fall back, each attempt runs, and is billed, at fast speed if you have [fast mode on its model](https://platform.claude.com/docs/en/build-with-claude/fast-mode#feature-availability). Otherwise, or if its fast mode rate limit is reached, it’s tried at standard speed.
1182
1183A `speed` on the attempt’s `fallbacks` entry overrides this, so you know its speed in advance:
1184
1185* `null` (python: `None`; go: `ExtraFields: map[string]any{"speed": nil}`; java: `Optional.empty()`; php: `BetaFallbackParam::with(model: $model)->withSpeed(null)`; ruby: `nil`) runs that attempt at standard speed if the request sends the `server-side-fallback-2026-07-01` header.
1186* `"fast"` runs that attempt at fast speed only. Where the model has no fast mode, the API rejects the whole request up front. If your fast mode limit on that model is 0, or you have reached it, you get the previous attempt’s refusal.
1187
1188With `fallbacks: "default"`, no entry can set `speed`, so name your models to control it.
1189
1190### With the SDK middleware
1191
1192Use `null` (python: `None`; go: `ExtraFields: map[string]any{"speed": nil}`; java: `Optional.empty()`; ruby: `nil`), not `"standard"`, for `speed` on each entry in your fallback list. An entry that leaves `speed` out retries at `"fast"`, which can fail with a 400 error.
1193
1194With this client, a fast mode request on Claude Opus 5.5 that is refused goes to Claude Opus 4.8 at standard speed:
1195
1196<CodeGroup exclude="shell">
1197 <CodeGroupItem language="cURL">
1198 The refusal-fallback middleware is part of the Anthropic SDK, so a cURL request can’t use it. Use [server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback) or [a manual retry](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#manual-retry).
1199 </CodeGroupItem>
1200
1201 <CodeGroupItem language="CLI">
1202 The `ant` CLI doesn’t include the refusal-fallback middleware. Use [server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback) or [a manual retry](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#manual-retry).
1203 </CodeGroupItem>
1204
1205 ```python Python
1206 from anthropic import Anthropic, BetaFallbackState, BetaRefusalFallbackMiddleware
1207
1208 client = Anthropic(
1209 middleware=[
1210 # None removes speed from the retry, which then runs at standard speed.
1211 BetaRefusalFallbackMiddleware([{"model": "claude-opus-4-8", "speed": None}]),
1212 ],
1213 )
1214 ```
1215
1216 ```typescript TypeScript
1217 import { BetaFallbackState, betaRefusalFallbackMiddleware } from "@anthropic-ai/sdk";
1218
1219 const client = new Anthropic({
1220 // null removes speed from the retry, which then runs at standard speed.
1221 middleware: [betaRefusalFallbackMiddleware([{ model: "claude-opus-4-8", speed: null }])]
1222 });
1223 ```
1224
1225 ```csharp C#
1226 using Anthropic.Helpers;
1227 using Anthropic.Models.Beta.Messages;
1228 using Messages = Anthropic.Models.Messages;
1229
1230 AnthropicClient client = new()
1231 {
1232 Handlers =
1233 [
1234 new BetaRefusalFallbackHandler
1235 {
1236 // A null Speed removes speed from the retry, which then runs at standard speed.
1237 Fallbacks = [new(Messages::Model.ClaudeOpus4_8) { Speed = null }],
1238 },
1239 ],
1240 };
1241 ```
1242
1243 ```go Go
1244 import (
1245 // ...
1246 "github.com/anthropics/anthropic-sdk-go/v2/lib/betafallback"
1247 "github.com/anthropics/anthropic-sdk-go/v2/option"
1248 )
1249
1250 func main() {
1251 client := anthropic.NewClient(
1252 option.WithMiddleware(betafallback.BetaRefusalFallbackMiddleware(
1253 []anthropic.BetaFallbackParam{{
1254 Model: anthropic.ModelClaudeOpus4_8,
1255 // The Speed field can't hold nil, so set it here. Nil removes speed from the
1256 // retry, which then runs at standard speed.
1257 ExtraFields: map[string]any{"speed": nil},
1258 }},
1259 )),
1260 )
1261 // ...
1262 }
1263 ```
1264
1265 ```java Java
1266 import com.anthropic.helpers.BetaRefusalFallbackInterceptor;
1267 import com.anthropic.models.beta.messages.BetaFallbackParam;
1268 // ...
1269 import com.anthropic.models.messages.Model;
1270 import java.util.Optional;
1271
1272 void main() {
1273 AnthropicClient client = AnthropicOkHttpClient.builder()
1274 .fromEnv()
1275 .addInterceptor(BetaRefusalFallbackInterceptor.builder()
1276 .addFallback(BetaFallbackParam.builder()
1277 .model(Model.CLAUDE_OPUS_4_8)
1278 // An empty speed removes it from the retry, which then runs at standard speed.
1279 .speed(Optional.empty())
1280 .build())
1281 .build())
1282 .build();
1283 // ...
1284 }
1285 ```
1286
1287 ```php PHP
1288 use Anthropic\Lib\Middleware\RefusalFallbackMiddleware;
1289 use Anthropic\Messages\Model;
1290
1291 $client = new Client(
1292 requestOptions: [
1293 'middleware' => [
1294 // null runs the retry at standard speed.
1295 // BetaFallbackParam::with(speed: null) loses the null, so the retry stays fast.
1296 new RefusalFallbackMiddleware(fallbacks: [['model' => Model::CLAUDE_OPUS_4_8, 'speed' => null]]),
1297 ],
1298 ],
1299 );
1300 ```
1301
1302 ```ruby Ruby
1303 client = Anthropic::Client.new(
1304 middleware: [
1305 # nil removes speed from the retry, which then runs at standard speed.
1306 Anthropic::BetaRefusalFallbackMiddleware.new([{model: Anthropic::Model::CLAUDE_OPUS_4_8, speed: nil}])
1307 ]
1308 )
1309 ```
1310</CodeGroup>
1311
1312### With a manual retry
1313
1314Delete `speed` to retry at standard speed. Keep it only where the fallback model’s fast mode is available to you, with any beta header it needs.
1315
1316### Claude Models on Google Cloud (Google managed) and Microsoft Foundry
1317
1318For the SDK middleware and a manual retry:
1319
1320* On Claude Models on Google Cloud (Google managed), a standard-speed request with the `fast-mode-2026-02-01` beta header returns a 400 error. Don’t send it on the original request either: fast mode doesn’t need it there, and the middleware’s retry would send it again.
1321* On Microsoft Foundry, [fast mode has its own model IDs](https://platform.claude.com/docs/en/build-with-claude/fast-mode#basic-usage). For each fallback, name a deployment of a model other than the refusing one, without `-fast`.
1322
1323### Which speed ran
1324
1325Read `usage.speed`. On a stream, it keeps the value from the first event. No field shows the speed of a fallback model that takes over later.
11681326
11691327## Refusals in Message Batches
11701328
No line in this hunk matches that.