parse() — anthropic-sdk-python Function Reference
Architecture documentation for the parse() function in messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 875f19aa_d89c_b439_dca0_bf289f16dce2["parse()"] db0dd20b_744d_feba_f585_1c4e91005d64["AsyncMessages"] 875f19aa_d89c_b439_dca0_bf289f16dce2 -->|defined in| db0dd20b_744d_feba_f585_1c4e91005d64 1f77730a_8062_4443_ad97_1696c0294a47["parse()"] 1f77730a_8062_4443_ad97_1696c0294a47 -->|calls| 875f19aa_d89c_b439_dca0_bf289f16dce2 1f77730a_8062_4443_ad97_1696c0294a47["parse()"] 875f19aa_d89c_b439_dca0_bf289f16dce2 -->|calls| 1f77730a_8062_4443_ad97_1696c0294a47 eedd35ac_a896_dc63_a3fe_c46cf577bffb["_validate_output_config_conflict()"] 875f19aa_d89c_b439_dca0_bf289f16dce2 -->|calls| eedd35ac_a896_dc63_a3fe_c46cf577bffb b3ae1af8_b549_4aef_c8c4_9309fd981a1a["_warn_output_format_deprecated()"] 875f19aa_d89c_b439_dca0_bf289f16dce2 -->|calls| b3ae1af8_b549_4aef_c8c4_9309fd981a1a 618c478a_823f_e214_e25b_6e82a7278cf7["_merge_output_configs()"] 875f19aa_d89c_b439_dca0_bf289f16dce2 -->|calls| 618c478a_823f_e214_e25b_6e82a7278cf7 style 875f19aa_d89c_b439_dca0_bf289f16dce2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/resources/beta/messages/messages.py lines 2891–3022
async def parse(
self,
*,
max_tokens: int,
messages: Iterable[BetaMessageParam],
model: ModelParam,
container: Optional[message_create_params.Container] | Omit = omit,
context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
inference_geo: Optional[str] | Omit = omit,
mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
metadata: BetaMetadataParam | Omit = omit,
output_config: BetaOutputConfigParam | Omit = omit,
output_format: Optional[type[ResponseFormatT]] | Omit = omit,
service_tier: Literal["auto", "standard_only"] | Omit = omit,
speed: Optional[Literal["standard", "fast"]] | Omit = omit,
stop_sequences: SequenceNotStr[str] | Omit = omit,
stream: Literal[False] | Literal[True] | Omit = omit,
system: Union[str, Iterable[BetaTextBlockParam]] | Omit = omit,
temperature: float | Omit = omit,
thinking: BetaThinkingConfigParam | Omit = omit,
tool_choice: BetaToolChoiceParam | Omit = omit,
tools: Iterable[BetaToolUnionParam] | Omit = omit,
top_k: int | Omit = omit,
top_p: float | Omit = omit,
betas: List[AnthropicBetaParam] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> ParsedBetaMessage[ResponseFormatT]:
_validate_output_config_conflict(output_config, output_format)
_warn_output_format_deprecated(output_format)
if not stream and not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = self._client._calculate_nonstreaming_timeout(
max_tokens, MODEL_NONSTREAMING_TOKENS.get(model, None)
)
if model in DEPRECATED_MODELS:
warnings.warn(
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.",
DeprecationWarning,
stacklevel=3,
)
if model in MODELS_TO_WARN_WITH_THINKING_ENABLED and thinking and thinking["type"] == "enabled":
warnings.warn(
f"Using Claude with {model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking",
UserWarning,
stacklevel=3,
)
betas = [beta for beta in betas] if is_given(betas) else []
if "structured-outputs-2025-12-15" not in betas:
# Ensure structured outputs beta is included for parse method
betas.append("structured-outputs-2025-12-15")
extra_headers = {
"X-Stainless-Helper": "beta.messages.parse",
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
**(extra_headers or {}),
}
if is_given(output_format) and output_format is not None:
adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
try:
schema = adapted_type.json_schema()
transformed_output_format = BetaJSONOutputFormatParam(
schema=transform_schema(schema), type="json_schema"
)
except pydantic.errors.PydanticSchemaGenerationError as e:
raise TypeError(
(
"Could not generate JSON schema for the given `output_format` type. "
"Use a type that works with `pydantic.TypeAdapter`"
)
) from e
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does parse() do?
parse() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/resources/beta/messages/messages.py.
Where is parse() defined?
parse() is defined in src/anthropic/resources/beta/messages/messages.py at line 2891.
What does parse() call?
parse() calls 4 function(s): _merge_output_configs, _validate_output_config_conflict, _warn_output_format_deprecated, parse.
What calls parse()?
parse() is called by 1 function(s): parse.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free