Commit be260b4
feat(messages)!: add extended thinking support (#5938)
## Summary
Fills four gaps in the Messages API extended thinking support:
- **`_SignatureDelta` model + stream handler** — Anthropic sends
`signature_delta` events at the end of each thinking block carrying a
cryptographic signature. The SSE parser was silently dropping these
(returning `None` for unknown delta types). Now parsed and forwarded
correctly in passthrough mode.
- **`AnthropicRedactedThinkingBlock` model** — When Claude redacts a
thinking block, it returns `{"type": "redacted_thinking", "data":
"<opaque>"}`. This block must be echoed back as-is in multi-turn
conversations. Without this model, Pydantic validation fails when
replaying message history containing redacted blocks.
- **`budget_tokens` validation fix** — Changed `ge=1` to `ge=1024` to
match [Anthropic's documented
minimum](https://platform.claude.com/docs/en/build-with-claude/extended-thinking).
The previous minimum was incorrect and would result in a 400 from the
upstream Anthropic API.
- **Translation mode error** — When `thinking.type == "enabled"` and the
request routes through translation mode (Anthropic → OpenAI format), the
thinking config was silently dropped. Now raises a clear 400 error
explaining that extended thinking requires a native Anthropic-compatible
provider.
## Breaking changes
This PR contains two intentional breaking changes flagged by the
`api-conformance` pre-commit hook:
1. **`budget_tokens` minimum raised from 1 to 1024** — This is a bug
fix, not a behavioral change. Values between 1 and 1023 were never valid
per the Anthropic API and would have been rejected upstream with
`invalid_request_error`. We now reject them at the OGX layer with a
Pydantic validation error instead.
2. **`AnthropicRedactedThinkingBlock` added to `AnthropicContentBlock`
union** — This is an additive change to a discriminated union. Existing
clients that only handle known block types (text, image, tool_use,
tool_result, thinking) are unaffected — the discriminator ensures they
won't accidentally match the new variant. Clients that exhaustively
match all variants will need to handle or skip `redacted_thinking`.
## Test plan
```bash
# Run messages unit tests (28 tests, all pass)
uv run pytest tests/unit/providers/inline/messages/test_impl.py -xvs
# Run full unit test suite (2275 tests pass, no regressions)
uv run pytest tests/unit/ -x --tb=short --ignore=tests/unit/providers/vector_io
```
Test output:
```
tests/unit/providers/inline/messages/test_impl.py::TestSSEParsing::test_signature_delta_parsed PASSED
tests/unit/providers/inline/messages/test_impl.py::TestSSEParsing::test_redacted_thinking_block_start_parsed PASSED
tests/unit/providers/inline/messages/test_impl.py::TestThinkingConfig::test_budget_tokens_below_minimum_rejected PASSED
tests/unit/providers/inline/messages/test_impl.py::TestThinkingConfig::test_budget_tokens_at_minimum_accepted PASSED
tests/unit/providers/inline/messages/test_impl.py::TestThinkingConfig::test_budget_tokens_above_minimum_accepted PASSED
tests/unit/providers/inline/messages/test_impl.py::TestThinkingConfig::test_thinking_enabled_raises_in_translation_mode PASSED
tests/unit/providers/inline/messages/test_impl.py::TestThinkingConfig::test_thinking_disabled_allowed_in_translation_mode PASSED
tests/unit/providers/inline/messages/test_impl.py::TestThinkingConfig::test_thinking_none_allowed_in_translation_mode PASSED
tests/unit/providers/inline/messages/test_impl.py::TestRequestTranslation::test_redacted_thinking_skipped_in_assistant_message PASSED
============================== 28 passed in 0.10s ==============================
```
🤖 Generated with [Claude Code](https://claude.ai/claude-code)
---------
Signed-off-by: Eleanor Hu <ehu@redhat.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent a50639a commit be260b4
9 files changed
Lines changed: 212 additions & 18 deletions
File tree
- client-sdks/stainless
- docs
- docs/api-anthropic-messages
- static
- src
- ogx_api/messages
- ogx/providers/inline/messages
- tests/unit/providers/inline/messages
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10644 | 10644 | | |
10645 | 10645 | | |
10646 | 10646 | | |
| 10647 | + | |
| 10648 | + | |
10647 | 10649 | | |
10648 | 10650 | | |
10649 | 10651 | | |
10650 | 10652 | | |
| 10653 | + | |
10651 | 10654 | | |
10652 | 10655 | | |
10653 | 10656 | | |
10654 | 10657 | | |
10655 | | - | |
| 10658 | + | |
10656 | 10659 | | |
10657 | 10660 | | |
10658 | 10661 | | |
| |||
10692 | 10695 | | |
10693 | 10696 | | |
10694 | 10697 | | |
| 10698 | + | |
| 10699 | + | |
10695 | 10700 | | |
10696 | 10701 | | |
10697 | 10702 | | |
10698 | 10703 | | |
| 10704 | + | |
10699 | 10705 | | |
10700 | 10706 | | |
10701 | 10707 | | |
10702 | 10708 | | |
10703 | | - | |
| 10709 | + | |
10704 | 10710 | | |
10705 | 10711 | | |
10706 | 10712 | | |
| |||
10725 | 10731 | | |
10726 | 10732 | | |
10727 | 10733 | | |
| 10734 | + | |
| 10735 | + | |
| 10736 | + | |
| 10737 | + | |
| 10738 | + | |
| 10739 | + | |
| 10740 | + | |
| 10741 | + | |
| 10742 | + | |
| 10743 | + | |
| 10744 | + | |
| 10745 | + | |
| 10746 | + | |
| 10747 | + | |
| 10748 | + | |
| 10749 | + | |
10728 | 10750 | | |
10729 | 10751 | | |
10730 | 10752 | | |
| |||
10814 | 10836 | | |
10815 | 10837 | | |
10816 | 10838 | | |
10817 | | - | |
| 10839 | + | |
10818 | 10840 | | |
10819 | 10841 | | |
10820 | 10842 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10197 | 10197 | | |
10198 | 10198 | | |
10199 | 10199 | | |
| 10200 | + | |
| 10201 | + | |
10200 | 10202 | | |
10201 | 10203 | | |
10202 | 10204 | | |
10203 | 10205 | | |
| 10206 | + | |
10204 | 10207 | | |
10205 | 10208 | | |
10206 | 10209 | | |
10207 | 10210 | | |
10208 | | - | |
| 10211 | + | |
10209 | 10212 | | |
10210 | 10213 | | |
10211 | 10214 | | |
| |||
10245 | 10248 | | |
10246 | 10249 | | |
10247 | 10250 | | |
| 10251 | + | |
| 10252 | + | |
10248 | 10253 | | |
10249 | 10254 | | |
10250 | 10255 | | |
10251 | 10256 | | |
| 10257 | + | |
10252 | 10258 | | |
10253 | 10259 | | |
10254 | 10260 | | |
10255 | 10261 | | |
10256 | | - | |
| 10262 | + | |
10257 | 10263 | | |
10258 | 10264 | | |
10259 | 10265 | | |
| |||
10278 | 10284 | | |
10279 | 10285 | | |
10280 | 10286 | | |
| 10287 | + | |
| 10288 | + | |
| 10289 | + | |
| 10290 | + | |
| 10291 | + | |
| 10292 | + | |
| 10293 | + | |
| 10294 | + | |
| 10295 | + | |
| 10296 | + | |
| 10297 | + | |
| 10298 | + | |
| 10299 | + | |
| 10300 | + | |
| 10301 | + | |
| 10302 | + | |
10281 | 10303 | | |
10282 | 10304 | | |
10283 | 10305 | | |
| |||
10367 | 10389 | | |
10368 | 10390 | | |
10369 | 10391 | | |
10370 | | - | |
| 10392 | + | |
10371 | 10393 | | |
10372 | 10394 | | |
10373 | 10395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10644 | 10644 | | |
10645 | 10645 | | |
10646 | 10646 | | |
| 10647 | + | |
| 10648 | + | |
10647 | 10649 | | |
10648 | 10650 | | |
10649 | 10651 | | |
10650 | 10652 | | |
| 10653 | + | |
10651 | 10654 | | |
10652 | 10655 | | |
10653 | 10656 | | |
10654 | 10657 | | |
10655 | | - | |
| 10658 | + | |
10656 | 10659 | | |
10657 | 10660 | | |
10658 | 10661 | | |
| |||
10692 | 10695 | | |
10693 | 10696 | | |
10694 | 10697 | | |
| 10698 | + | |
| 10699 | + | |
10695 | 10700 | | |
10696 | 10701 | | |
10697 | 10702 | | |
10698 | 10703 | | |
| 10704 | + | |
10699 | 10705 | | |
10700 | 10706 | | |
10701 | 10707 | | |
10702 | 10708 | | |
10703 | | - | |
| 10709 | + | |
10704 | 10710 | | |
10705 | 10711 | | |
10706 | 10712 | | |
| |||
10725 | 10731 | | |
10726 | 10732 | | |
10727 | 10733 | | |
| 10734 | + | |
| 10735 | + | |
| 10736 | + | |
| 10737 | + | |
| 10738 | + | |
| 10739 | + | |
| 10740 | + | |
| 10741 | + | |
| 10742 | + | |
| 10743 | + | |
| 10744 | + | |
| 10745 | + | |
| 10746 | + | |
| 10747 | + | |
| 10748 | + | |
| 10749 | + | |
10728 | 10750 | | |
10729 | 10751 | | |
10730 | 10752 | | |
| |||
10814 | 10836 | | |
10815 | 10837 | | |
10816 | 10838 | | |
10817 | | - | |
| 10839 | + | |
10818 | 10840 | | |
10819 | 10841 | | |
10820 | 10842 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
520 | 522 | | |
521 | 523 | | |
522 | 524 | | |
523 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
524 | 528 | | |
525 | 529 | | |
526 | 530 | | |
527 | 531 | | |
528 | 532 | | |
| 533 | + | |
| 534 | + | |
529 | 535 | | |
530 | 536 | | |
531 | 537 | | |
532 | 538 | | |
533 | 539 | | |
534 | 540 | | |
535 | | - | |
| 541 | + | |
536 | 542 | | |
537 | 543 | | |
538 | 544 | | |
539 | 545 | | |
540 | 546 | | |
541 | 547 | | |
| 548 | + | |
| 549 | + | |
542 | 550 | | |
543 | 551 | | |
544 | 552 | | |
| |||
586 | 594 | | |
587 | 595 | | |
588 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
589 | 603 | | |
590 | 604 | | |
591 | 605 | | |
| |||
597 | 611 | | |
598 | 612 | | |
599 | 613 | | |
600 | | - | |
601 | | - | |
602 | 614 | | |
603 | 615 | | |
604 | 616 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
111 | 118 | | |
112 | | - | |
| 119 | + | |
| 120 | + | |
113 | 121 | | |
114 | 122 | | |
115 | 123 | | |
| |||
198 | 206 | | |
199 | 207 | | |
200 | 208 | | |
201 | | - | |
| 209 | + | |
202 | 210 | | |
203 | 211 | | |
204 | 212 | | |
| |||
345 | 353 | | |
346 | 354 | | |
347 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
348 | 361 | | |
349 | 362 | | |
350 | 363 | | |
351 | 364 | | |
352 | 365 | | |
353 | | - | |
| 366 | + | |
354 | 367 | | |
355 | 368 | | |
356 | 369 | | |
| |||
0 commit comments