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 e39b95d3_6106_fca7_db85_ce3b819a4002["parse()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e["Messages"] e39b95d3_6106_fca7_db85_ce3b819a4002 -->|defined in| 31b9de52_3b0b_f20e_01d3_803490d7de7e 224b3cfd_d77c_12ea_9523_cee2cda5dc60["parse()"] 224b3cfd_d77c_12ea_9523_cee2cda5dc60 -->|calls| e39b95d3_6106_fca7_db85_ce3b819a4002 224b3cfd_d77c_12ea_9523_cee2cda5dc60["parse()"] e39b95d3_6106_fca7_db85_ce3b819a4002 -->|calls| 224b3cfd_d77c_12ea_9523_cee2cda5dc60 style e39b95d3_6106_fca7_db85_ce3b819a4002 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/resources/messages/messages.py lines 1118–1234
def parse(
self,
*,
max_tokens: int,
messages: Iterable[MessageParam],
model: ModelParam,
metadata: MetadataParam | Omit = omit,
output_config: OutputConfigParam | Omit = omit,
output_format: Optional[type[ResponseFormatT]] | Omit = omit,
service_tier: Literal["auto", "standard_only"] | Omit = omit,
stop_sequences: SequenceNotStr[str] | Omit = omit,
stream: Literal[False] | Literal[True] | Omit = omit,
system: Union[str, Iterable[TextBlockParam]] | Omit = omit,
temperature: float | Omit = omit,
thinking: ThinkingConfigParam | Omit = omit,
tool_choice: ToolChoiceParam | Omit = omit,
tools: Iterable[ToolUnionParam] | Omit = omit,
top_k: int | Omit = omit,
top_p: float | 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,
) -> ParsedMessage[ResponseFormatT]:
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,
)
extra_headers = {
"X-Stainless-Helper": "messages.parse",
**(extra_headers or {}),
}
transformed_output_format: Optional[JSONOutputFormatParam] | NotGiven = NOT_GIVEN
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 = JSONOutputFormatParam(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
def parser(response: Message) -> ParsedMessage[ResponseFormatT]:
return parse_response(
response=response,
output_format=cast(
ResponseFormatT,
output_format if is_given(output_format) and output_format is not None else NOT_GIVEN,
),
)
# Merge output_format into output_config
merged_output_config: OutputConfigParam | Omit = omit
if is_given(transformed_output_format):
if is_given(output_config):
merged_output_config = {**output_config, "format": transformed_output_format}
else:
Domain
Subdomains
Defined In
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/messages/messages.py.
Where is parse() defined?
parse() is defined in src/anthropic/resources/messages/messages.py at line 1118.
What does parse() call?
parse() calls 1 function(s): 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