Skip to content

Messages Types

The Messages API types are Pydantic models used by any_llm.api.messages() and any_llm.api.amessages().

Full response from the Messages API.

Import: from any_llm.types.messages import MessageResponse

Content block in a Messages API response.

Import: from any_llm.types.messages import MessageContentBlock

Token usage information for Messages API.

Import: from any_llm.types.messages import MessageUsage

FieldTypeDescription
cache_creationCacheCreation | NoneBreakdown of cached tokens by TTL
cache_creation_input_tokensint | NoneThe number of input tokens used to create the cache entry.
cache_read_input_tokensint | NoneThe number of input tokens read from the cache.
inference_geostr | NoneThe geographic region where inference was performed for this request.
input_tokensintThe number of input tokens which were used.
output_tokensintThe number of output tokens which were used.
server_tool_useServerToolUsage | NoneThe number of server tool requests.
service_tierLiteral['standard', 'priority', 'batch'] | NoneIf the request used the priority, standard, or batch tier.

Union of Anthropic SDK stream event types, re-exported from the anthropic package:

  • MessageStartEventtype: 'message_start', message: Message
  • MessageDeltaEventtype: 'message_delta', delta: Delta, usage: MessageDeltaUsage
  • MessageStopEventtype: 'message_stop'
  • ContentBlockStartEventtype: 'content_block_start', index: int, content_block: ContentBlock
  • ContentBlockDeltaEventtype: 'content_block_delta', index: int, delta: RawContentBlockDelta
  • ContentBlockStopEventtype: 'content_block_stop', index: int

Import: from any_llm.types.messages import MessageStreamEvent

Normalized parameters for the Anthropic Messages API, used internally to pass structured parameters from the public API to provider implementations.

Import: from any_llm.types.messages import MessagesParams

FieldTypeDescription
modelstrModel identifier
messageslist[dict[str, Any]]List of messages for the conversation
max_tokensintMaximum number of tokens to generate (required by Anthropic API)
systemstr | list[dict[str, Any]] | NoneSystem prompt (string or list of content blocks with optional cache_control)
temperaturefloat | NoneControls randomness in the response (0.0 to 1.0)
top_pfloat | NoneControls diversity via nucleus sampling
top_kint | NoneOnly sample from the top K options for each subsequent token
streambool | NoneWhether to stream the response
stop_sequenceslist[str] | NoneCustom text sequences that will cause the model to stop generating
toolslist[dict[str, Any]] | NoneList of tools in Anthropic format ({name, description, input_schema})
tool_choicedict[str, Any] | NoneControls which tool the model uses
metadatadict[str, Any] | NoneRequest metadata
thinkingdict[str, Any] | NoneThinking/reasoning configuration
cache_controldict[str, Any] | NoneCache control configuration for prompt caching