handle-streaming-refusals changedtest-and-evaluate/strengthen-guardrails/handle-streaming-refusals
Nearest release: v2.1.304, published under an hour 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+8added
Lines−32removed
From line
56
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits12to this page, all time
The whole hunk
from line 56, old and new numbered
/
from line 56
5656
5757Here's how to detect and handle streaming refusals in your application:
5858
59<CodeGroup>
60 ```bash cURL
61 response=$(curl -N https://api.anthropic.com/v1/messages \
62 -H "anthropic-version: 2023-06-01" \
63 -H "content-type: application/json" \
64 -H "x-api-key: $ANTHROPIC_API_KEY" \
65 -d '{
66 "model": "claude-opus-5-5",
67 "messages": [{"role": "user", "content": "Hello"}],
68 "max_tokens": 1024,
69 "stream": true
70 }')
59<CodeGroup exclude="shell:cURL, shell:CLI">
60 <CodeGroupItem language="cURL">
61 Detecting a refusal in the stream and resetting the conversation needs more logic than a single shell command. Use the [Claude SDK](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) to run it.
62 </CodeGroupItem>
7163
72 if echo "$response" | jq -R -e 'select(startswith("data: "))
73 | sub("^data: "; "") | fromjson
74 | select(.delta.stop_reason == "refusal")' >/dev/null; then
75 echo "Response refused - resetting conversation context"
76 # Reset your conversation state here
77 fi
78 ```
79
80 ```bash CLI
81 response=$(ant messages create --stream --format jsonl \
82 --model claude-opus-5-5 \
83 --max-tokens 1024 \
84 --message '{role: user, content: Hello}')
85
86 if echo "$response" | jq -e 'select(.delta.stop_reason == "refusal")' >/dev/null; then
87 echo "Response refused - resetting conversation context"
88 # Reset your conversation state here
89 fi
90 ```
64 <CodeGroupItem language="CLI">
65 Detecting a refusal in the stream and resetting the conversation needs more logic than a single shell command. Use the [Claude SDK](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) to run it.
66 </CodeGroupItem>
9167
9268 ```python Python
9369 client = anthropic.Anthropic()
No line in this hunk matches that.