anthropic 0.74.1__py3-none-any.whl → 0.76.0__py3-none-any.whl

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.
Files changed (84) hide show
  1. anthropic/_base_client.py +140 -11
  2. anthropic/_client.py +4 -12
  3. anthropic/_models.py +16 -1
  4. anthropic/_streaming.py +78 -76
  5. anthropic/_types.py +12 -2
  6. anthropic/_version.py +1 -1
  7. anthropic/lib/streaming/_beta_messages.py +1 -1
  8. anthropic/lib/tools/_beta_compaction_control.py +48 -0
  9. anthropic/lib/tools/_beta_functions.py +30 -8
  10. anthropic/lib/tools/_beta_runner.py +233 -34
  11. anthropic/resources/beta/messages/messages.py +134 -27
  12. anthropic/resources/messages/messages.py +4 -0
  13. anthropic/types/anthropic_beta_param.py +1 -0
  14. anthropic/types/beta/__init__.py +31 -0
  15. anthropic/types/beta/beta_code_execution_tool_20250522_param.py +9 -1
  16. anthropic/types/beta/beta_code_execution_tool_20250825_param.py +9 -1
  17. anthropic/types/beta/beta_container.py +4 -0
  18. anthropic/types/beta/beta_container_params.py +2 -0
  19. anthropic/types/beta/beta_container_upload_block.py +2 -0
  20. anthropic/types/beta/beta_container_upload_block_param.py +5 -0
  21. anthropic/types/beta/beta_content_block.py +2 -0
  22. anthropic/types/beta/beta_content_block_param.py +2 -0
  23. anthropic/types/beta/beta_direct_caller.py +13 -0
  24. anthropic/types/beta/beta_direct_caller_param.py +13 -0
  25. anthropic/types/beta/beta_mcp_tool_config_param.py +15 -0
  26. anthropic/types/beta/beta_mcp_tool_default_config_param.py +15 -0
  27. anthropic/types/beta/beta_mcp_toolset_param.py +34 -0
  28. anthropic/types/beta/beta_memory_tool_20250818_param.py +11 -1
  29. anthropic/types/beta/beta_output_config_param.py +13 -0
  30. anthropic/types/beta/beta_raw_content_block_start_event.py +2 -0
  31. anthropic/types/beta/beta_server_tool_caller.py +15 -0
  32. anthropic/types/beta/beta_server_tool_caller_param.py +15 -0
  33. anthropic/types/beta/beta_server_tool_use_block.py +20 -4
  34. anthropic/types/beta/beta_server_tool_use_block_param.py +19 -4
  35. anthropic/types/beta/beta_skill.py +2 -0
  36. anthropic/types/beta/beta_skill_params.py +2 -0
  37. anthropic/types/beta/beta_tool_bash_20241022_param.py +11 -1
  38. anthropic/types/beta/beta_tool_bash_20250124_param.py +11 -1
  39. anthropic/types/beta/beta_tool_choice_any_param.py +2 -0
  40. anthropic/types/beta/beta_tool_choice_auto_param.py +2 -0
  41. anthropic/types/beta/beta_tool_choice_none_param.py +2 -0
  42. anthropic/types/beta/beta_tool_choice_tool_param.py +2 -0
  43. anthropic/types/beta/beta_tool_computer_use_20241022_param.py +11 -1
  44. anthropic/types/beta/beta_tool_computer_use_20250124_param.py +11 -1
  45. anthropic/types/beta/beta_tool_computer_use_20251124_param.py +47 -0
  46. anthropic/types/beta/beta_tool_param.py +16 -1
  47. anthropic/types/beta/beta_tool_reference_block.py +13 -0
  48. anthropic/types/beta/beta_tool_reference_block_param.py +21 -0
  49. anthropic/types/beta/beta_tool_result_block_param.py +6 -1
  50. anthropic/types/beta/beta_tool_search_tool_bm25_20251119_param.py +33 -0
  51. anthropic/types/beta/beta_tool_search_tool_regex_20251119_param.py +33 -0
  52. anthropic/types/beta/beta_tool_search_tool_result_block.py +20 -0
  53. anthropic/types/beta/beta_tool_search_tool_result_block_param.py +25 -0
  54. anthropic/types/beta/beta_tool_search_tool_result_error.py +16 -0
  55. anthropic/types/beta/beta_tool_search_tool_result_error_param.py +13 -0
  56. anthropic/types/beta/beta_tool_search_tool_search_result_block.py +15 -0
  57. anthropic/types/beta/beta_tool_search_tool_search_result_block_param.py +16 -0
  58. anthropic/types/beta/beta_tool_text_editor_20241022_param.py +11 -1
  59. anthropic/types/beta/beta_tool_text_editor_20250124_param.py +11 -1
  60. anthropic/types/beta/beta_tool_text_editor_20250429_param.py +11 -1
  61. anthropic/types/beta/beta_tool_text_editor_20250728_param.py +11 -1
  62. anthropic/types/beta/beta_tool_union_param.py +8 -0
  63. anthropic/types/beta/beta_tool_use_block.py +11 -3
  64. anthropic/types/beta/beta_tool_use_block_param.py +10 -3
  65. anthropic/types/beta/beta_web_fetch_tool_20250910_param.py +9 -1
  66. anthropic/types/beta/beta_web_search_tool_20250305_param.py +14 -1
  67. anthropic/types/beta/message_count_tokens_params.py +15 -0
  68. anthropic/types/beta/message_create_params.py +7 -0
  69. anthropic/types/beta/messages/batch_create_params.py +4 -4
  70. anthropic/types/beta/messages/beta_message_batch_individual_response.py +4 -0
  71. anthropic/types/messages/batch_create_params.py +2 -2
  72. anthropic/types/messages/message_batch_individual_response.py +4 -0
  73. anthropic/types/model.py +2 -0
  74. anthropic/types/model_param.py +2 -0
  75. anthropic/types/tool_choice_any_param.py +2 -0
  76. anthropic/types/tool_choice_auto_param.py +2 -0
  77. anthropic/types/tool_choice_none_param.py +2 -0
  78. anthropic/types/tool_choice_tool_param.py +2 -0
  79. anthropic/types/tool_param.py +5 -0
  80. anthropic/types/web_search_tool_20250305_param.py +5 -0
  81. {anthropic-0.74.1.dist-info → anthropic-0.76.0.dist-info}/METADATA +4 -2
  82. {anthropic-0.74.1.dist-info → anthropic-0.76.0.dist-info}/RECORD +84 -64
  83. {anthropic-0.74.1.dist-info → anthropic-0.76.0.dist-info}/WHEEL +0 -0
  84. {anthropic-0.74.1.dist-info → anthropic-0.76.0.dist-info}/licenses/LICENSE +0 -0
