anthropic 0.75.0__py3-none-any.whl → 0.77.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 (81) hide show
  1. anthropic/_base_client.py +145 -13
  2. anthropic/_client.py +4 -12
  3. anthropic/_compat.py +3 -3
  4. anthropic/_models.py +16 -1
  5. anthropic/_streaming.py +78 -76
  6. anthropic/_types.py +12 -2
  7. anthropic/_utils/_json.py +35 -0
  8. anthropic/_version.py +1 -1
  9. anthropic/lib/_parse/_response.py +29 -1
  10. anthropic/lib/streaming/__init__.py +3 -0
  11. anthropic/lib/streaming/_messages.py +74 -40
  12. anthropic/lib/streaming/_types.py +42 -2
  13. anthropic/lib/tools/_beta_compaction_control.py +2 -2
  14. anthropic/lib/tools/_beta_runner.py +17 -0
  15. anthropic/resources/beta/messages/messages.py +229 -83
  16. anthropic/resources/messages/messages.py +409 -5
  17. anthropic/types/__init__.py +7 -0
  18. anthropic/types/beta/beta_code_execution_tool_20250522_param.py +1 -0
  19. anthropic/types/beta/beta_code_execution_tool_20250825_param.py +1 -0
  20. anthropic/types/beta/beta_container.py +4 -0
  21. anthropic/types/beta/beta_container_params.py +2 -0
  22. anthropic/types/beta/beta_container_upload_block.py +2 -0
  23. anthropic/types/beta/beta_container_upload_block_param.py +5 -0
  24. anthropic/types/beta/beta_direct_caller.py +2 -0
  25. anthropic/types/beta/beta_direct_caller_param.py +2 -0
  26. anthropic/types/beta/beta_mcp_tool_config_param.py +2 -0
  27. anthropic/types/beta/beta_mcp_tool_default_config_param.py +2 -0
  28. anthropic/types/beta/beta_mcp_toolset_param.py +6 -0
  29. anthropic/types/beta/beta_memory_tool_20250818_param.py +1 -0
  30. anthropic/types/beta/beta_output_config_param.py +15 -1
  31. anthropic/types/beta/beta_server_tool_caller.py +2 -0
  32. anthropic/types/beta/beta_server_tool_caller_param.py +2 -0
  33. anthropic/types/beta/beta_server_tool_use_block.py +4 -4
  34. anthropic/types/beta/beta_skill.py +2 -0
  35. anthropic/types/beta/beta_skill_params.py +2 -0
  36. anthropic/types/beta/beta_tool_bash_20241022_param.py +1 -0
  37. anthropic/types/beta/beta_tool_bash_20250124_param.py +1 -0
  38. anthropic/types/beta/beta_tool_choice_any_param.py +2 -0
  39. anthropic/types/beta/beta_tool_choice_auto_param.py +2 -0
  40. anthropic/types/beta/beta_tool_choice_none_param.py +2 -0
  41. anthropic/types/beta/beta_tool_choice_tool_param.py +2 -0
  42. anthropic/types/beta/beta_tool_computer_use_20241022_param.py +1 -0
  43. anthropic/types/beta/beta_tool_computer_use_20250124_param.py +1 -0
  44. anthropic/types/beta/beta_tool_computer_use_20251124_param.py +1 -0
  45. anthropic/types/beta/beta_tool_param.py +6 -0
  46. anthropic/types/beta/beta_tool_reference_block_param.py +2 -0
  47. anthropic/types/beta/beta_tool_search_tool_bm25_20251119_param.py +1 -0
  48. anthropic/types/beta/beta_tool_search_tool_regex_20251119_param.py +1 -0
  49. anthropic/types/beta/beta_tool_text_editor_20241022_param.py +1 -0
  50. anthropic/types/beta/beta_tool_text_editor_20250124_param.py +1 -0
  51. anthropic/types/beta/beta_tool_text_editor_20250429_param.py +1 -0
  52. anthropic/types/beta/beta_tool_text_editor_20250728_param.py +1 -0
  53. anthropic/types/beta/beta_web_fetch_tool_20250910_param.py +1 -0
  54. anthropic/types/beta/beta_web_search_tool_20250305_param.py +6 -0
  55. anthropic/types/beta/beta_web_search_tool_result_error_code.py +1 -1
  56. anthropic/types/beta/message_count_tokens_params.py +9 -5
  57. anthropic/types/beta/message_create_params.py +9 -5
  58. anthropic/types/beta/messages/batch_create_params.py +2 -9
  59. anthropic/types/beta/messages/beta_message_batch_individual_response.py +4 -0
  60. anthropic/types/json_output_format_param.py +15 -0
  61. anthropic/types/message_count_tokens_params.py +4 -0
  62. anthropic/types/message_create_params.py +4 -0
  63. anthropic/types/messages/message_batch_individual_response.py +4 -0
  64. anthropic/types/output_config_param.py +19 -0
  65. anthropic/types/parsed_message.py +56 -0
  66. anthropic/types/tool_bash_20250124_param.py +3 -0
  67. anthropic/types/tool_choice_any_param.py +2 -0
  68. anthropic/types/tool_choice_auto_param.py +2 -0
  69. anthropic/types/tool_choice_none_param.py +2 -0
  70. anthropic/types/tool_choice_tool_param.py +2 -0
  71. anthropic/types/tool_param.py +8 -0
  72. anthropic/types/tool_text_editor_20250124_param.py +3 -0
  73. anthropic/types/tool_text_editor_20250429_param.py +3 -0
  74. anthropic/types/tool_text_editor_20250728_param.py +3 -0
  75. anthropic/types/web_search_tool_20250305_param.py +8 -0
  76. anthropic/types/web_search_tool_request_error_param.py +8 -1
  77. anthropic/types/web_search_tool_result_error.py +8 -1
  78. {anthropic-0.75.0.dist-info → anthropic-0.77.0.dist-info}/METADATA +4 -2
  79. {anthropic-0.75.0.dist-info → anthropic-0.77.0.dist-info}/RECORD +81 -77
  80. {anthropic-0.75.0.dist-info → anthropic-0.77.0.dist-info}/WHEEL +0 -0
  81. {anthropic-0.75.0.dist-info → anthropic-0.77.0.dist-info}/licenses/LICENSE +0 -0
