fallback-credit changedbuild-with-claude/fallback-credit
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−62removed
From line
46
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits14to this page, all time
The whole hunk
from line 46, old and new numbered
/
from line 46
4646
4747The following example makes a request that may be refused and redeems the credit token on a retry against Claude Opus 4.8. When a retry attempt is rejected, the example degrades through the rejection ladder: the sequence of progressively simpler retry shapes covered in [When a retry is rejected](https://platform.claude.com/docs/en/build-with-claude/fallback-credit#when-a-retry-is-rejected).
4848
49<CodeGroup>
50 ```bash cURL
51 # Initial request (may be refused)
52 response=$(curl --fail-with-body -sS https://api.anthropic.com/v1/messages \
53 -H "x-api-key: $ANTHROPIC_API_KEY" \
54 -H "anthropic-version: 2023-06-01" \
55 -H "anthropic-beta: fallback-credit-2026-07-01" \
56 -H "content-type: application/json" \
57 -d '{
58 "model": "claude-fable-5",
59 "max_tokens": 1024,
60 "messages": [{"role": "user", "content": "Hello, Claude"}]
61 }')
49<CodeGroup exclude="shell:cURL, shell:CLI">
50 <CodeGroupItem language="cURL">
51 This workflow 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.
52 </CodeGroupItem>
6253
63 # A refusal carries a one-time credit token in stop_details
64 token=$(jq -r '.stop_details.fallback_credit_token // empty' <<<"${response}")
65
66 if [[ -n "${token}" ]]; then
67 # Retry on the fallback model with the credit token (same body)
68 response=$(curl --fail-with-body -sS https://api.anthropic.com/v1/messages \
69 -H "x-api-key: $ANTHROPIC_API_KEY" \
70 -H "anthropic-version: 2023-06-01" \
71 -H "anthropic-beta: fallback-credit-2026-07-01" \
72 -H "content-type: application/json" \
73 -d "$(jq -n --arg token "${token}" '{
74 model: "claude-opus-4-8",
75 max_tokens: 1024,
76 messages: [{"role": "user", "content": "Hello, Claude"}],
77 fallback_credit_token: $token
78 }')")
79 fi
80
81 # See the SDK examples for the full rejection-handling ladder.
82 jq -c '{stop_reason, model}' <<<"${response}"
83 ```
84
85 ```bash CLI
86 # Initial request (may be refused)
87 response=$(ant beta:messages create \
88 --model claude-fable-5 \
89 --max-tokens 1024 \
90 --message '{"role":"user","content":"Hello, Claude"}' \
91 --beta fallback-credit-2026-07-01 \
92 --format json)
93
94 # A refusal carries a one-time credit token in stop_details
95 token=$(jq -r '.stop_details.fallback_credit_token // empty' <<<"${response}")
96
97 if [[ -n "${token}" ]]; then
98 # Retry on the fallback model with the credit token
99 response=$(ant beta:messages create \
100 --model claude-opus-4-8 \
101 --max-tokens 1024 \
102 --message '{"role":"user","content":"Hello, Claude"}' \
103 --fallback-credit-token "${token}" \
104 --beta fallback-credit-2026-07-01 \
105 --format json)
106 fi
107
108 # See the SDK examples for the full rejection-handling ladder.
109 jq -c '{stop_reason, model}' <<<"${response}"
110 ```
54 <CodeGroupItem language="CLI">
55 This workflow 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.
56 </CodeGroupItem>
11157
11258 ```python Python
11359 client = Anthropic()
No line in this hunk matches that.