@@ -41,13 +41,21 @@ from ....types.beta import (
41
41
  message_count_tokens_params,
42
42
  )
43
43
  from ...._base_client import make_request_options
44
+ from ...._utils._utils import is_dict
44
45
  from ....lib.streaming import BetaMessageStreamManager, BetaAsyncMessageStreamManager
45
46
  from ...messages.messages import DEPRECATED_MODELS
46
47
  from ....types.model_param import ModelParam
47
48
  from ....lib._parse._response import ResponseFormatT, parse_response
48
49
  from ....lib._parse._transform import transform_schema
49
50
  from ....types.beta.beta_message import BetaMessage
50
- from ....lib.tools._beta_functions import BetaRunnableTool, BetaAsyncRunnableTool
51
+ from ....lib.tools._beta_functions import (
52
+ BetaFunctionTool,
53
+ BetaRunnableTool,
54
+ BetaAsyncFunctionTool,
55
+ BetaAsyncRunnableTool,
56
+ BetaBuiltinFunctionTool,
57
+ BetaAsyncBuiltinFunctionTool,
58
+ )
51
59
  from ....types.anthropic_beta_param import AnthropicBetaParam
52
60
  from ....types.beta.beta_message_param import BetaMessageParam
53
61
  from ....types.beta.beta_metadata_param import BetaMetadataParam
@@ -55,6 +63,8 @@ from ....types.beta.parsed_beta_message import ParsedBetaMessage
55
63
  from ....types.beta.beta_text_block_param import BetaTextBlockParam
56
64
  from ....types.beta.beta_tool_union_param import BetaToolUnionParam
57
65
  from ....types.beta.beta_tool_choice_param import BetaToolChoiceParam
66
+ from ....lib.tools._beta_compaction_control import CompactionControl
67
+ from ....types.beta.beta_output_config_param import BetaOutputConfigParam
58
68
  from ....types.beta.beta_message_tokens_count import BetaMessageTokensCount
59
69
  from ....types.beta.beta_thinking_config_param import BetaThinkingConfigParam
60
70
  from ....types.beta.beta_json_output_format_param import BetaJSONOutputFormatParam
@@ -103,6 +113,7 @@ class Messages(SyncAPIResource):
103
113
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
104
114
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
105
115
  metadata: BetaMetadataParam | Omit = omit,
116
+ output_config: BetaOutputConfigParam | Omit = omit,
106
117
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
107
118
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
108
119
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -222,6 +233,9 @@ class Messages(SyncAPIResource):
222
233
 
223
234
  metadata: An object describing metadata about the request.
224
235
 
236
+ output_config: Configuration options for the model's output. Controls aspects like how much
237
+ effort the model puts into its response.
238
+
225
239
  output_format: A schema to specify Claude's output format in responses.
226
240
 
227
241
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
@@ -390,6 +404,7 @@ class Messages(SyncAPIResource):
390
404
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
391
405
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
392
406
  metadata: BetaMetadataParam | Omit = omit,