@@ -40,14 +40,23 @@ from ....types.beta import (
40
40
  message_create_params,
41
41
  message_count_tokens_params,
42
42
  )
43
+ from ...._exceptions import AnthropicError
43
44
  from ...._base_client import make_request_options
45
+ from ...._utils._utils import is_dict
44
46
  from ....lib.streaming import BetaMessageStreamManager, BetaAsyncMessageStreamManager
45
47
  from ...messages.messages import DEPRECATED_MODELS
46
48
  from ....types.model_param import ModelParam
47
- from ....lib._parse._response import ResponseFormatT, parse_response
49
+ from ....lib._parse._response import ResponseFormatT, parse_beta_response
48
50
  from ....lib._parse._transform import transform_schema
49
51
  from ....types.beta.beta_message import BetaMessage
50
- from ....lib.tools._beta_functions import BetaRunnableTool, BetaAsyncRunnableTool
52
+ from ....lib.tools._beta_functions import (
53
+ BetaFunctionTool,
54
+ BetaRunnableTool,
55
+ BetaAsyncFunctionTool,
56
+ BetaAsyncRunnableTool,
57
+ BetaBuiltinFunctionTool,
58
+ BetaAsyncBuiltinFunctionTool,
59
+ )
51
60
  from ....types.anthropic_beta_param import AnthropicBetaParam
52
61
  from ....types.beta.beta_message_param import BetaMessageParam
53
62
  from ....types.beta.beta_metadata_param import BetaMetadataParam
@@ -225,10 +234,13 @@ class Messages(SyncAPIResource):
225
234
 
226
235
  metadata: An object describing metadata about the request.
227
236
 
228
- output_config: Configuration options for the model's output. Controls aspects like how much
229
- effort the model puts into its response.
237
+ output_config: Configuration options for the model's output, such as the output format.
238
+
239
+ output_format: Deprecated: Use `output_config.format` instead. See
240
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
230
241
 
231
- output_format: A schema to specify Claude's output format in responses.
242
+ A schema to specify Claude's output format in responses. This parameter will be
243
+ removed in a future release.
232
244
 
233
245
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
234
246
  for this request.
@@ -519,10 +531,13 @@ class Messages(SyncAPIResource):
519
531
 
520
532
  metadata: An object describing metadata about the request.
521
533
 
522
- output_config: Configuration options for the model's output. Controls aspects like how much
523
- effort the model puts into its response.
534
+ output_config: Configuration options for the model's output, such as the output format.
535
+
536
+ output_format: Deprecated: Use `output_config.format` instead. See
537
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
524
538
 
525
- output_format: A schema to specify Claude's output format in responses.
539
+ A schema to specify Claude's output format in responses. This parameter will be
540
+ removed in a future release.
526
541
 
527
542
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
528
543
  for this request.
@@ -809,10 +824,13 @@ class Messages(SyncAPIResource):
809
824
 
810
825
  metadata: An object describing metadata about the request.
811
826
 
812
- output_config: Configuration options for the model's output. Controls aspects like how much
813
- effort the model puts into its response.
827
+ output_config: Configuration options for the model's output, such as the output format.
814
828
 
815
- output_format: A schema to specify Claude's output format in responses.
829
+ output_format: Deprecated: Use `output_config.format` instead. See
830
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
831
+
832
+ A schema to specify Claude's output format in responses. This parameter will be
833
+ removed in a future release.
816
834
 
817
835
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
818
836
  for this request.
@@ -996,6 +1014,8 @@ class Messages(SyncAPIResource):
996
1014
  timeout: float | httpx.Timeout | None | NotGiven = not_given,
997
1015
  ) -> BetaMessage | Stream[BetaRawMessageStreamEvent]:
998
1016
  validate_output_format(output_format)
1017
+ _validate_output_config_conflict(output_config, output_format)
1018
+ _warn_output_format_deprecated(output_format)
999
1019
 
1000
1020
  if not stream and not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
1001
1021
  timeout = self._client._calculate_nonstreaming_timeout(
@@ -1009,6 +1029,8 @@ class Messages(SyncAPIResource):
1009
1029
  stacklevel=3,
1010
1030
  )
1011
1031
 
1032
+ merged_output_config = _merge_output_configs(output_config, output_format)
1033
+
1012
1034
  extra_headers = {
1013
1035
  **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
1014
1036
  **(extra_headers or {}),
@@ -1024,8 +1046,8 @@ class Messages(SyncAPIResource):
1024
1046
  "context_management": context_management,
1025
1047
  "mcp_servers": mcp_servers,
1026
1048
  "metadata": metadata,
1027
- "output_config": output_config,
1028
- "output_format": output_format,
1049
+ "output_config": merged_output_config,
1050
+ "output_format": omit,
1029
1051
  "service_tier": service_tier,
1030
1052
  "stop_sequences": stop_sequences,
1031
1053
  "stream": stream,
@@ -1079,6 +1101,9 @@ class Messages(SyncAPIResource):
1079
1101
  extra_body: Body | None = None,
1080
1102
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1081
1103
  ) -> ParsedBetaMessage[ResponseFormatT]:
