@tanstack/ai-anthropic 0.15.13 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/model-meta.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import type {
2
+ AnthropicAdaptiveOnlyThinkingOptions,
3
+ AnthropicAdaptiveOrDisabledThinkingOptions,
4
+ AnthropicAdaptiveThinkingOptions,
2
5
  AnthropicContainerOptions,
3
6
  AnthropicContextManagementOptions,
4
7
  AnthropicMCPOptions,
8
+ AnthropicMaxTokensOptions,
9
+ AnthropicOutputConfigOptions,
5
10
  AnthropicSamplingOptions,
6
11
  AnthropicServiceTierOptions,
7
12
  AnthropicStopSequencesOptions,
@@ -57,6 +62,8 @@ interface ModelMeta<
57
62
  messageCapabilities?: TMessageCapabilities
58
63
  }
59
64
 
65
+ // Claude Opus 4.6 accepts adaptive thinking alongside the deprecated
66
+ // budget-based extended thinking, and still accepts sampling parameters.
60
67
  const CLAUDE_OPUS_4_6 = {
61
68
  name: 'claude-opus-4-6',
62
69
  id: 'claude-opus-4-6',
@@ -74,6 +81,7 @@ const CLAUDE_OPUS_4_6 = {
74
81
  supports: {
75
82
  input: ['text', 'image', 'document'],
76
83
  extended_thinking: true,
84
+ adaptive_thinking: true,
77
85
  priority_tier: true,
78
86
  tools: [
79
87
  'web_search',
@@ -91,7 +99,7 @@ const CLAUDE_OPUS_4_6 = {
91
99
  AnthropicMCPOptions &
92
100
  AnthropicServiceTierOptions &
93
101
  AnthropicStopSequencesOptions &
94
- AnthropicThinkingOptions &
102
+ AnthropicAdaptiveThinkingOptions &
95
103
  AnthropicToolChoiceOptions &
96
104
  AnthropicSamplingOptions
97
105
  >
@@ -135,6 +143,8 @@ const CLAUDE_OPUS_4_5 = {
135
143
  AnthropicSamplingOptions
136
144
  >
137
145
 
146
+ // Claude Sonnet 4.6 accepts adaptive thinking alongside the deprecated
147
+ // budget-based extended thinking, and still accepts sampling parameters.
138
148
  const CLAUDE_SONNET_4_6 = {
139
149
  name: 'claude-sonnet-4-6',
140
150
  id: 'claude-sonnet-4-6',
@@ -170,7 +180,7 @@ const CLAUDE_SONNET_4_6 = {
170
180
  AnthropicMCPOptions &
171
181
  AnthropicServiceTierOptions &
172
182
  AnthropicStopSequencesOptions &
173
- AnthropicThinkingOptions &
183
+ AnthropicAdaptiveThinkingOptions &
174
184
  AnthropicToolChoiceOptions &
175
185
  AnthropicSamplingOptions
176
186
  >
@@ -292,276 +302,18 @@ const CLAUDE_OPUS_4_1 = {
292
302
  AnthropicSamplingOptions
293
303
  >
294
304
 
295
- const CLAUDE_SONNET_4 = {
296
- name: 'claude-sonnet-4',
297
- id: 'claude-sonnet-4',
298
- context_window: 200_000,
299
- max_output_tokens: 64_000,
300
- knowledge_cutoff: '2025-05-14',
301
- pricing: {
302
- input: {
303
- normal: 3,
304
- },
305
- output: {
306
- normal: 15,
307
- },
308
- },
309
- supports: {
310
- input: ['text', 'image', 'document'],
311
- extended_thinking: true,
312
- priority_tier: true,
313
- tools: [
314
- 'web_search',
315
- 'web_fetch',
316
- 'code_execution',
317
- 'computer_use',
318
- 'bash',
319
- 'text_editor',
320
- 'memory',
321
- ],
322
- },
323
- } as const satisfies ModelMeta<
324
- AnthropicContainerOptions &
325
- AnthropicContextManagementOptions &
326
- AnthropicMCPOptions &
327
- AnthropicServiceTierOptions &
328
- AnthropicStopSequencesOptions &
329
- AnthropicThinkingOptions &
330
- AnthropicToolChoiceOptions &
331
- AnthropicSamplingOptions
332
- >
333
-
334
- const CLAUDE_SONNET_3_7 = {
335
- name: 'claude-sonnet-3-7',
336
- id: 'claude-3-7-sonnet',
337
- max_output_tokens: 64_000,
338
- knowledge_cutoff: '2025-05-14',
339
- pricing: {
340
- input: {
341
- normal: 3,
342
- },
343
- output: {
344
- normal: 15,
345
- },
346
- },
347
- supports: {
348
- input: ['text', 'image', 'document'],
349
- extended_thinking: true,
350
- priority_tier: true,
351
- tools: [
352
- 'web_search',
353
- 'web_fetch',
354
- 'code_execution',
355
- 'computer_use',
356
- 'bash',
357
- 'text_editor',
358
- 'memory',
359
- ],
360
- },
361
- } as const satisfies ModelMeta<
362
- AnthropicContainerOptions &
363
- AnthropicContextManagementOptions &
364
- AnthropicMCPOptions &
365
- AnthropicServiceTierOptions &
366
- AnthropicStopSequencesOptions &
367
- AnthropicThinkingOptions &
368
- AnthropicToolChoiceOptions &
369
- AnthropicSamplingOptions
370
- >
371
-
372
- const CLAUDE_OPUS_4 = {
373
- name: 'claude-opus-4',
374
- id: 'claude-opus-4',
375
- context_window: 200_000,
376
- max_output_tokens: 32_000,
377
- knowledge_cutoff: '2025-05-14',
378
- pricing: {
379
- input: {
380
- normal: 15,
381
- },
382
- output: {
383
- normal: 75,
384
- },
385
- },
386
- supports: {
387
- input: ['text', 'image', 'document'],
388
- extended_thinking: true,
389
- priority_tier: true,
390
- tools: [
391
- 'web_search',
392
- 'web_fetch',
393
- 'code_execution',
394
- 'computer_use',
395
- 'bash',
396
- 'text_editor',
397
- 'memory',
398
- ],
399
- },
400
- } as const satisfies ModelMeta<
401
- AnthropicContainerOptions &
402
- AnthropicContextManagementOptions &
403
- AnthropicMCPOptions &
404
- AnthropicServiceTierOptions &
405
- AnthropicStopSequencesOptions &
406
- AnthropicThinkingOptions &
407
- AnthropicToolChoiceOptions &
408
- AnthropicSamplingOptions
409
- >
410
-
411
- const CLAUDE_HAIKU_3_5 = {
412
- name: 'claude-haiku-3-5',
413
- id: 'claude-3-5-haiku',
414
- context_window: 200_000,
415
- max_output_tokens: 8_000,
416
- knowledge_cutoff: '2025-10-22',
417
- pricing: {
418
- input: {
419
- normal: 0.8,
420
- },
421
- output: {
422
- normal: 4,
423
- },
424
- },
425
- supports: {
426
- input: ['text', 'image', 'document'],
427
- extended_thinking: false,
428
- priority_tier: true,
429
- tools: ['web_search', 'web_fetch'],
430
- },
431
- } as const satisfies ModelMeta<
432
- AnthropicContainerOptions &
433
- AnthropicContextManagementOptions &
434
- AnthropicMCPOptions &
435
- AnthropicServiceTierOptions &
436
- AnthropicStopSequencesOptions &
437
- AnthropicThinkingOptions &
438
- AnthropicToolChoiceOptions &
439
- AnthropicSamplingOptions
440
- >
441
-
442
- const CLAUDE_HAIKU_3 = {
443
- name: 'claude-haiku-3',
444
- id: 'claude-3-haiku',
445
- context_window: 200_000,
446
- max_output_tokens: 4_000,
447
- knowledge_cutoff: '2024-03-07',
448
- pricing: {
449
- input: {
450
- normal: 0.25,
451
- },
452
- output: {
453
- normal: 1.25,
454
- },
455
- },
456
- supports: {
457
- input: ['text', 'image', 'document'],
458
- extended_thinking: false,
459
- priority_tier: false,
460
- tools: ['web_search'],
461
- },
462
- } as const satisfies ModelMeta<
463
- AnthropicContainerOptions &
464
- AnthropicContextManagementOptions &
465
- AnthropicMCPOptions &
466
- AnthropicServiceTierOptions &
467
- AnthropicStopSequencesOptions &
468
- AnthropicThinkingOptions &
469
- AnthropicToolChoiceOptions &
470
- AnthropicSamplingOptions
471
- >
472
-
473
- /* const ANTHROPIC_MODEL_META = {
474
- [CLAUDE_OPUS_4_5.name]: CLAUDE_OPUS_4_5,
475
- [CLAUDE_SONNET_4_5.name]: CLAUDE_SONNET_4_5,
476
- [CLAUDE_HAIKU_4_5.name]: CLAUDE_HAIKU_4_5,
477
- [CLAUDE_OPUS_4_1.name]: CLAUDE_OPUS_4_1,
478
- [CLAUDE_SONNET_4.name]: CLAUDE_SONNET_4,
479
- [CLAUDE_SONNET_3_7.name]: CLAUDE_SONNET_3_7,
480
- [CLAUDE_OPUS_4.name]: CLAUDE_OPUS_4,
481
- [CLAUDE_HAIKU_3_5.name]: CLAUDE_HAIKU_3_5,
482
- [CLAUDE_HAIKU_3.name]: CLAUDE_HAIKU_3,
483
- } as const */
484
-
485
- /* export type AnthropicModelProviderOptions<
486
- TModel extends keyof AnthropicModelMetaMap,
487
- > =
488
- AnthropicModelMetaMap[TModel] extends ModelMeta<
489
- infer TProviderOptions,
490
- any,
491
- any
492
- >
493
- ? TProviderOptions
494
- : unknown */
495
-
496
- /* export type AnthropicModelToolCapabilities<
497
- TModel extends keyof AnthropicModelMetaMap,
498
- > =
499
- AnthropicModelMetaMap[TModel] extends ModelMeta<
500
- any,
501
- infer TToolCapabilities,
502
- any
503
- >
504
- ? TToolCapabilities
505
- : unknown
506
- */
507
- /* export type AnthropicModelMessageCapabilities<
508
- TModel extends keyof AnthropicModelMetaMap,
509
- > =
510
- AnthropicModelMetaMap[TModel] extends ModelMeta<
511
- any,
512
- any,
513
- infer TMessageCapabilities
514
- >
515
- ? TMessageCapabilities
516
- : unknown */
517
-
518
- const CLAUDE_OPUS_4_6_FAST = {
519
- name: 'claude-opus-4-6-fast',
520
- id: 'claude-opus-4-6-fast',
521
- context_window: 1_000_000,
522
- max_output_tokens: 128_000,
523
- supports: {
524
- input: ['text', 'image'],
525
- extended_thinking: true,
526
- priority_tier: true,
527
- tools: [
528
- 'web_search',
529
- 'web_fetch',
530
- 'code_execution',
531
- 'computer_use',
532
- 'bash',
533
- 'text_editor',
534
- 'memory',
535
- ],
536
- },
537
- pricing: {
538
- input: {
539
- normal: 30,
540
- cached: 3,
541
- },
542
- output: {
543
- normal: 150,
544
- },
545
- },
546
- } as const satisfies ModelMeta<
547
- AnthropicContainerOptions &
548
- AnthropicContextManagementOptions &
549
- AnthropicMCPOptions &
550
- AnthropicServiceTierOptions &
551
- AnthropicStopSequencesOptions &
552
- AnthropicThinkingOptions &
553
- AnthropicToolChoiceOptions &
554
- AnthropicSamplingOptions
555
- >
556
-
305
+ // Claude Opus 4.7 removed budget-based extended thinking and the sampling
306
+ // parameters (`temperature`, `top_p`, `top_k`) — sending either returns a
307
+ // 400. Use adaptive thinking with `output_config.effort` instead.
557
308
  const CLAUDE_OPUS_4_7 = {
558
309
  name: 'claude-opus-4-7',
559
310
  id: 'claude-opus-4-7',
560
311
  context_window: 1_000_000,
561
312
  max_output_tokens: 128_000,
562
313
  supports: {
563
- input: ['text', 'image'],
564
- extended_thinking: true,
314
+ input: ['text', 'image', 'document'],
315
+ extended_thinking: false,
316
+ adaptive_thinking: true,
565
317
  priority_tier: true,
566
318
  tools: [
567
319
  'web_search',
@@ -588,58 +340,23 @@ const CLAUDE_OPUS_4_7 = {
588
340
  AnthropicMCPOptions &
589
341
  AnthropicServiceTierOptions &
590
342
  AnthropicStopSequencesOptions &
591
- AnthropicThinkingOptions &
343
+ AnthropicAdaptiveOrDisabledThinkingOptions &
592
344
  AnthropicToolChoiceOptions &
593
- AnthropicSamplingOptions
594
- >
595
-
596
- const CLAUDE_OPUS_4_7_FAST = {
597
- name: 'claude-opus-4-7-fast',
598
- id: 'claude-opus-4-7-fast',
599
- context_window: 1_000_000,
600
- max_output_tokens: 128_000,
601
- supports: {
602
- input: ['text', 'image', 'document'],
603
- extended_thinking: true,
604
- priority_tier: true,
605
- tools: [
606
- 'web_search',
607
- 'web_fetch',
608
- 'code_execution',
609
- 'computer_use',
610
- 'bash',
611
- 'text_editor',
612
- 'memory',
613
- ],
614
- },
615
- pricing: {
616
- input: {
617
- normal: 30,
618
- cached: 3,
619
- },
620
- output: {
621
- normal: 150,
622
- },
623
- },
624
- } as const satisfies ModelMeta<
625
- AnthropicContainerOptions &
626
- AnthropicContextManagementOptions &
627
- AnthropicMCPOptions &
628
- AnthropicServiceTierOptions &
629
- AnthropicStopSequencesOptions &
630
- AnthropicThinkingOptions &
631
- AnthropicToolChoiceOptions &
632
- AnthropicSamplingOptions
345
+ AnthropicMaxTokensOptions &
346
+ AnthropicOutputConfigOptions
633
347
  >
634
348
 
349
+ // Claude Opus 4.8 keeps the same request surface as Opus 4.7: adaptive
350
+ // thinking only (budget_tokens 400s), no sampling parameters.
635
351
  const CLAUDE_OPUS_4_8 = {
636
- name: 'claude-opus-4.8',
637
- id: 'claude-opus-4.8',
352
+ name: 'claude-opus-4-8',
353
+ id: 'claude-opus-4-8',
638
354
  context_window: 1_000_000,
639
355
  max_output_tokens: 128_000,
640
356
  supports: {
641
357
  input: ['text', 'image', 'document'],
642
- extended_thinking: true,
358
+ extended_thinking: false,
359
+ adaptive_thinking: true,
643
360
  priority_tier: true,
644
361
  tools: [
645
362
  'web_search',
@@ -666,50 +383,17 @@ const CLAUDE_OPUS_4_8 = {
666
383
  AnthropicMCPOptions &
667
384
  AnthropicServiceTierOptions &
668
385
  AnthropicStopSequencesOptions &
669
- AnthropicThinkingOptions &
670
- AnthropicToolChoiceOptions &
671
- AnthropicSamplingOptions
672
- >
673
-
674
- const CLAUDE_OPUS_4_8_FAST = {
675
- name: 'claude-opus-4.8-fast',
676
- id: 'claude-opus-4.8-fast',
677
- context_window: 1_000_000,
678
- max_output_tokens: 128_000,
679
- supports: {
680
- input: ['text', 'image', 'document'],
681
- extended_thinking: true,
682
- priority_tier: true,
683
- tools: [
684
- 'web_search',
685
- 'web_fetch',
686
- 'code_execution',
687
- 'computer_use',
688
- 'bash',
689
- 'text_editor',
690
- 'memory',
691
- ],
692
- },
693
- pricing: {
694
- input: {
695
- normal: 10,
696
- cached: 1,
697
- },
698
- output: {
699
- normal: 50,
700
- },
701
- },
702
- } as const satisfies ModelMeta<
703
- AnthropicContainerOptions &
704
- AnthropicContextManagementOptions &
705
- AnthropicMCPOptions &
706
- AnthropicServiceTierOptions &
707
- AnthropicStopSequencesOptions &
708
- AnthropicThinkingOptions &
386
+ AnthropicAdaptiveOrDisabledThinkingOptions &
709
387
  AnthropicToolChoiceOptions &
710
- AnthropicSamplingOptions
388
+ AnthropicMaxTokensOptions &
389
+ AnthropicOutputConfigOptions
711
390
  >
712
391
 
392
+ // Claude Fable 5: thinking is always on — the only accepted explicit
393
+ // `thinking` config is `{type: 'adaptive'}` (disabled/budget_tokens 400),
394
+ // and the sampling parameters (`temperature`, `top_p`, `top_k`) are
395
+ // rejected. Its provider options therefore use the adaptive-only thinking
396
+ // shape and `max_tokens` without the sampling knobs.
713
397
  const CLAUDE_FABLE_5 = {
714
398
  name: 'claude-fable-5',
715
399
  id: 'claude-fable-5',
@@ -717,7 +401,8 @@ const CLAUDE_FABLE_5 = {
717
401
  max_output_tokens: 128_000,
718
402
  supports: {
719
403
  input: ['text', 'image', 'document'],
720
- extended_thinking: true,
404
+ extended_thinking: false,
405
+ adaptive_thinking: true,
721
406
  priority_tier: true,
722
407
  tools: [
723
408
  'web_search',
@@ -744,11 +429,18 @@ const CLAUDE_FABLE_5 = {
744
429
  AnthropicMCPOptions &
745
430
  AnthropicServiceTierOptions &
746
431
  AnthropicStopSequencesOptions &
747
- AnthropicThinkingOptions &
432
+ AnthropicAdaptiveOnlyThinkingOptions &
748
433
  AnthropicToolChoiceOptions &
749
- AnthropicSamplingOptions
434
+ AnthropicMaxTokensOptions &
435
+ AnthropicOutputConfigOptions
750
436
  >
751
437
 
438
+ // Claude Sonnet 5: adaptive thinking is the default (omitting `thinking`
439
+ // runs adaptive); `{type: 'disabled'}` opts out, but the manual
440
+ // `{type: 'enabled', budget_tokens}` shape and non-default sampling
441
+ // parameters (`temperature`, `top_p`, `top_k`) are rejected with a 400.
442
+ // Pricing below is the sticker $3/$15 per MTok (an introductory $2/$10
443
+ // applies through 2026-08-31).
752
444
  const CLAUDE_SONNET_5 = {
753
445
  name: 'claude-sonnet-5',
754
446
  id: 'claude-sonnet-5',
@@ -756,7 +448,8 @@ const CLAUDE_SONNET_5 = {
756
448
  max_output_tokens: 128_000,
757
449
  supports: {
758
450
  input: ['text', 'image', 'document'],
759
- extended_thinking: true,
451
+ extended_thinking: false,
452
+ adaptive_thinking: true,
760
453
  priority_tier: true,
761
454
  tools: [
762
455
  'web_search',
@@ -770,11 +463,11 @@ const CLAUDE_SONNET_5 = {
770
463
  },
771
464
  pricing: {
772
465
  input: {
773
- normal: 2,
774
- cached: 0.2,
466
+ normal: 3,
467
+ cached: 0.3,
775
468
  },
776
469
  output: {
777
- normal: 10,
470
+ normal: 15,
778
471
  },
779
472
  },
780
473
  } as const satisfies ModelMeta<
@@ -783,11 +476,21 @@ const CLAUDE_SONNET_5 = {
783
476
  AnthropicMCPOptions &
784
477
  AnthropicServiceTierOptions &
785
478
  AnthropicStopSequencesOptions &
786
- AnthropicThinkingOptions &
479
+ AnthropicAdaptiveOrDisabledThinkingOptions &
787
480
  AnthropicToolChoiceOptions &
788
- AnthropicSamplingOptions
481
+ AnthropicMaxTokensOptions &
482
+ AnthropicOutputConfigOptions
789
483
  >
790
484
 
485
+ /**
486
+ * Model ids accepted by the Anthropic text adapter.
487
+ *
488
+ * Every id here resolves against the first-party Anthropic API
489
+ * (`GET /v1/models/{id}`). Retired models (Claude 3.x, Sonnet 3.7,
490
+ * Opus 4 / Sonnet 4) and the `-fast` variant ids (fast mode is requested
491
+ * via the `speed` parameter, not a model id) were removed after Anthropic
492
+ * turned them off.
493
+ */
791
494
  export const ANTHROPIC_MODELS = [
792
495
  CLAUDE_OPUS_4_6.id,
793
496
  CLAUDE_OPUS_4_5.id,
@@ -795,25 +498,89 @@ export const ANTHROPIC_MODELS = [
795
498
  CLAUDE_SONNET_4_5.id,
796
499
  CLAUDE_HAIKU_4_5.id,
797
500
  CLAUDE_OPUS_4_1.id,
798
- CLAUDE_SONNET_4.id,
799
- CLAUDE_SONNET_3_7.id,
800
- CLAUDE_OPUS_4.id,
801
- CLAUDE_HAIKU_3_5.id,
802
- CLAUDE_HAIKU_3.id,
803
-
804
- CLAUDE_OPUS_4_6_FAST.id,
805
501
 
806
502
  CLAUDE_OPUS_4_7.id,
807
-
808
- CLAUDE_OPUS_4_7_FAST.id,
809
-
810
503
  CLAUDE_OPUS_4_8.id,
811
- CLAUDE_OPUS_4_8_FAST.id,
812
504
 
813
505
  CLAUDE_FABLE_5.id,
814
506
  CLAUDE_SONNET_5.id,
815
507
  ] as const
816
508
 
509
+ /**
510
+ * Fallback `max_tokens` ceiling for a model whose metadata carries no
511
+ * `max_output_tokens` (e.g. an unrecognized model id). Anthropic's Messages
512
+ * API *requires* `max_tokens`, so the adapter must always send a value. 64K is
513
+ * the output ceiling of the current mainstream Claude tier (Sonnet/Haiku 4.5),
514
+ * so it's a sane default for an unknown — almost certainly modern — model and
515
+ * avoids silently truncating long generations (issue #849). Recognized models
516
+ * use their exact `max_output_tokens` from {@link ANTHROPIC_MODEL_MAX_OUTPUT_TOKENS}
517
+ * (e.g. 128K for Opus), so this fallback only ever applies to ids not in the
518
+ * map.
519
+ */
520
+ export const ANTHROPIC_DEFAULT_MAX_OUTPUT_TOKENS = 64_000
521
+
522
+ /**
523
+ * Runtime lookup of each model's maximum output-token ceiling, keyed by model
524
+ * id. Lets the text adapter default the required `max_tokens` request field to
525
+ * the model's real ceiling when the caller doesn't specify one, rather than a
526
+ * low constant that truncates responses mid-stream (issue #849).
527
+ *
528
+ * Kept in sync with {@link ANTHROPIC_MODELS} by `scripts/sync-provider-models.ts`
529
+ * — when that script adds a model it also inserts the model's `max_output_tokens`
530
+ * here, so a freshly-synced model resolves to its real ceiling rather than the
531
+ * fallback above.
532
+ */
533
+ const ANTHROPIC_MODEL_MAX_OUTPUT_TOKENS: Record<string, number> = {
534
+ [CLAUDE_OPUS_4_6.id]: CLAUDE_OPUS_4_6.max_output_tokens,
535
+ [CLAUDE_OPUS_4_5.id]: CLAUDE_OPUS_4_5.max_output_tokens,
536
+ [CLAUDE_SONNET_4_6.id]: CLAUDE_SONNET_4_6.max_output_tokens,
537
+ [CLAUDE_SONNET_4_5.id]: CLAUDE_SONNET_4_5.max_output_tokens,
538
+ [CLAUDE_HAIKU_4_5.id]: CLAUDE_HAIKU_4_5.max_output_tokens,
539
+ [CLAUDE_OPUS_4_1.id]: CLAUDE_OPUS_4_1.max_output_tokens,
540
+ [CLAUDE_OPUS_4_7.id]: CLAUDE_OPUS_4_7.max_output_tokens,
541
+ [CLAUDE_OPUS_4_8.id]: CLAUDE_OPUS_4_8.max_output_tokens,
542
+ [CLAUDE_FABLE_5.id]: CLAUDE_FABLE_5.max_output_tokens,
543
+ [CLAUDE_SONNET_5.id]: CLAUDE_SONNET_5.max_output_tokens,
544
+ }
545
+
546
+ /**
547
+ * Largest `max_tokens` the Anthropic SDK permits on a **non-streaming**
548
+ * request. The SDK refuses to make a non-streaming call it estimates could
549
+ * exceed its 10-minute timeout, computed as
550
+ * `(60min * max_tokens) / 128_000 > 10min` — i.e. it throws
551
+ * `"Streaming is required for operations that may take longer than 10 minutes"`
552
+ * once `max_tokens > 128_000 * 10 / 60 ≈ 21_333`
553
+ * (`@anthropic-ai/sdk`'s `calculateNonstreamingTimeout`). The text adapter's
554
+ * only non-streaming call is the forced-tool `structuredOutput()` request, so
555
+ * its defaulted ceiling must stay at or below this; the streaming chat path
556
+ * keeps the model's full {@link getAnthropicDefaultMaxTokens} ceiling. We sit
557
+ * just under the boundary (`21_333` would round-trip to exactly 10min). This
558
+ * caps only the *default* — an explicit oversized `max_tokens` from the caller
559
+ * still surfaces the SDK's "use streaming" error, which is the correct signal.
560
+ */
561
+ export const ANTHROPIC_MAX_NONSTREAMING_TOKENS = 21_000
562
+
563
+ /**
564
+ * Resolve the default `max_tokens` for a model: its known `max_output_tokens`
565
+ * ceiling, or {@link ANTHROPIC_DEFAULT_MAX_OUTPUT_TOKENS} for unknown models.
566
+ * Callers that pass an explicit `max_tokens` bypass this entirely.
567
+ *
568
+ * Pass `stream: false` for non-streaming requests (the `structuredOutput()`
569
+ * path): the result is then clamped to {@link ANTHROPIC_MAX_NONSTREAMING_TOKENS}
570
+ * so the defaulted ceiling doesn't trip the SDK's non-streaming 10-minute guard
571
+ * (issue #849). Streaming requests (the default) are unaffected and get the
572
+ * model's full ceiling.
573
+ */
574
+ export function getAnthropicDefaultMaxTokens(
575
+ model: string,
576
+ { stream = true }: { stream?: boolean } = {},
577
+ ): number {
578
+ const ceiling =
579
+ ANTHROPIC_MODEL_MAX_OUTPUT_TOKENS[model] ??
580
+ ANTHROPIC_DEFAULT_MAX_OUTPUT_TOKENS
581
+ return stream ? ceiling : Math.min(ceiling, ANTHROPIC_MAX_NONSTREAMING_TOKENS)
582
+ }
583
+
817
584
  /**
818
585
  * Anthropic models that support combining `tools` + JSON-Schema-constrained
819
586
  * output in a single streaming Messages request (per issue #605). GA'd
@@ -824,9 +591,10 @@ export const ANTHROPIC_MODELS = [
824
591
  export const ANTHROPIC_COMBINED_TOOLS_AND_SCHEMA_MODELS = new Set<string>([
825
592
  CLAUDE_OPUS_4_5.id,
826
593
  CLAUDE_OPUS_4_6.id,
827
- CLAUDE_OPUS_4_6_FAST.id,
828
594
  CLAUDE_OPUS_4_7.id,
829
- CLAUDE_OPUS_4_7_FAST.id,
595
+ CLAUDE_OPUS_4_8.id,
596
+ CLAUDE_FABLE_5.id,
597
+ CLAUDE_SONNET_5.id,
830
598
  CLAUDE_SONNET_4_5.id,
831
599
  CLAUDE_SONNET_4_6.id,
832
600
  CLAUDE_HAIKU_4_5.id,
@@ -837,29 +605,32 @@ export const ANTHROPIC_COMBINED_TOOLS_AND_SCHEMA_MODELS = new Set<string>([
837
605
  // const ANTHROPIC_AUDIO_MODELS = [] as const
838
606
  // const ANTHROPIC_VIDEO_MODELS = [] as const
839
607
 
840
- /* type AnthropicModel = (typeof ANTHROPIC_MODELS)[number] */
841
608
  export type AnthropicChatModel = (typeof ANTHROPIC_MODELS)[number]
842
609
  // Manual type map for per-model provider options
843
- // Models are differentiated by extended_thinking and priority_tier support
610
+ // Models are differentiated by which thinking shapes and sampling
611
+ // parameters the API accepts.
844
612
  export type AnthropicChatModelProviderOptionsByName = {
845
- // Models with both extended_thinking and priority_tier
613
+ // 4.6 generation: adaptive thinking plus the deprecated budget-based
614
+ // shape; sampling parameters still accepted.
846
615
  [CLAUDE_OPUS_4_6.id]: AnthropicContainerOptions &
847
616
  AnthropicContextManagementOptions &
848
617
  AnthropicMCPOptions &
849
618
  AnthropicServiceTierOptions &
850
619
  AnthropicStopSequencesOptions &
851
- AnthropicThinkingOptions &
620
+ AnthropicAdaptiveThinkingOptions &
852
621
  AnthropicToolChoiceOptions &
853
622
  AnthropicSamplingOptions
854
- [CLAUDE_OPUS_4_5.id]: AnthropicContainerOptions &
623
+ [CLAUDE_SONNET_4_6.id]: AnthropicContainerOptions &
855
624
  AnthropicContextManagementOptions &
856
625
  AnthropicMCPOptions &
857
626
  AnthropicServiceTierOptions &
858
627
  AnthropicStopSequencesOptions &
859
- AnthropicThinkingOptions &
628
+ AnthropicAdaptiveThinkingOptions &
860
629
  AnthropicToolChoiceOptions &
861
630
  AnthropicSamplingOptions
862
- [CLAUDE_SONNET_4_6.id]: AnthropicContainerOptions &
631
+
632
+ // Pre-4.6 models: budget-based extended thinking and sampling parameters.
633
+ [CLAUDE_OPUS_4_5.id]: AnthropicContainerOptions &
863
634
  AnthropicContextManagementOptions &
864
635
  AnthropicMCPOptions &
865
636
  AnthropicServiceTierOptions &
@@ -891,103 +662,51 @@ export type AnthropicChatModelProviderOptionsByName = {
891
662
  AnthropicThinkingOptions &
892
663
  AnthropicToolChoiceOptions &
893
664
  AnthropicSamplingOptions
894
- [CLAUDE_SONNET_4.id]: AnthropicContainerOptions &
895
- AnthropicContextManagementOptions &
896
- AnthropicMCPOptions &
897
- AnthropicServiceTierOptions &
898
- AnthropicStopSequencesOptions &
899
- AnthropicThinkingOptions &
900
- AnthropicToolChoiceOptions &
901
- AnthropicSamplingOptions
902
- [CLAUDE_SONNET_3_7.id]: AnthropicContainerOptions &
903
- AnthropicContextManagementOptions &
904
- AnthropicMCPOptions &
905
- AnthropicServiceTierOptions &
906
- AnthropicStopSequencesOptions &
907
- AnthropicThinkingOptions &
908
- AnthropicToolChoiceOptions &
909
- AnthropicSamplingOptions
910
- [CLAUDE_OPUS_4.id]: AnthropicContainerOptions &
911
- AnthropicContextManagementOptions &
912
- AnthropicMCPOptions &
913
- AnthropicServiceTierOptions &
914
- AnthropicStopSequencesOptions &
915
- AnthropicThinkingOptions &
916
- AnthropicToolChoiceOptions &
917
- AnthropicSamplingOptions
918
-
919
- // Model with priority_tier but NO extended_thinking
920
- [CLAUDE_HAIKU_3_5.id]: AnthropicContainerOptions &
921
- AnthropicContextManagementOptions &
922
- AnthropicMCPOptions &
923
- AnthropicServiceTierOptions &
924
- AnthropicStopSequencesOptions &
925
- AnthropicToolChoiceOptions &
926
- AnthropicSamplingOptions
927
665
 
928
- // Model with neither extended_thinking nor priority_tier
929
- [CLAUDE_HAIKU_3.id]: AnthropicContainerOptions &
930
- AnthropicContextManagementOptions &
931
- AnthropicMCPOptions &
932
- AnthropicStopSequencesOptions &
933
- AnthropicToolChoiceOptions &
934
- AnthropicSamplingOptions
935
- [CLAUDE_OPUS_4_6_FAST.id]: AnthropicContainerOptions &
936
- AnthropicContextManagementOptions &
937
- AnthropicMCPOptions &
938
- AnthropicServiceTierOptions &
939
- AnthropicStopSequencesOptions &
940
- AnthropicThinkingOptions &
941
- AnthropicToolChoiceOptions &
942
- AnthropicSamplingOptions
666
+ // Opus 4.7/4.8: adaptive thinking (or explicit disable), no
667
+ // budget_tokens, no sampling parameters — see the constants above.
943
668
  [CLAUDE_OPUS_4_7.id]: AnthropicContainerOptions &
944
669
  AnthropicContextManagementOptions &
945
670
  AnthropicMCPOptions &
946
671
  AnthropicServiceTierOptions &
947
672
  AnthropicStopSequencesOptions &
948
- AnthropicThinkingOptions &
949
- AnthropicToolChoiceOptions &
950
- AnthropicSamplingOptions
951
- [CLAUDE_OPUS_4_7_FAST.id]: AnthropicContainerOptions &
952
- AnthropicContextManagementOptions &
953
- AnthropicMCPOptions &
954
- AnthropicServiceTierOptions &
955
- AnthropicStopSequencesOptions &
956
- AnthropicThinkingOptions &
673
+ AnthropicAdaptiveOrDisabledThinkingOptions &
957
674
  AnthropicToolChoiceOptions &
958
- AnthropicSamplingOptions
675
+ AnthropicMaxTokensOptions &
676
+ AnthropicOutputConfigOptions
959
677
  [CLAUDE_OPUS_4_8.id]: AnthropicContainerOptions &
960
678
  AnthropicContextManagementOptions &
961
679
  AnthropicMCPOptions &
962
680
  AnthropicServiceTierOptions &
963
681
  AnthropicStopSequencesOptions &
964
- AnthropicThinkingOptions &
682
+ AnthropicAdaptiveOrDisabledThinkingOptions &
965
683
  AnthropicToolChoiceOptions &
966
- AnthropicSamplingOptions
967
- [CLAUDE_OPUS_4_8_FAST.id]: AnthropicContainerOptions &
968
- AnthropicContextManagementOptions &
969
- AnthropicMCPOptions &
970
- AnthropicServiceTierOptions &
971
- AnthropicStopSequencesOptions &
972
- AnthropicThinkingOptions &
973
- AnthropicToolChoiceOptions &
974
- AnthropicSamplingOptions
684
+ AnthropicMaxTokensOptions &
685
+ AnthropicOutputConfigOptions
686
+
687
+ // Claude Fable 5: thinking always on (adaptive-only config); sampling
688
+ // parameters removed — see the CLAUDE_FABLE_5 constant above.
975
689
  [CLAUDE_FABLE_5.id]: AnthropicContainerOptions &
976
690
  AnthropicContextManagementOptions &
977
691
  AnthropicMCPOptions &
978
692
  AnthropicServiceTierOptions &
979
693
  AnthropicStopSequencesOptions &
980
- AnthropicThinkingOptions &
694
+ AnthropicAdaptiveOnlyThinkingOptions &
981
695
  AnthropicToolChoiceOptions &
982
- AnthropicSamplingOptions
696
+ AnthropicMaxTokensOptions &
697
+ AnthropicOutputConfigOptions
698
+ // Claude Sonnet 5: adaptive thinking by default, explicit disable
699
+ // allowed; no budget_tokens, no sampling parameters — see the
700
+ // CLAUDE_SONNET_5 constant above.
983
701
  [CLAUDE_SONNET_5.id]: AnthropicContainerOptions &
984
702
  AnthropicContextManagementOptions &
985
703
  AnthropicMCPOptions &
986
704
  AnthropicServiceTierOptions &
987
705
  AnthropicStopSequencesOptions &
988
- AnthropicThinkingOptions &
706
+ AnthropicAdaptiveOrDisabledThinkingOptions &
989
707
  AnthropicToolChoiceOptions &
990
- AnthropicSamplingOptions
708
+ AnthropicMaxTokensOptions &
709
+ AnthropicOutputConfigOptions
991
710
  }
992
711
 
993
712
  export type AnthropicChatModelToolCapabilitiesByName = {
@@ -997,13 +716,10 @@ export type AnthropicChatModelToolCapabilitiesByName = {
997
716
  [CLAUDE_SONNET_4_5.id]: typeof CLAUDE_SONNET_4_5.supports.tools
998
717
  [CLAUDE_HAIKU_4_5.id]: typeof CLAUDE_HAIKU_4_5.supports.tools
999
718
  [CLAUDE_OPUS_4_1.id]: typeof CLAUDE_OPUS_4_1.supports.tools
1000
- [CLAUDE_SONNET_4.id]: typeof CLAUDE_SONNET_4.supports.tools
1001
- [CLAUDE_SONNET_3_7.id]: typeof CLAUDE_SONNET_3_7.supports.tools
1002
- [CLAUDE_OPUS_4.id]: typeof CLAUDE_OPUS_4.supports.tools
1003
- [CLAUDE_HAIKU_3_5.id]: typeof CLAUDE_HAIKU_3_5.supports.tools
1004
- [CLAUDE_HAIKU_3.id]: typeof CLAUDE_HAIKU_3.supports.tools
1005
- [CLAUDE_OPUS_4_6_FAST.id]: typeof CLAUDE_OPUS_4_6_FAST.supports.tools
1006
719
  [CLAUDE_OPUS_4_7.id]: typeof CLAUDE_OPUS_4_7.supports.tools
720
+ [CLAUDE_OPUS_4_8.id]: typeof CLAUDE_OPUS_4_8.supports.tools
721
+ [CLAUDE_FABLE_5.id]: typeof CLAUDE_FABLE_5.supports.tools
722
+ [CLAUDE_SONNET_5.id]: typeof CLAUDE_SONNET_5.supports.tools
1007
723
  }
1008
724
 
1009
725
  /**
@@ -1024,16 +740,8 @@ export type AnthropicModelInputModalitiesByName = {
1024
740
  [CLAUDE_SONNET_4_5.id]: typeof CLAUDE_SONNET_4_5.supports.input
1025
741
  [CLAUDE_HAIKU_4_5.id]: typeof CLAUDE_HAIKU_4_5.supports.input
1026
742
  [CLAUDE_OPUS_4_1.id]: typeof CLAUDE_OPUS_4_1.supports.input
1027
- [CLAUDE_SONNET_4.id]: typeof CLAUDE_SONNET_4.supports.input
1028
- [CLAUDE_SONNET_3_7.id]: typeof CLAUDE_SONNET_3_7.supports.input
1029
- [CLAUDE_OPUS_4.id]: typeof CLAUDE_OPUS_4.supports.input
1030
- [CLAUDE_HAIKU_3_5.id]: typeof CLAUDE_HAIKU_3_5.supports.input
1031
- [CLAUDE_HAIKU_3.id]: typeof CLAUDE_HAIKU_3.supports.input
1032
- [CLAUDE_OPUS_4_6_FAST.id]: typeof CLAUDE_OPUS_4_6_FAST.supports.input
1033
743
  [CLAUDE_OPUS_4_7.id]: typeof CLAUDE_OPUS_4_7.supports.input
1034
- [CLAUDE_OPUS_4_7_FAST.id]: typeof CLAUDE_OPUS_4_7_FAST.supports.input
1035
744
  [CLAUDE_OPUS_4_8.id]: typeof CLAUDE_OPUS_4_8.supports.input
1036
- [CLAUDE_OPUS_4_8_FAST.id]: typeof CLAUDE_OPUS_4_8_FAST.supports.input
1037
745
  [CLAUDE_FABLE_5.id]: typeof CLAUDE_FABLE_5.supports.input
1038
746
  [CLAUDE_SONNET_5.id]: typeof CLAUDE_SONNET_5.supports.input
1039
747
  }