407
+ output_config: BetaOutputConfigParam | Omit = omit,
393
408
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
394
409
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
395
410
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -512,6 +527,9 @@ class Messages(SyncAPIResource):
512
527
 
513
528
  metadata: An object describing metadata about the request.
514
529
 
530
+ output_config: Configuration options for the model's output. Controls aspects like how much
531
+ effort the model puts into its response.
532
+
515
533
  output_format: A schema to specify Claude's output format in responses.
516
534
 
517
535
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
@@ -676,6 +694,7 @@ class Messages(SyncAPIResource):
676
694
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
677
695
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
678
696
  metadata: BetaMetadataParam | Omit = omit,
697
+ output_config: BetaOutputConfigParam | Omit = omit,
679
698
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
680
699
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
681
700
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -798,6 +817,9 @@ class Messages(SyncAPIResource):
798
817
 
799
818
  metadata: An object describing metadata about the request.
800
819
 
820
+ output_config: Configuration options for the model's output. Controls aspects like how much
821
+ effort the model puts into its response.
822
+
801
823
  output_format: A schema to specify Claude's output format in responses.
802
824
 
803
825
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
@@ -961,6 +983,7 @@ class Messages(SyncAPIResource):
961
983
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
962
984
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
963
985
  metadata: BetaMetadataParam | Omit = omit,
986
+ output_config: BetaOutputConfigParam | Omit = omit,
964
987
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
965
988
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
966
989
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -1009,6 +1032,7 @@ class Messages(SyncAPIResource):
1009
1032
  "context_management": context_management,
1010
1033
  "mcp_servers": mcp_servers,
1011
1034
  "metadata": metadata,
1035
+ "output_config": output_config,
1012
1036
  "output_format": output_format,
1013
1037
  "service_tier": service_tier,
1014
1038
  "stop_sequences": stop_sequences,
@@ -1043,6 +1067,7 @@ class Messages(SyncAPIResource):
1043
1067
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1044
1068
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1045
1069
  metadata: BetaMetadataParam | Omit = omit,
1070
+ output_config: BetaOutputConfigParam | Omit = omit,
1046
1071
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
1047
1072
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1048
1073
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -1124,6 +1149,7 @@ class Messages(SyncAPIResource):
1124
1149
  "context_management": context_management,
1125
1150
  "mcp_servers": mcp_servers,
1126
1151
  "metadata": metadata,
1152
+ "output_config": output_config,
1127
1153
  "output_format": transformed_output_format,
1128
1154
  "service_tier": service_tier,
1129
1155
  "stop_sequences": stop_sequences,
@@ -1156,12 +1182,14 @@ class Messages(SyncAPIResource):
1156
1182
  max_tokens: int,
1157
1183
  messages: Iterable[BetaMessageParam],
1158
1184
  model: ModelParam,
1159
- tools: Iterable[BetaRunnableTool],
1185
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1186
+ compaction_control: CompactionControl | Omit = omit,
1160
1187
  container: Optional[message_create_params.Container] | Omit = omit,
1161
1188
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1162
1189
  max_iterations: int | Omit = omit,
1163
1190
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1164
1191
  metadata: BetaMetadataParam | Omit = omit,
1192
+ output_config: BetaOutputConfigParam | Omit = omit,
1165
1193
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
1166
1194
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1167
1195
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -1188,13 +1216,15 @@ class Messages(SyncAPIResource):
1188
1216
  max_tokens: int,
1189
1217
  messages: Iterable[BetaMessageParam],
1190
1218
  model: ModelParam,
1191
- tools: Iterable[BetaRunnableTool],
1219
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1220
+ compaction_control: CompactionControl | Omit = omit,
1192
1221
  stream: Literal[True],
1193
1222
  max_iterations: int | Omit = omit,
1194
1223
  container: Optional[message_create_params.Container] | Omit = omit,
1195
1224
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1196
1225
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1197
1226
  metadata: BetaMetadataParam | Omit = omit,
1227
+ output_config: BetaOutputConfigParam | Omit = omit,
1198
1228
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
1199
1229
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1200
1230
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -1220,13 +1250,15 @@ class Messages(SyncAPIResource):
1220
1250
  max_tokens: int,
1221
1251
  messages: Iterable[BetaMessageParam],
1222
1252
  model: ModelParam,
1223
- tools: Iterable[BetaRunnableTool],
1253
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1254
+ compaction_control: CompactionControl | Omit = omit,
1224
1255
  stream: bool,
1225
1256
  max_iterations: int | Omit = omit,
1226
1257
  container: Optional[message_create_params.Container] | Omit = omit,
1227
1258
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1228
1259
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1229
1260
  metadata: BetaMetadataParam | Omit = omit,
1261
+ output_config: BetaOutputConfigParam | Omit = omit,
1230
1262
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
1231
1263
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1232
1264
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -1251,12 +1283,14 @@ class Messages(SyncAPIResource):
1251
1283
  max_tokens: int,
1252
1284
  messages: Iterable[BetaMessageParam],
