Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Anthropics Anthropic sdk python MessageCreateParams

From Leeroopedia
Knowledge Sources
Domains API_Client, LLM
Last Updated 2026-02-15 00:00 GMT

Overview

This page documents the MessageCreateParamsNonStreaming and MessageCreateParamsStreaming TypedDict classes that define the shape of request parameters for the Messages API. These types are used both for runtime request construction and for static type checking.

API Signature

class MessageCreateParamsBase(TypedDict, total=False):
    max_tokens: Required[int]
    messages: Required[Iterable[MessageParam]]
    model: Required[ModelParam]
    inference_geo: Optional[str]
    metadata: MetadataParam
    output_config: OutputConfigParam
    service_tier: Literal["auto", "standard_only"]
    stop_sequences: SequenceNotStr[str]
    system: Union[str, Iterable[TextBlockParam]]
    temperature: float
    thinking: ThinkingConfigParam
    tool_choice: ToolChoiceParam
    tools: Iterable[ToolUnionParam]
    top_k: int
    top_p: float

class MessageCreateParamsNonStreaming(MessageCreateParamsBase, total=False):
    stream: Literal[False]

class MessageCreateParamsStreaming(MessageCreateParamsBase):
    stream: Required[Literal[True]]

MessageCreateParams = Union[MessageCreateParamsNonStreaming, MessageCreateParamsStreaming]

Source Location

  • File: src/anthropic/types/message_create_params.py
  • Lines: 1-323

Import

from anthropic.types import MessageCreateParamsNonStreaming, MessageCreateParamsStreaming
from anthropic.types.message_create_params import MessageCreateParams

Parameters

Required Fields

Parameter Type Description
max_tokens Required[int] Maximum number of tokens to generate. Models may stop before this limit. Different models have different maximums.
messages Required[Iterable[MessageParam]] Input messages representing the conversation history. Must alternate between "user" and "assistant" roles. Limit of 100,000 messages per request.
model Required[ModelParam] Model identifier (e.g., "claude-sonnet-4-20250514"). Union of known model literals and generic str.

Optional Fields

Parameter Type Description
inference_geo Optional[str] Geographic region for inference processing.
metadata MetadataParam Metadata about the request (e.g., user ID for abuse detection).
output_config OutputConfigParam Configuration for model output format.
service_tier Literal["auto", "standard_only"] Whether to use priority or standard capacity.
stop_sequences SequenceNotStr[str] Custom stop sequences that halt generation.
stream Literal[False] or Required[Literal[True]] Enables server-sent event streaming. Determines the variant class used.
system Union[str, Iterable[TextBlockParam]] System prompt providing context and instructions. Supports plain string or structured text blocks.
temperature float Randomness (0.0-1.0, default 1.0). Lower values for analytical tasks, higher for creative tasks.
thinking ThinkingConfigParam Extended thinking configuration. When enabled, responses include thinking blocks.
tool_choice ToolChoiceParam Controls tool usage: auto, any, specific tool, or none.
tools Iterable[ToolUnionParam] Tool definitions the model may invoke.
top_k int Sample from top K token options. Advanced use only.
top_p float Nucleus sampling threshold. Advanced use only.

Type Hierarchy

MessageCreateParamsBase (TypedDict, total=False)
    |
    +-- MessageCreateParamsNonStreaming (stream: Literal[False], optional)
    |
    +-- MessageCreateParamsStreaming (stream: Required[Literal[True]])

MessageCreateParams = Union[NonStreaming, Streaming]

Usage Examples

from anthropic.types import MessageCreateParamsNonStreaming

# Minimal required parameters
params: MessageCreateParamsNonStreaming = {
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello, Claude!"}],
    "model": "claude-sonnet-4-20250514",
}

# Full configuration with optional parameters
params_full: MessageCreateParamsNonStreaming = {
    "max_tokens": 4096,
    "messages": [{"role": "user", "content": "Explain quantum computing."}],
    "model": "claude-sonnet-4-20250514",
    "system": "You are a physics professor.",
    "temperature": 0.7,
    "stop_sequences": ["END"],
    "metadata": {"user_id": "user-123"},
}

# These params are typically passed directly to client.messages.create()
# rather than constructed explicitly as TypedDicts
message = client.messages.create(
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}],
    model="claude-sonnet-4-20250514",
)

Dependencies

  • typing_extensions -- Required, Literal, TypedDict, TypeAlias
  • anthropic.types.message_param -- MessageParam
  • anthropic.types.model_param -- ModelParam
  • anthropic.types.metadata_param -- MetadataParam
  • anthropic.types.text_block_param -- TextBlockParam
  • anthropic.types.tool_union_param -- ToolUnionParam
  • anthropic.types.tool_choice_param -- ToolChoiceParam
  • anthropic.types.thinking_config_param -- ThinkingConfigParam

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment