Follow Discord
Sweep 31 Oct 2026 · 01:10Z Build v2.1.316 534 read Stable v2.1.309 Latest v2.1.316 Next v2.1.316 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

middleware changedcli-sdks-libraries/middleware

Recorded here
Lines+49added
Lines−0removed
From line 2 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits10to this page, all time

## Availability ### API support #### [Messages API](https://platform.claude.com/docs/en/build-with-claude/working-with-messages) #### [Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview)

The whole hunk

from line 2, old and new numbered
/
lines
from line 2
22title: SDK middleware
33url: https://platform.claude.com/docs/en/cli-sdks-libraries/middleware
44description: Intercept and modify the SDK's requests and responses.
5featureMetadata:
6 supportedModels:
7 - claude-fable-5-1
8 - claude-mythos-5-1
9 - claude-fable-5
10 - claude-mythos-5
11 - claude-mythos-preview
12 - claude-opus-5-5
13 - claude-opus-5
14 - claude-sonnet-5-5
15 - claude-sonnet-5
16 - claude-haiku-5-5
17 - claude-haiku-4-5-20251001
18 - claude-opus-4-8
19 - claude-opus-4-7
20 - claude-opus-4-6
21 - claude-sonnet-4-6
22 - claude-opus-4-5-20251101
23 - claude-sonnet-4-5-20250929
24 supportedPlatforms:
25 Claude API: ga
26 Claude Platform on AWS: ga
27 Amazon Bedrock: ga
28 Amazon Bedrock (InvokeModel): ga
29 Claude Models on Google Cloud (Google managed): ga
30 Microsoft Foundry: ga
531---
632 
733The Claude SDK provides a middleware (or interceptor) hook that lets you run code before a request is sent and after the response is received. Use middleware for cross-cutting concerns such as logging, custom retries, request annotation, and refusal fallback handling.
from line 208
182208## Built-in middleware
183209 
184210The SDK ships a refusal-fallback middleware that automatically retries a request Claude declines (`stop_reason: "refusal"`) on a fallback model. [Refusals and fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback) lists the models whose safety classifiers can decline requests, and [Detect and retry on a fallback model](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#client-side-fallback) covers setup and per-language examples.
211 
212## Availability
213 
214SDK middleware is available or in beta, depending on the API.
215 
216### API support
217 
218#### [Messages API](https://platform.claude.com/docs/en/build-with-claude/working-with-messages)
219 
220* Availability: Available
221 
222| Status | Cloud platforms |
223| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
224| Available | Claude API, [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws), [Amazon Bedrock](https://platform.claude.com/docs/en/build-with-claude/claude-in-amazon-bedrock), [Amazon Bedrock (InvokeModel)](https://platform.claude.com/docs/en/build-with-claude/claude-on-amazon-bedrock-legacy), [Claude Models on Google Cloud (Google managed)](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/google-managed), [Microsoft Foundry](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry) |
225 
226#### [Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview)
227 
228* Availability: Available
229* Usage: Runs on your SDK client’s calls to the Managed Agents API. It does not see the model calls the agent makes inside its loop.
230 
231| Status | Cloud platforms |
232| ------ | ------------------------------------------------------------------------------------------------------------------ |
233| Beta | Claude API, [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws) |
185234 
Feedback