1253
1285
  model: ModelParam,
1254
- tools: Iterable[BetaRunnableTool],
1286
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1287
+ compaction_control: CompactionControl | Omit = omit,
1255
1288
  max_iterations: int | Omit = omit,
1256
1289
  container: Optional[message_create_params.Container] | Omit = omit,
1257
1290
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1258
1291
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1259
1292
  metadata: BetaMetadataParam | Omit = omit,
1293
+ output_config: BetaOutputConfigParam | Omit = omit,
1260
1294
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
1261
1295
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1262
1296
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -1289,6 +1323,15 @@ class Messages(SyncAPIResource):
1289
1323
  **(extra_headers or {}),
1290
1324
  }
1291
1325
 
1326
+ runnable_tools: list[BetaRunnableTool] = []
1327
+ raw_tools: list[BetaToolUnionParam] = []
1328
+
1329
+ for tool in tools:
1330
+ if isinstance(tool, (BetaFunctionTool, BetaBuiltinFunctionTool)):
1331
+ runnable_tools.append(tool)
1332
+ else:
1333
+ raw_tools.append(tool)
1334
+
1292
1335
  params = cast(
1293
1336
  message_create_params.ParseMessageCreateParamsBase[ResponseFormatT],
1294
1337
  {
@@ -1299,6 +1342,7 @@ class Messages(SyncAPIResource):
1299
1342
  "context_management": context_management,
1300
1343
  "mcp_servers": mcp_servers,
1301
1344
  "metadata": metadata,
1345
+ "output_config": output_config,
1302
1346
  "output_format": output_format,
1303
1347
  "service_tier": service_tier,
1304
1348
  "stop_sequences": stop_sequences,
@@ -1306,7 +1350,7 @@ class Messages(SyncAPIResource):
1306
1350
  "temperature": temperature,
1307
1351
  "thinking": thinking,
1308
1352
  "tool_choice": tool_choice,
1309
- "tools": [tool.to_dict() for tool in tools],
1353
+ "tools": [*[tool.to_dict() for tool in runnable_tools], *raw_tools],
1310
1354
  "top_k": top_k,
1311
1355
  "top_p": top_p,
1312
1356
  },
@@ -1314,7 +1358,7 @@ class Messages(SyncAPIResource):
1314
1358
 
1315
1359
  if stream:
1316
1360
  return BetaStreamingToolRunner[ResponseFormatT](
1317
- tools=tools,
1361
+ tools=runnable_tools,
1318
1362
  params=params,
1319
1363
  options={
1320
1364
  "extra_headers": extra_headers,
@@ -1324,9 +1368,10 @@ class Messages(SyncAPIResource):
1324
1368
  },
1325
1369
  client=cast("Anthropic", self._client),
1326
1370
  max_iterations=max_iterations if is_given(max_iterations) else None,
1371
+ compaction_control=compaction_control if is_given(compaction_control) else None,
1327
1372
  )
1328
1373
  return BetaToolRunner[ResponseFormatT](
1329
- tools=tools,
1374
+ tools=runnable_tools,
1330
1375
  params=params,
1331
1376
  options={
1332
1377
  "extra_headers": extra_headers,
@@ -1336,6 +1381,7 @@ class Messages(SyncAPIResource):
1336
1381
  },
1337
1382
  client=cast("Anthropic", self._client),
1338
1383
  max_iterations=max_iterations if is_given(max_iterations) else None,
1384
+ compaction_control=compaction_control if is_given(compaction_control) else None,
1339
1385
  )
1340
1386
 
1341
1387
  def stream(
@@ -1348,7 +1394,8 @@ class Messages(SyncAPIResource):
1348
1394
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1349
1395
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1350
1396
  metadata: BetaMetadataParam | Omit = omit,
1351
- output_format: Optional[type[ResponseFormatT]] | Omit = omit,
1397
+ output_config: BetaOutputConfigParam | Omit = omit,
1398
+ output_format: None | BetaJSONOutputFormatParam | type[ResponseFormatT] | Omit = omit,
1352
1399
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1353
1400
  stop_sequences: SequenceNotStr[str] | Omit = omit,
1354
1401
  system: Union[str, Iterable[BetaTextBlockParam]] | Omit = omit,
@@ -1375,19 +1422,22 @@ class Messages(SyncAPIResource):
1375
1422
 
1376
1423
  """Create a Message stream"""
1377
1424
  extra_headers = {
1425
+ "X-Stainless-Helper-Method": "stream",
1378
1426
  "X-Stainless-Stream-Helper": "beta.messages",
1379
1427
  **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
1380
1428
  **(extra_headers or {}),
1381
1429
  }
1382
1430
 
1383
- transformed_output_format: Optional[message_create_params.OutputFormat] | NotGiven = NOT_GIVEN
1431
+ transformed_output_format: Optional[BetaJSONOutputFormatParam] | NotGiven = NOT_GIVEN
1384
1432
 
1385
- if is_given(output_format) and output_format is not None:
1433
+ if is_dict(output_format):
1434
+ transformed_output_format = cast(BetaJSONOutputFormatParam, output_format)
1435
+ elif is_given(output_format) and output_format is not None:
1386
1436
  adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
1387
1437
 
1388
1438
  try:
1389
1439
  schema = adapted_type.json_schema()
1390
- transformed_output_format = message_create_params.OutputFormat(
1440
+ transformed_output_format = BetaJSONOutputFormatParam(
1391
1441
  schema=transform_schema(schema), type="json_schema"
1392
1442
  )
1393
1443
  except pydantic.errors.PydanticSchemaGenerationError as e:
@@ -1397,7 +1447,6 @@ class Messages(SyncAPIResource):
1397
1447
  "Use a type that works with `pydanitc.TypeAdapter`"
1398
1448
  )
1399
1449
  ) from e
1400
-
1401
1450
  make_request = partial(
1402
1451
  self._post,
1403
1452
  "/v1/messages?beta=true",
@@ -1407,6 +1456,7 @@ class Messages(SyncAPIResource):
1407
1456
  "messages": messages,
1408
1457
  "model": model,
1409
1458
  "metadata": metadata,
1459
+ "output_config": output_config,
1410
1460
  "output_format": transformed_output_format,
1411
1461
  "container": container,
1412
1462
  "context_management": context_management,
@@ -1431,7 +1481,10 @@ class Messages(SyncAPIResource):
1431
1481
  stream=True,
1432
1482
  stream_cls=Stream[BetaRawMessageStreamEvent],
1433
1483
  )
1434
- return BetaMessageStreamManager(make_request, output_format=cast(ResponseFormatT, output_format))
1484
+ return BetaMessageStreamManager(
1485
+ make_request,
1486
+ output_format=NOT_GIVEN if is_dict(output_format) else cast(ResponseFormatT, output_format),
1487
+ )
1435
1488
 
1436
1489
  def count_tokens(
1437
1490
  self,
@@ -1440,6 +1493,7 @@ class Messages(SyncAPIResource):
1440
1493
  model: ModelParam,
1441
1494
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1442
1495
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1496
+ output_config: BetaOutputConfigParam | Omit = omit,
1443
1497
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
1444
1498
  system: Union[str, Iterable[BetaTextBlockParam]] | Omit = omit,
1445
1499
  thinking: BetaThinkingConfigParam | Omit = omit,
@@ -1540,6 +1594,9 @@ class Messages(SyncAPIResource):
1540
1594
 
1541
1595
  mcp_servers: MCP servers to be utilized in this request
1542
1596
 
1597
+ output_config: Configuration options for the model's output. Controls aspects like how much
1598
+ effort the model puts into its response.
1599
+
1543
1600
  output_format: A schema to specify Claude's output format in responses.
1544
1601
 
1545
1602
  system: System prompt.
@@ -1666,6 +1723,7 @@ class Messages(SyncAPIResource):
1666
1723
  "model": model,
1667
1724
  "context_management": context_management,
1668
1725
  "mcp_servers": mcp_servers,
1726
+ "output_config": output_config,
1669
1727
  "output_format": output_format,
1670
1728
  "system": system,
1671
1729
  "thinking": thinking,
@@ -1716,6 +1774,7 @@ class AsyncMessages(AsyncAPIResource):
1716
1774
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
1717
1775
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1718
1776
  metadata: BetaMetadataParam | Omit = omit,
1777
+ output_config: BetaOutputConfigParam | Omit = omit,
1719
1778
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
1720
1779
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1721
1780
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -1835,6 +1894,9 @@ class AsyncMessages(AsyncAPIResource):
1835
1894
 
1836
1895
  metadata: An object describing metadata about the request.
1837
1896
 
1897
+ output_config: Configuration options for the model's output. Controls aspects like how much
1898
+ effort the model puts into its response.
1899
+
1838
1900
  output_format: A schema to specify Claude's output format in responses.
1839
1901
 
1840
1902
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
@@ -2003,6 +2065,7 @@ class AsyncMessages(AsyncAPIResource):
2003
2065
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2004
2066
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2005
2067
  metadata: BetaMetadataParam | Omit = omit,
2068
+ output_config: BetaOutputConfigParam | Omit = omit,
2006
2069
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
2007
2070
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2008
2071
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2125,6 +2188,9 @@ class AsyncMessages(AsyncAPIResource):
2125
2188
 
2126
2189
  metadata: An object describing metadata about the request.
2127
2190
 
2191
+ output_config: Configuration options for the model's output. Controls aspects like how much
2192
+ effort the model puts into its response.
2193
+
2128
2194
  output_format: A schema to specify Claude's output format in responses.
2129
2195
 
2130
2196
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
@@ -2289,6 +2355,7 @@ class AsyncMessages(AsyncAPIResource):
2289
2355
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2290
2356
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2291
2357
  metadata: BetaMetadataParam | Omit = omit,
2358
+ output_config: BetaOutputConfigParam | Omit = omit,
2292
2359
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
2293
2360
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2294
2361
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2411,6 +2478,9 @@ class AsyncMessages(AsyncAPIResource):
2411
2478
 
2412
2479
  metadata: An object describing metadata about the request.
2413
2480
 
2481
+ output_config: Configuration options for the model's output. Controls aspects like how much
2482
+ effort the model puts into its response.
2483
+
2414
2484
  output_format: A schema to specify Claude's output format in responses.
2415
2485
 
2416
2486
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
@@ -2574,6 +2644,7 @@ class AsyncMessages(AsyncAPIResource):
2574
2644
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2575
2645
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2576
2646
  metadata: BetaMetadataParam | Omit = omit,
2647
+ output_config: BetaOutputConfigParam | Omit = omit,
2577
2648
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
2578
2649
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2579
2650
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2622,6 +2693,7 @@ class AsyncMessages(AsyncAPIResource):
2622
2693
  "context_management": context_management,
2623
2694
  "mcp_servers": mcp_servers,
2624
2695
  "metadata": metadata,
2696
+ "output_config": output_config,
2625
2697
  "output_format": output_format,
2626
2698
  "service_tier": service_tier,
2627
2699
  "stop_sequences": stop_sequences,
@@ -2656,6 +2728,7 @@ class AsyncMessages(AsyncAPIResource):
2656
2728
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2657
2729
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2658
2730
  metadata: BetaMetadataParam | Omit = omit,
2731
+ output_config: BetaOutputConfigParam | Omit = omit,
2659
2732
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
2660
2733
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2661
2734
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2735,6 +2808,7 @@ class AsyncMessages(AsyncAPIResource):
2735
2808
  "container": container,
2736
2809
  "context_management": context_management,
2737
2810
  "mcp_servers": mcp_servers,
2811
+ "output_config": output_config,
2738
2812
  "metadata": metadata,
2739
2813
  "output_format": transformed_output_format,
2740
2814
  "service_tier": service_tier,
@@ -2768,12 +2842,14 @@ class AsyncMessages(AsyncAPIResource):
2768
2842
  max_tokens: int,
2769
2843
  messages: Iterable[BetaMessageParam],
2770
2844
  model: ModelParam,
2771
- tools: Iterable[BetaAsyncRunnableTool],
2845
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2846
+ compaction_control: CompactionControl | Omit = omit,
2772
2847
  max_iterations: int | Omit = omit,
2773
2848
  container: Optional[message_create_params.Container] | Omit = omit,
2774
2849
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2775
2850
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2776
2851
  metadata: BetaMetadataParam | Omit = omit,
2852
+ output_config: BetaOutputConfigParam | Omit = omit,
2777
2853
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
2778
2854
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2779
2855
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2800,13 +2876,15 @@ class AsyncMessages(AsyncAPIResource):
2800
2876
  max_tokens: int,
2801
2877
  messages: Iterable[BetaMessageParam],
2802
2878
  model: ModelParam,
2803
- tools: Iterable[BetaAsyncRunnableTool],
2879
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2880
+ compaction_control: CompactionControl | Omit = omit,
2804
2881
  stream: Literal[True],
2805
2882
  max_iterations: int | Omit = omit,
2806
2883
  container: Optional[message_create_params.Container] | Omit = omit,
2807
2884
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2808
2885
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2809
2886
  metadata: BetaMetadataParam | Omit = omit,
2887
+ output_config: BetaOutputConfigParam | Omit = omit,
2810
2888
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
2811
2889
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2812
2890
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2832,13 +2910,15 @@ class AsyncMessages(AsyncAPIResource):
2832
2910
  max_tokens: int,
2833
2911
  messages: Iterable[BetaMessageParam],
2834
2912
  model: ModelParam,
2835
- tools: Iterable[BetaAsyncRunnableTool],
2913
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2914
+ compaction_control: CompactionControl | Omit = omit,
2836
2915
  stream: bool,
2837
2916
  max_iterations: int | Omit = omit,
2838
2917
  container: Optional[message_create_params.Container] | Omit = omit,
2839
2918
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2840
2919
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2841
2920
  metadata: BetaMetadataParam | Omit = omit,
2921
+ output_config: BetaOutputConfigParam | Omit = omit,
2842
2922
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
2843
2923
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2844
2924
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2863,12 +2943,14 @@ class AsyncMessages(AsyncAPIResource):
2863
2943
  max_tokens: int,
2864
2944
  messages: Iterable[BetaMessageParam],
2865
2945
  model: ModelParam,
2866
- tools: Iterable[BetaAsyncRunnableTool],
2946
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2947
+ compaction_control: CompactionControl | Omit = omit,
2867
2948
  max_iterations: int | Omit = omit,
2868
2949
  container: Optional[message_create_params.Container] | Omit = omit,
2869
2950
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2870
2951
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
2871
2952
  metadata: BetaMetadataParam | Omit = omit,
2953
+ output_config: BetaOutputConfigParam | Omit = omit,
2872
2954
  output_format: Optional[type[ResponseFormatT]] | Omit = omit,
2873
2955
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
2874
2956
  stop_sequences: SequenceNotStr[str] | Omit = omit,
@@ -2901,6 +2983,15 @@ class AsyncMessages(AsyncAPIResource):
2901
2983
  **(extra_headers or {}),
2902
2984
  }
2903
2985
 
2986
+ runnable_tools: list[BetaAsyncRunnableTool] = []
2987
+ raw_tools: list[BetaToolUnionParam] = []
2988
+
2989
+ for tool in tools:
2990
+ if isinstance(tool, (BetaAsyncFunctionTool, BetaAsyncBuiltinFunctionTool)):
2991
+ runnable_tools.append(tool)
2992
+ else:
2993
+ raw_tools.append(tool)
2994
+
2904
2995
  params = cast(
2905
2996
  message_create_params.ParseMessageCreateParamsBase[ResponseFormatT],
2906
2997
  {
@@ -2911,6 +3002,7 @@ class AsyncMessages(AsyncAPIResource):
2911
3002
  "context_management": context_management,
2912
3003
  "mcp_servers": mcp_servers,
2913
3004
  "metadata": metadata,
3005
+ "output_config": output_config,
2914
3006
  "output_format": output_format,
2915
3007
  "service_tier": service_tier,
2916
3008
  "stop_sequences": stop_sequences,
@@ -2918,7 +3010,7 @@ class AsyncMessages(AsyncAPIResource):
2918
3010
  "temperature": temperature,
2919
3011
  "thinking": thinking,
2920
3012
  "tool_choice": tool_choice,
2921
- "tools": [tool.to_dict() for tool in tools],
3013
+ "tools": [*[tool.to_dict() for tool in runnable_tools], *raw_tools],
2922
3014
  "top_k": top_k,
2923
3015
  "top_p": top_p,
2924
3016
  },
@@ -2926,7 +3018,7 @@ class AsyncMessages(AsyncAPIResource):
2926
3018
 
2927
3019
  if stream:
2928
3020
  return BetaAsyncStreamingToolRunner[ResponseFormatT](
2929
- tools=tools,
3021
+ tools=runnable_tools,
2930
3022
  params=params,
2931
3023
  options={
2932
3024
  "extra_headers": extra_headers,
@@ -2936,9 +3028,10 @@ class AsyncMessages(AsyncAPIResource):
2936
3028
  },
2937
3029
  client=cast("AsyncAnthropic", self._client),
2938
3030
  max_iterations=max_iterations if is_given(max_iterations) else None,
3031
+ compaction_control=compaction_control if is_given(compaction_control) else None,
2939
3032
  )
2940
3033
  return BetaAsyncToolRunner[ResponseFormatT](
2941
- tools=tools,
3034
+ tools=runnable_tools,
2942
3035
  params=params,
2943
3036
  options={
2944
3037
  "extra_headers": extra_headers,
@@ -2948,6 +3041,7 @@ class AsyncMessages(AsyncAPIResource):
2948
3041
  },
2949
3042
  client=cast("AsyncAnthropic", self._client),
2950
3043
  max_iterations=max_iterations if is_given(max_iterations) else None,
3044
+ compaction_control=compaction_control if is_given(compaction_control) else None,
2951
3045
  )
2952
3046
 
2953
3047
  def stream(
@@ -2957,7 +3051,8 @@ class AsyncMessages(AsyncAPIResource):
2957
3051
  messages: Iterable[BetaMessageParam],
2958
3052
  model: ModelParam,
2959
3053
  metadata: BetaMetadataParam | Omit = omit,
2960
- output_format: Optional[type[ResponseFormatT]] | Omit = omit,
3054
+ output_config: BetaOutputConfigParam | Omit = omit,
3055
+ output_format: None | type[ResponseFormatT] | BetaJSONOutputFormatParam | Omit = omit,
2961
3056
  container: Optional[message_create_params.Container] | Omit = omit,
2962
3057
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
2963
3058
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
@@ -2986,19 +3081,22 @@ class AsyncMessages(AsyncAPIResource):
2986
3081
  )
2987
3082
 
2988
3083
  extra_headers = {
3084
+ "X-Stainless-Helper-Method": "stream",
2989
3085
  "X-Stainless-Stream-Helper": "beta.messages",
2990
3086
  **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
2991
3087
  **(extra_headers or {}),
2992
3088
  }
2993
3089
 
2994
- transformed_output_format: Optional[message_create_params.OutputFormat] | NotGiven = NOT_GIVEN
3090
+ transformed_output_format: Optional[BetaJSONOutputFormatParam] | NotGiven = NOT_GIVEN
2995
3091
 
2996
- if is_given(output_format) and output_format is not None:
3092
+ if is_dict(output_format):
3093
+ transformed_output_format = cast(BetaJSONOutputFormatParam, output_format)
3094
+ elif is_given(output_format) and output_format is not None:
2997
3095
  adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
2998
3096
 
2999
3097
  try:
3000
3098
  schema = adapted_type.json_schema()
3001
- transformed_output_format = message_create_params.OutputFormat(
3099
+ transformed_output_format = BetaJSONOutputFormatParam(
3002
3100
  schema=transform_schema(schema), type="json_schema"
3003
3101
  )
3004
3102
  except pydantic.errors.PydanticSchemaGenerationError as e:
@@ -3009,13 +3107,14 @@ class AsyncMessages(AsyncAPIResource):
3009
3107
  )
3010
3108
  ) from e
3011
3109
  request = self._post(
3012
- "/v1/messages",
3110
+ "/v1/messages?beta=true",
3013
3111
  body=maybe_transform(
3014
3112
  {
3015
3113
  "max_tokens": max_tokens,
3016
3114
  "messages": messages,
3017
3115
  "model": model,
3018
3116
  "metadata": metadata,
3117
+ "output_config": output_config,
3019
3118
  "output_format": transformed_output_format,
3020
3119
  "container": container,
3021
3120
  "context_management": context_management,
@@ -3040,7 +3139,10 @@ class AsyncMessages(AsyncAPIResource):
3040
3139
  stream=True,
3041
3140
  stream_cls=AsyncStream[BetaRawMessageStreamEvent],
3042
3141
  )
3043
- return BetaAsyncMessageStreamManager(request, output_format=cast(ResponseFormatT, output_format))
3142
+ return BetaAsyncMessageStreamManager(
3143
+ request,
3144
+ output_format=NOT_GIVEN if is_dict(output_format) else cast(ResponseFormatT, output_format),
3145
+ )
3044
3146
 
3045
3147
  async def count_tokens(
3046
3148
  self,
@@ -3049,6 +3151,7 @@ class AsyncMessages(AsyncAPIResource):
3049
3151
  model: ModelParam,
3050
3152
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
3051
3153
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
3154
+ output_config: BetaOutputConfigParam | Omit = omit,
3052
3155
  output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
3053
3156
  system: Union[str, Iterable[BetaTextBlockParam]] | Omit = omit,
3054
3157
  thinking: BetaThinkingConfigParam | Omit = omit,
@@ -3149,6 +3252,9 @@ class AsyncMessages(AsyncAPIResource):
3149
3252
 
3150
3253
  mcp_servers: MCP servers to be utilized in this request
3151
3254
 
3255
+ output_config: Configuration options for the model's output. Controls aspects like how much
3256
+ effort the model puts into its response.
3257
+
3152
3258
  output_format: A schema to specify Claude's output format in responses.
3153
3259
 
3154
3260
  system: System prompt.
@@ -3275,6 +3381,7 @@ class AsyncMessages(AsyncAPIResource):
3275
3381
  "model": model,
3276
3382
  "context_management": context_management,
3277
3383
  "mcp_servers": mcp_servers,
3384
+ "output_config": output_config,
3278
3385
  "output_format": output_format,
3279
3386
  "system": system,
3280
3387
  "thinking": thinking,
@@ -59,6 +59,8 @@ DEPRECATED_MODELS = {
59
59
  "claude-2.0": "July 21st, 2025",
60
60
  "claude-3-7-sonnet-latest": "February 19th, 2026",
61
61
  "claude-3-7-sonnet-20250219": "February 19th, 2026",
62
+ "claude-3-5-haiku-latest": "February 19th, 2026",
63
+ "claude-3-5-haiku-20241022": "February 19th, 2026",
62
64
  }
63
65
 
64
66
 
@@ -991,6 +993,7 @@ class Messages(SyncAPIResource):
991
993
  )
992
994
 
993
995
  extra_headers = {
996
+ "X-Stainless-Helper-Method": "stream",
994
997
  "X-Stainless-Stream-Helper": "messages",
995
998
  **(extra_headers or {}),
996
999
  }
@@ -2174,6 +2177,7 @@ class AsyncMessages(AsyncAPIResource):
2174
2177
  )
2175
2178
 
2176
2179
  extra_headers = {
2180
+ "X-Stainless-Helper-Method": "stream",
2177
2181
  "X-Stainless-Stream-Helper": "messages",
2178
2182
  **(extra_headers or {}),
2179
2183
  }
@@ -20,6 +20,7 @@ AnthropicBetaParam: TypeAlias = Union[
20
20
  "output-128k-2025-02-19",
21
21
  "files-api-2025-04-14",
22
22
  "mcp-client-2025-04-04",
23
+ "mcp-client-2025-11-20",
23
24
  "dev-full-thinking-2025-05-14",
24
25
  "interleaved-thinking-2025-05-14",
25
26
  "code-execution-2025-05-22",