1104
+ _validate_output_config_conflict(output_config, output_format)
1105
+ _warn_output_format_deprecated(output_format)
1106
+
1082
1107
  if not stream and not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
1083
1108
  timeout = self._client._calculate_nonstreaming_timeout(
1084
1109
  max_tokens, MODEL_NONSTREAMING_TOKENS.get(model, None)
@@ -1093,9 +1118,9 @@ class Messages(SyncAPIResource):
1093
1118
 
1094
1119
  betas = [beta for beta in betas] if is_given(betas) else []
1095
1120
 
1096
- if "structured-outputs-2025-11-13" not in betas:
1121
+ if "structured-outputs-2025-12-15" not in betas and is_given(output_format):
1097
1122
  # Ensure structured outputs beta is included for parse method
1098
- betas.append("structured-outputs-2025-11-13")
1123
+ betas.append("structured-outputs-2025-12-15")
1099
1124
 
1100
1125
  extra_headers = {
1101
1126
  "X-Stainless-Helper": "beta.messages.parse",
@@ -1103,26 +1128,28 @@ class Messages(SyncAPIResource):
1103
1128
  **(extra_headers or {}),
1104
1129
  }
1105
1130
 
1106
- transformed_output_format: Optional[message_create_params.OutputFormat] | NotGiven = NOT_GIVEN
1107
-
1108
1131
  if is_given(output_format) and output_format is not None:
1109
1132
  adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
1110
1133
 
1111
1134
  try:
1112
1135
  schema = adapted_type.json_schema()
1113
- transformed_output_format = message_create_params.OutputFormat(
1136
+ transformed_output_format = BetaJSONOutputFormatParam(
1114
1137
  schema=transform_schema(schema), type="json_schema"
1115
1138
  )
1116
1139
  except pydantic.errors.PydanticSchemaGenerationError as e:
1117
1140
  raise TypeError(
1118
1141
  (
1119
1142
  "Could not generate JSON schema for the given `output_format` type. "
1120
- "Use a type that works with `pydanitc.TypeAdapter`"
1143
+ "Use a type that works with `pydantic.TypeAdapter`"
1121
1144
  )
1122
1145
  ) from e
1123
1146
 
1147
+ merged_output_config = _merge_output_configs(output_config, transformed_output_format)
1148
+ else:
1149
+ merged_output_config = output_config
1150
+
1124
1151
  def parser(response: BetaMessage) -> ParsedBetaMessage[ResponseFormatT]:
1125
- return parse_response(
1152
+ return parse_beta_response(
1126
1153
  response=response,
1127
1154
  output_format=cast(
1128
1155
  ResponseFormatT,
@@ -1141,8 +1168,8 @@ class Messages(SyncAPIResource):
1141
1168
  "context_management": context_management,
1142
1169
  "mcp_servers": mcp_servers,
1143
1170
  "metadata": metadata,
1144
- "output_config": output_config,
1145
- "output_format": transformed_output_format,
1171
+ "output_config": merged_output_config,
1172
+ "output_format": omit,
1146
1173
  "service_tier": service_tier,
1147
1174
  "stop_sequences": stop_sequences,
1148
1175
  "stream": stream,
@@ -1174,7 +1201,7 @@ class Messages(SyncAPIResource):
1174
1201
  max_tokens: int,
1175
1202
  messages: Iterable[BetaMessageParam],
1176
1203
  model: ModelParam,
1177
- tools: Iterable[BetaRunnableTool],
1204
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1178
1205
  compaction_control: CompactionControl | Omit = omit,
1179
1206
  container: Optional[message_create_params.Container] | Omit = omit,
1180
1207
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
@@ -1208,7 +1235,7 @@ class Messages(SyncAPIResource):
1208
1235
  max_tokens: int,
1209
1236
  messages: Iterable[BetaMessageParam],
1210
1237
  model: ModelParam,
1211
- tools: Iterable[BetaRunnableTool],
1238
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1212
1239
  compaction_control: CompactionControl | Omit = omit,
1213
1240
  stream: Literal[True],
1214
1241
  max_iterations: int | Omit = omit,
@@ -1242,7 +1269,7 @@ class Messages(SyncAPIResource):
1242
1269
  max_tokens: int,
1243
1270
  messages: Iterable[BetaMessageParam],
1244
1271
  model: ModelParam,
1245
- tools: Iterable[BetaRunnableTool],
1272
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1246
1273
  compaction_control: CompactionControl | Omit = omit,
1247
1274
  stream: bool,
1248
1275
  max_iterations: int | Omit = omit,
@@ -1275,7 +1302,7 @@ class Messages(SyncAPIResource):
1275
1302
  max_tokens: int,
1276
1303
  messages: Iterable[BetaMessageParam],
1277
1304
  model: ModelParam,
1278
- tools: Iterable[BetaRunnableTool],
1305
+ tools: Iterable[BetaRunnableTool | BetaToolUnionParam],
1279
1306
  compaction_control: CompactionControl | Omit = omit,
1280
1307
  max_iterations: int | Omit = omit,
1281
1308
  container: Optional[message_create_params.Container] | Omit = omit,
@@ -1302,6 +1329,9 @@ class Messages(SyncAPIResource):
1302
1329
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1303
1330
  ) -> BetaStreamingToolRunner[ResponseFormatT] | BetaToolRunner[ResponseFormatT]:
1304
1331
  """Create a Message stream"""
1332
+ _validate_output_config_conflict(output_config, output_format)
1333
+ _warn_output_format_deprecated(output_format)
1334
+
1305
1335
  if model in DEPRECATED_MODELS:
1306
1336
  warnings.warn(
1307
1337
  f"The model '{model}' is deprecated and will reach end-of-life on {DEPRECATED_MODELS[model]}.\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.",
@@ -1315,6 +1345,15 @@ class Messages(SyncAPIResource):
1315
1345
  **(extra_headers or {}),
1316
1346
  }
1317
1347
 
1348
+ runnable_tools: list[BetaRunnableTool] = []
1349
+ raw_tools: list[BetaToolUnionParam] = []
1350
+
1351
+ for tool in tools:
1352
+ if isinstance(tool, (BetaFunctionTool, BetaBuiltinFunctionTool)):
1353
+ runnable_tools.append(tool)
1354
+ else:
1355
+ raw_tools.append(tool)
1356
+
1318
1357
  params = cast(
1319
1358
  message_create_params.ParseMessageCreateParamsBase[ResponseFormatT],
1320
1359
  {
@@ -1333,7 +1372,7 @@ class Messages(SyncAPIResource):
1333
1372
  "temperature": temperature,
1334
1373
  "thinking": thinking,
1335
1374
  "tool_choice": tool_choice,
1336
- "tools": [tool.to_dict() for tool in tools],
1375
+ "tools": [*[tool.to_dict() for tool in runnable_tools], *raw_tools],
1337
1376
  "top_k": top_k,
1338
1377
  "top_p": top_p,
1339
1378
  },
@@ -1341,7 +1380,7 @@ class Messages(SyncAPIResource):
1341
1380
 
1342
1381
  if stream:
1343
1382
  return BetaStreamingToolRunner[ResponseFormatT](
1344
- tools=tools,
1383
+ tools=runnable_tools,
1345
1384
  params=params,
1346
1385
  options={
1347
1386
  "extra_headers": extra_headers,
@@ -1354,7 +1393,7 @@ class Messages(SyncAPIResource):
1354
1393
  compaction_control=compaction_control if is_given(compaction_control) else None,
1355
1394
  )
1356
1395
  return BetaToolRunner[ResponseFormatT](
1357
- tools=tools,
1396
+ tools=runnable_tools,
1358
1397
  params=params,
1359
1398
  options={
1360
1399
  "extra_headers": extra_headers,
@@ -1378,7 +1417,7 @@ class Messages(SyncAPIResource):
1378
1417
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
1379
1418
  metadata: BetaMetadataParam | Omit = omit,
1380
1419
  output_config: BetaOutputConfigParam | Omit = omit,
1381
- output_format: Optional[type[ResponseFormatT]] | Omit = omit,
1420
+ output_format: None | BetaJSONOutputFormatParam | type[ResponseFormatT] | Omit = omit,
1382
1421
  service_tier: Literal["auto", "standard_only"] | Omit = omit,
1383
1422
  stop_sequences: SequenceNotStr[str] | Omit = omit,
1384
1423
  system: Union[str, Iterable[BetaTextBlockParam]] | Omit = omit,
@@ -1396,6 +1435,9 @@ class Messages(SyncAPIResource):
1396
1435
  extra_body: Body | None = None,
1397
1436
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1398
1437
  ) -> BetaMessageStreamManager[ResponseFormatT]:
1438
+ _validate_output_config_conflict(output_config, output_format)
1439
+ _warn_output_format_deprecated(output_format)
1440
+
1399
1441
  if model in DEPRECATED_MODELS:
1400
1442
  warnings.warn(
1401
1443
  f"The model '{model}' is deprecated and will reach end-of-life on {DEPRECATED_MODELS[model]}.\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.",
@@ -1411,24 +1453,28 @@ class Messages(SyncAPIResource):
1411
1453
  **(extra_headers or {}),
1412
1454
  }
1413
1455
 
1414
- transformed_output_format: Optional[message_create_params.OutputFormat] | NotGiven = NOT_GIVEN
1456
+ transformed_output_format: BetaJSONOutputFormatParam | Omit = omit
1415
1457
 
1416
- if is_given(output_format) and output_format is not None:
1458
+ if is_dict(output_format):
1459
+ transformed_output_format = cast(BetaJSONOutputFormatParam, output_format)
1460
+ elif is_given(output_format) and output_format is not None:
1417
1461
  adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
1418
1462
 
1419
1463
  try:
1420
1464
  schema = adapted_type.json_schema()
1421
- transformed_output_format = message_create_params.OutputFormat(
1465
+ transformed_output_format = BetaJSONOutputFormatParam(
1422
1466
  schema=transform_schema(schema), type="json_schema"
1423
1467
  )
1424
1468
  except pydantic.errors.PydanticSchemaGenerationError as e:
1425
1469
  raise TypeError(
1426
1470
  (
1427
1471
  "Could not generate JSON schema for the given `output_format` type. "
1428
- "Use a type that works with `pydanitc.TypeAdapter`"
1472
+ "Use a type that works with `pydantic.TypeAdapter`"
1429
1473
  )
1430
1474
  ) from e
1431
1475
 
1476
+ merged_output_config = _merge_output_configs(output_config, transformed_output_format)
1477
+
1432
1478
  make_request = partial(
1433
1479
  self._post,
1434
1480
  "/v1/messages?beta=true",
@@ -1438,8 +1484,8 @@ class Messages(SyncAPIResource):
1438
1484
  "messages": messages,
1439
1485
  "model": model,
1440
1486
  "metadata": metadata,
1441
- "output_config": output_config,
1442
- "output_format": transformed_output_format,
1487
+ "output_config": merged_output_config,
1488
+ "output_format": omit,
1443
1489
  "container": container,
1444
1490
  "context_management": context_management,
1445
1491
  "mcp_servers": mcp_servers,
@@ -1463,7 +1509,10 @@ class Messages(SyncAPIResource):
1463
1509
  stream=True,
1464
1510
  stream_cls=Stream[BetaRawMessageStreamEvent],
1465
1511
  )
1466
- return BetaMessageStreamManager(make_request, output_format=cast(ResponseFormatT, output_format))
1512
+ return BetaMessageStreamManager(
1513
+ make_request,
1514
+ output_format=NOT_GIVEN if is_dict(output_format) else cast(ResponseFormatT, output_format),
1515
+ )
1467
1516
 
1468
1517
  def count_tokens(
1469
1518
  self,
@@ -1573,10 +1622,13 @@ class Messages(SyncAPIResource):
1573
1622
 
1574
1623
  mcp_servers: MCP servers to be utilized in this request
1575
1624
 
1576
- output_config: Configuration options for the model's output. Controls aspects like how much
1577
- effort the model puts into its response.
1625
+ output_config: Configuration options for the model's output, such as the output format.
1626
+
1627
+ output_format: Deprecated: Use `output_config.format` instead. See
1628
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
1578
1629
 
1579
- output_format: A schema to specify Claude's output format in responses.
1630
+ A schema to specify Claude's output format in responses. This parameter will be
1631
+ removed in a future release.
1580
1632
 
1581
1633
  system: System prompt.
1582
1634
 
@@ -1683,6 +1735,11 @@ class Messages(SyncAPIResource):
1683
1735
 
1684
1736
  timeout: Override the client-level default timeout for this request, in seconds
1685
1737
  """
1738
+ _validate_output_config_conflict(output_config, output_format)
1739
+ _warn_output_format_deprecated(output_format)
1740
+
1741
+ merged_output_config = _merge_output_configs(output_config, output_format)
1742
+
1686
1743
  extra_headers = {
1687
1744
  **strip_not_given(
1688
1745
  {
@@ -1702,8 +1759,8 @@ class Messages(SyncAPIResource):
1702
1759
  "model": model,
1703
1760
  "context_management": context_management,
1704
1761
  "mcp_servers": mcp_servers,
1705
- "output_config": output_config,
1706
- "output_format": output_format,
1762
+ "output_config": merged_output_config,
1763
+ "output_format": omit,
1707
1764
  "system": system,
1708
1765
  "thinking": thinking,
1709
1766
  "tool_choice": tool_choice,
@@ -1873,10 +1930,13 @@ class AsyncMessages(AsyncAPIResource):
1873
1930
 
1874
1931
  metadata: An object describing metadata about the request.
1875
1932
 
1876
- output_config: Configuration options for the model's output. Controls aspects like how much
1877
- effort the model puts into its response.
1933
+ output_config: Configuration options for the model's output, such as the output format.
1934
+
1935
+ output_format: Deprecated: Use `output_config.format` instead. See
1936
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
1878
1937
 
1879
- output_format: A schema to specify Claude's output format in responses.
1938
+ A schema to specify Claude's output format in responses. This parameter will be
1939
+ removed in a future release.
1880
1940
 
1881
1941
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
1882
1942
  for this request.
@@ -2167,10 +2227,13 @@ class AsyncMessages(AsyncAPIResource):
2167
2227
 
2168
2228
  metadata: An object describing metadata about the request.
2169
2229
 
2170
- output_config: Configuration options for the model's output. Controls aspects like how much
2171
- effort the model puts into its response.
2230
+ output_config: Configuration options for the model's output, such as the output format.
2231
+
2232
+ output_format: Deprecated: Use `output_config.format` instead. See
2233
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
2172
2234
 
2173
- output_format: A schema to specify Claude's output format in responses.
2235
+ A schema to specify Claude's output format in responses. This parameter will be
2236
+ removed in a future release.
2174
2237
 
2175
2238
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
2176
2239
  for this request.
@@ -2457,10 +2520,13 @@ class AsyncMessages(AsyncAPIResource):
2457
2520
 
2458
2521
  metadata: An object describing metadata about the request.
2459
2522
 
2460
- output_config: Configuration options for the model's output. Controls aspects like how much
2461
- effort the model puts into its response.
2523
+ output_config: Configuration options for the model's output, such as the output format.
2462
2524
 
2463
- output_format: A schema to specify Claude's output format in responses.
2525
+ output_format: Deprecated: Use `output_config.format` instead. See
2526
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
2527
+
2528
+ A schema to specify Claude's output format in responses. This parameter will be
2529
+ removed in a future release.
2464
2530
 
2465
2531
  service_tier: Determines whether to use priority capacity (if available) or standard capacity
2466
2532
  for this request.
@@ -2644,6 +2710,8 @@ class AsyncMessages(AsyncAPIResource):
2644
2710
  timeout: float | httpx.Timeout | None | NotGiven = not_given,
2645
2711
  ) -> BetaMessage | AsyncStream[BetaRawMessageStreamEvent]:
2646
2712
  validate_output_format(output_format)
2713
+ _validate_output_config_conflict(output_config, output_format)
2714
+ _warn_output_format_deprecated(output_format)
2647
2715
 
2648
2716
  if not stream and not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
2649
2717
  timeout = self._client._calculate_nonstreaming_timeout(
@@ -2657,6 +2725,8 @@ class AsyncMessages(AsyncAPIResource):
2657
2725
  stacklevel=3,
2658
2726
  )
2659
2727
 
2728
+ merged_output_config = _merge_output_configs(output_config, output_format)
2729
+
2660
2730
  extra_headers = {
2661
2731
  **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
2662
2732
  **(extra_headers or {}),
@@ -2672,8 +2742,8 @@ class AsyncMessages(AsyncAPIResource):
2672
2742
  "context_management": context_management,
2673
2743
  "mcp_servers": mcp_servers,
2674
2744
  "metadata": metadata,
2675
- "output_config": output_config,
2676
- "output_format": output_format,
2745
+ "output_config": merged_output_config,
2746
+ "output_format": omit,
2677
2747
  "service_tier": service_tier,
2678
2748
  "stop_sequences": stop_sequences,
2679
2749
  "stream": stream,
@@ -2727,6 +2797,9 @@ class AsyncMessages(AsyncAPIResource):
2727
2797
  extra_body: Body | None = None,
2728
2798
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
2729
2799
  ) -> ParsedBetaMessage[ResponseFormatT]:
2800
+ _validate_output_config_conflict(output_config, output_format)
2801
+ _warn_output_format_deprecated(output_format)
2802
+
2730
2803
  if not stream and not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
2731
2804
  timeout = self._client._calculate_nonstreaming_timeout(
2732
2805
  max_tokens, MODEL_NONSTREAMING_TOKENS.get(model, None)
@@ -2740,9 +2813,9 @@ class AsyncMessages(AsyncAPIResource):
2740
2813
  )
2741
2814
  betas = [beta for beta in betas] if is_given(betas) else []
2742
2815
 
2743
- if "structured-outputs-2025-11-13" not in betas:
2816
+ if "structured-outputs-2025-12-15" not in betas and is_given(output_format):
2744
2817
  # Ensure structured outputs beta is included for parse method
2745
- betas.append("structured-outputs-2025-11-13")
2818
+ betas.append("structured-outputs-2025-12-15")
2746
2819
 
2747
2820
  extra_headers = {
2748
2821
  "X-Stainless-Helper": "beta.messages.parse",
@@ -2750,26 +2823,28 @@ class AsyncMessages(AsyncAPIResource):
2750
2823
  **(extra_headers or {}),
2751
2824
  }
2752
2825
 
2753
- transformed_output_format: Optional[message_create_params.OutputFormat] | NotGiven = NOT_GIVEN
2754
-
2755
2826
  if is_given(output_format) and output_format is not None:
2756
2827
  adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
2757
2828
 
2758
2829
  try:
2759
2830
  schema = adapted_type.json_schema()
2760
- transformed_output_format = message_create_params.OutputFormat(
2831
+ transformed_output_format = BetaJSONOutputFormatParam(
2761
2832
  schema=transform_schema(schema), type="json_schema"
2762
2833
  )
2763
2834
  except pydantic.errors.PydanticSchemaGenerationError as e:
2764
2835
  raise TypeError(
2765
2836
  (
2766
2837
  "Could not generate JSON schema for the given `output_format` type. "
2767
- "Use a type that works with `pydanitc.TypeAdapter`"
2838
+ "Use a type that works with `pydantic.TypeAdapter`"
2768
2839
  )
2769
2840
  ) from e
2770
2841
 
2842
+ merged_output_config = _merge_output_configs(output_config, transformed_output_format)
2843
+ else:
2844
+ merged_output_config = output_config
2845
+
2771
2846
  def parser(response: BetaMessage) -> ParsedBetaMessage[ResponseFormatT]:
2772
- return parse_response(
2847
+ return parse_beta_response(
2773
2848
  response=response,
2774
2849
  output_format=cast(
2775
2850
  ResponseFormatT,
@@ -2787,9 +2862,9 @@ class AsyncMessages(AsyncAPIResource):
2787
2862
  "container": container,
2788
2863
  "context_management": context_management,
2789
2864
  "mcp_servers": mcp_servers,
2790
- "output_config": output_config,
2865
+ "output_config": merged_output_config,
2791
2866
  "metadata": metadata,
2792
- "output_format": transformed_output_format,
2867
+ "output_format": omit,
2793
2868
  "service_tier": service_tier,
2794
2869
  "stop_sequences": stop_sequences,
2795
2870
  "stream": stream,
@@ -2821,7 +2896,7 @@ class AsyncMessages(AsyncAPIResource):
2821
2896
  max_tokens: int,
2822
2897
  messages: Iterable[BetaMessageParam],
2823
2898
  model: ModelParam,
2824
- tools: Iterable[BetaAsyncRunnableTool],
2899
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2825
2900
  compaction_control: CompactionControl | Omit = omit,
2826
2901
  max_iterations: int | Omit = omit,
2827
2902
  container: Optional[message_create_params.Container] | Omit = omit,
@@ -2855,7 +2930,7 @@ class AsyncMessages(AsyncAPIResource):
2855
2930
  max_tokens: int,
2856
2931
  messages: Iterable[BetaMessageParam],
2857
2932
  model: ModelParam,
2858
- tools: Iterable[BetaAsyncRunnableTool],
2933
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2859
2934
  compaction_control: CompactionControl | Omit = omit,
2860
2935
  stream: Literal[True],
2861
2936
  max_iterations: int | Omit = omit,
@@ -2889,7 +2964,7 @@ class AsyncMessages(AsyncAPIResource):
2889
2964
  max_tokens: int,
2890
2965
  messages: Iterable[BetaMessageParam],
2891
2966
  model: ModelParam,
2892
- tools: Iterable[BetaAsyncRunnableTool],
2967
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2893
2968
  compaction_control: CompactionControl | Omit = omit,
2894
2969
  stream: bool,
2895
2970
  max_iterations: int | Omit = omit,
@@ -2922,7 +2997,7 @@ class AsyncMessages(AsyncAPIResource):
2922
2997
  max_tokens: int,
2923
2998
  messages: Iterable[BetaMessageParam],
2924
2999
  model: ModelParam,
2925
- tools: Iterable[BetaAsyncRunnableTool],
3000
+ tools: Iterable[BetaAsyncRunnableTool | BetaToolUnionParam],
2926
3001
  compaction_control: CompactionControl | Omit = omit,
2927
3002
  max_iterations: int | Omit = omit,
2928
3003
  container: Optional[message_create_params.Container] | Omit = omit,
@@ -2949,6 +3024,9 @@ class AsyncMessages(AsyncAPIResource):
2949
3024
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
2950
3025
  ) -> BetaAsyncToolRunner[ResponseFormatT] | BetaAsyncStreamingToolRunner[ResponseFormatT]:
2951
3026
  """Create a Message stream"""
3027
+ _validate_output_config_conflict(output_config, output_format)
3028
+ _warn_output_format_deprecated(output_format)
3029
+
2952
3030
  if model in DEPRECATED_MODELS:
2953
3031
  warnings.warn(
2954
3032
  f"The model '{model}' is deprecated and will reach end-of-life on {DEPRECATED_MODELS[model]}.\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.",
@@ -2962,6 +3040,15 @@ class AsyncMessages(AsyncAPIResource):
2962
3040
  **(extra_headers or {}),
2963
3041
  }
2964
3042
 
3043
+ runnable_tools: list[BetaAsyncRunnableTool] = []
3044
+ raw_tools: list[BetaToolUnionParam] = []
3045
+
3046
+ for tool in tools:
3047
+ if isinstance(tool, (BetaAsyncFunctionTool, BetaAsyncBuiltinFunctionTool)):
3048
+ runnable_tools.append(tool)
3049
+ else:
3050
+ raw_tools.append(tool)
3051
+
2965
3052
  params = cast(
2966
3053
  message_create_params.ParseMessageCreateParamsBase[ResponseFormatT],
2967
3054
  {
@@ -2980,7 +3067,7 @@ class AsyncMessages(AsyncAPIResource):
2980
3067
  "temperature": temperature,
2981
3068
  "thinking": thinking,
2982
3069
  "tool_choice": tool_choice,
2983
- "tools": [tool.to_dict() for tool in tools],
3070
+ "tools": [*[tool.to_dict() for tool in runnable_tools], *raw_tools],
2984
3071
  "top_k": top_k,
2985
3072
  "top_p": top_p,
2986
3073
  },
@@ -2988,7 +3075,7 @@ class AsyncMessages(AsyncAPIResource):
2988
3075
 
2989
3076
  if stream:
2990
3077
  return BetaAsyncStreamingToolRunner[ResponseFormatT](
2991
- tools=tools,
3078
+ tools=runnable_tools,
2992
3079
  params=params,
2993
3080
  options={
2994
3081
  "extra_headers": extra_headers,
@@ -3001,7 +3088,7 @@ class AsyncMessages(AsyncAPIResource):
3001
3088
  compaction_control=compaction_control if is_given(compaction_control) else None,
3002
3089
  )
3003
3090
  return BetaAsyncToolRunner[ResponseFormatT](
3004
- tools=tools,
3091
+ tools=runnable_tools,
3005
3092
  params=params,
3006
3093
  options={
3007
3094
  "extra_headers": extra_headers,
@@ -3022,7 +3109,7 @@ class AsyncMessages(AsyncAPIResource):
3022
3109
  model: ModelParam,
3023
3110
  metadata: BetaMetadataParam | Omit = omit,
3024
3111
  output_config: BetaOutputConfigParam | Omit = omit,
3025
- output_format: Optional[type[ResponseFormatT]] | Omit = omit,
3112
+ output_format: None | type[ResponseFormatT] | BetaJSONOutputFormatParam | Omit = omit,
3026
3113
  container: Optional[message_create_params.Container] | Omit = omit,
3027
3114
  context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
3028
3115
  mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
@@ -3043,6 +3130,9 @@ class AsyncMessages(AsyncAPIResource):
3043
3130
  extra_body: Body | None = None,
3044
3131
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
3045
3132
  ) -> BetaAsyncMessageStreamManager[ResponseFormatT]:
3133
+ _validate_output_config_conflict(output_config, output_format)
3134
+ _warn_output_format_deprecated(output_format)
3135
+
3046
3136
  if model in DEPRECATED_MODELS:
3047
3137
  warnings.warn(
3048
3138
  f"The model '{model}' is deprecated and will reach end-of-life on {DEPRECATED_MODELS[model]}.\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.",
@@ -3057,33 +3147,38 @@ class AsyncMessages(AsyncAPIResource):
3057
3147
  **(extra_headers or {}),
3058
3148
  }
3059
3149
 
3060
- transformed_output_format: Optional[message_create_params.OutputFormat] | NotGiven = NOT_GIVEN
3150
+ transformed_output_format: BetaJSONOutputFormatParam | Omit = omit
3061
3151
 
3062
- if is_given(output_format) and output_format is not None:
3152
+ if is_dict(output_format):
3153
+ transformed_output_format = cast(BetaJSONOutputFormatParam, output_format)
3154
+ elif is_given(output_format) and output_format is not None:
3063
3155
  adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
3064
3156
 
3065
3157
  try:
3066
3158
  schema = adapted_type.json_schema()
3067
- transformed_output_format = message_create_params.OutputFormat(
3159
+ transformed_output_format = BetaJSONOutputFormatParam(
3068
3160
  schema=transform_schema(schema), type="json_schema"
3069
3161
  )
3070
3162
  except pydantic.errors.PydanticSchemaGenerationError as e:
3071
3163
  raise TypeError(
3072
3164
  (
3073
3165
  "Could not generate JSON schema for the given `output_format` type. "
3074
- "Use a type that works with `pydanitc.TypeAdapter`"
3166
+ "Use a type that works with `pydantic.TypeAdapter`"
3075
3167
  )
3076
3168
  ) from e
3169
+
3170
+ merged_output_config = _merge_output_configs(output_config, transformed_output_format)
3171
+
3077
3172
  request = self._post(
3078
- "/v1/messages",
3173
+ "/v1/messages?beta=true",
3079
3174
  body=maybe_transform(
3080
3175
  {
3081
3176
  "max_tokens": max_tokens,
3082
3177
  "messages": messages,
3083
3178
  "model": model,
3084
3179
  "metadata": metadata,
3085
- "output_config": output_config,
3086
- "output_format": transformed_output_format,
3180
+ "output_config": merged_output_config,
3181
+ "output_format": omit,
3087
3182
  "container": container,
3088
3183
  "context_management": context_management,
3089
3184
  "mcp_servers": mcp_servers,
@@ -3107,7 +3202,10 @@ class AsyncMessages(AsyncAPIResource):
3107
3202
  stream=True,
3108
3203
  stream_cls=AsyncStream[BetaRawMessageStreamEvent],
3109
3204
  )
3110
- return BetaAsyncMessageStreamManager(request, output_format=cast(ResponseFormatT, output_format))
3205
+ return BetaAsyncMessageStreamManager(
3206
+ request,
3207
+ output_format=NOT_GIVEN if is_dict(output_format) else cast(ResponseFormatT, output_format),
3208
+ )
3111
3209
 
3112
3210
  async def count_tokens(
3113
3211
  self,
@@ -3217,10 +3315,13 @@ class AsyncMessages(AsyncAPIResource):
3217
3315
 
3218
3316
  mcp_servers: MCP servers to be utilized in this request
3219
3317
 
3220
- output_config: Configuration options for the model's output. Controls aspects like how much
3221
- effort the model puts into its response.
3318
+ output_config: Configuration options for the model's output, such as the output format.
3222
3319
 
3223
- output_format: A schema to specify Claude's output format in responses.
3320
+ output_format: Deprecated: Use `output_config.format` instead. See
3321
+ [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
3322
+
3323
+ A schema to specify Claude's output format in responses. This parameter will be
3324
+ removed in a future release.
3224
3325
 
3225
3326
  system: System prompt.
3226
3327
 
@@ -3327,6 +3428,11 @@ class AsyncMessages(AsyncAPIResource):
3327
3428
 
3328
3429
  timeout: Override the client-level default timeout for this request, in seconds
3329
3430
  """
3431
+ _validate_output_config_conflict(output_config, output_format)
3432
+ _warn_output_format_deprecated(output_format)
3433
+
3434
+ merged_output_config = _merge_output_configs(output_config, output_format)
3435
+
3330
3436
  extra_headers = {
3331
3437
  **strip_not_given(
3332
3438
  {
@@ -3346,8 +3452,8 @@ class AsyncMessages(AsyncAPIResource):
3346
3452
  "model": model,
3347
3453
  "context_management": context_management,
3348
3454
  "mcp_servers": mcp_servers,
3349
- "output_config": output_config,
3350
- "output_format": output_format,
3455
+ "output_config": merged_output_config,
3456
+ "output_format": omit,
3351
3457
  "system": system,
3352
3458
  "thinking": thinking,
3353
3459
  "tool_choice": tool_choice,
@@ -3369,6 +3475,9 @@ class MessagesWithRawResponse:
3369
3475
  self.create = _legacy_response.to_raw_response_wrapper(
3370
3476
  messages.create,
3371
3477
  )
3478
+ self.parse = _legacy_response.to_raw_response_wrapper(
3479
+ messages.parse,
3480
+ )
3372
3481
  self.count_tokens = _legacy_response.to_raw_response_wrapper(
3373
3482
  messages.count_tokens,
3374
3483
  )
@@ -3385,6 +3494,9 @@ class AsyncMessagesWithRawResponse:
3385
3494
  self.create = _legacy_response.async_to_raw_response_wrapper(
3386
3495
  messages.create,
3387
3496
  )
3497
+ self.parse = _legacy_response.async_to_raw_response_wrapper(
3498
+ messages.parse,
3499
+ )
3388
3500
  self.count_tokens = _legacy_response.async_to_raw_response_wrapper(
3389
3501
  messages.count_tokens,
3390
3502
  )
@@ -3431,3 +3543,37 @@ def validate_output_format(output_format: object) -> None:
3431
3543
  raise TypeError(
3432
3544
  "You tried to pass a `BaseModel` class to `beta.messages.create()`; You must use `beta.messages.parse()` instead"
3433
3545
  )
3546
+
3547
+
3548
+ def _validate_output_config_conflict(
3549
+ output_config: BetaOutputConfigParam | Omit,
3550
+ output_format: object,
3551
+ ) -> None:
3552
+ if is_given(output_format) and output_format is not None and is_given(output_config):
3553
+ if "format" in output_config and output_config["format"] is not None:
3554
+ raise AnthropicError(
3555
+ "Both output_format and output_config.format were provided. "
3556
+ "Please use only output_config.format (output_format is deprecated).",
3557
+ )
3558
+
3559
+
3560
+ def _merge_output_configs(
3561
+ output_config: BetaOutputConfigParam | Omit,
3562
+ output_format: Optional[BetaJSONOutputFormatParam] | Omit,
3563
+ ) -> BetaOutputConfigParam | Omit:
3564
+ if is_given(output_format):
3565
+ if is_given(output_config):
3566
+ return {**output_config, "format": output_format}
3567
+ else:
3568
+ return {"format": output_format}
3569
+ return output_config
3570
+
3571
+
3572
+ def _warn_output_format_deprecated(output_format: object) -> None:
3573
+ """Emit deprecation warning if output_format is provided."""
3574
+ if is_given(output_format) and output_format is not None:
3575
+ warnings.warn(
3576
+ "The 'output_format' parameter is deprecated. Please use 'output_config.format' instead.",
3577
+ DeprecationWarning,
3578
+ stacklevel=4,
3579
+ )