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 Beta MessageCreateParams

From Leeroopedia
Knowledge Sources
Domains API_Types, SDK_Infrastructure
Last Updated 2026-02-15 12:00 GMT

Overview

TypedDict definitions for beta message creation request parameters, including the base parameter class and its streaming/non-streaming variants.

Description

This module defines the MessageCreateParams TypedDict hierarchy for the beta Messages API. The core class MessageCreateParamsBase declares all fields available when creating a beta message, including required fields (max_tokens, messages, model) and numerous optional fields for controlling model behavior, tool use, thinking, citations, containers, context management, MCP servers, and more.

Two variant classes extend the base: MessageCreateParamsNonStreaming sets stream to Literal[False] (optional), while MessageCreateParamsStreaming requires stream: Literal[True]. The union MessageCreateParams = Union[MessageCreateParamsNonStreaming, MessageCreateParamsStreaming] provides the full type for the beta messages.create() method. A generic variant ParseMessageCreateParamsBase adds an output_format field typed as type[ResponseFormatT] for structured output parsing.

This is the most comprehensive parameter definition in the SDK, as the beta Messages API supports the full range of experimental features including extended thinking, tool use (client and server tools), web search, web fetch, code execution, MCP toolsets, containers, context management, and structured output formats. The file is auto-generated from the OpenAPI specification by the Stainless code generation tool.

Usage

Use these types when constructing request parameters for the beta messages.create() method, or when type-annotating functions that accept or produce beta message creation parameters. The types ensure compile-time type safety and provide IDE autocompletion for all available parameters.

Code Reference

Source Location

  • Repository: Anthropic SDK Python
  • File: src/anthropic/types/beta/message_create_params.py (354 lines)

Classes

Class Parent Description
MessageCreateParamsBase TypedDict Base parameter definition with all fields (total=False except Required fields)
ParseMessageCreateParamsBase MessageCreateParamsBase, Generic[ResponseFormatT] Generic variant with typed output_format for structured output parsing
MessageCreateParamsNonStreaming MessageCreateParamsBase Non-streaming variant (stream: Literal[False])
MessageCreateParamsStreaming MessageCreateParamsBase Streaming variant (stream: Required[Literal[True]])
OutputFormat TypedDict JSON schema output format definition

Type Aliases

Container: TypeAlias = Union[BetaContainerParams, str]
MessageCreateParams = Union[MessageCreateParamsNonStreaming, MessageCreateParamsStreaming]

Signature

class MessageCreateParamsBase(TypedDict, total=False):
    max_tokens: Required[int]
    messages: Required[Iterable[BetaMessageParam]]
    model: Required[ModelParam]
    container: Optional[Container]
    context_management: Optional[BetaContextManagementConfigParam]
    inference_geo: Optional[str]
    mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam]
    metadata: BetaMetadataParam
    output_config: BetaOutputConfigParam
    output_format: Optional[BetaJSONOutputFormatParam]  # Deprecated
    service_tier: Literal["auto", "standard_only"]
    speed: Optional[Literal["standard", "fast"]]
    stop_sequences: SequenceNotStr[str]
    system: Union[str, Iterable[BetaTextBlockParam]]
    temperature: float
    thinking: BetaThinkingConfigParam
    tool_choice: BetaToolChoiceParam
    tools: Iterable[BetaToolUnionParam]
    top_k: int
    top_p: float
    betas: Annotated[List[AnthropicBetaParam], PropertyInfo(alias="anthropic-beta")]

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

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

Import

from anthropic.types.beta import MessageCreateParams
from anthropic.types.beta.message_create_params import (
    MessageCreateParamsBase,
    MessageCreateParamsNonStreaming,
    MessageCreateParamsStreaming,
)

I/O Contract

Required Fields

Field Type Description
max_tokens int Maximum tokens to generate before stopping. Limits vary by model.
messages Iterable[BetaMessageParam] Input conversation messages. Alternating user/assistant turns. Limit of 100,000 messages.
model ModelParam Model identifier (e.g., "claude-sonnet-4-20250514")

Optional Fields -- Model Behavior

Field Type Description
temperature float Randomness (0.0 to 1.0, default 1.0). Lower for analytical, higher for creative.
top_k int Top-K sampling. Advanced use only.
top_p float Nucleus sampling. Do not combine with temperature.
stop_sequences SequenceNotStr[str] Custom text sequences that trigger generation stop.
system Union[str, Iterable[BetaTextBlockParam]] System prompt providing context and instructions.
speed None Inference speed mode; "fast" enables high throughput.
service_tier Literal["auto", "standard_only"] Priority vs standard capacity selection.

Optional Fields -- Tools and Features

Field Type Description
tools Iterable[BetaToolUnionParam] Tool definitions (client tools, server tools, computer use, text editor, bash, web search, etc.)
tool_choice BetaToolChoiceParam How the model should use tools (any, auto, none, specific tool)
thinking BetaThinkingConfigParam Extended thinking configuration. Minimum 1,024 token budget.
mcp_servers Iterable[BetaRequestMCPServerURLDefinitionParam] MCP server definitions for remote tool access
container None Container identifier for code execution persistence
context_management None Context management configuration for multi-turn optimization

Optional Fields -- Output and Metadata

Field Type Description
metadata BetaMetadataParam Request metadata object
output_config BetaOutputConfigParam Output configuration (format, etc.)
output_format None Deprecated: Use output_config.format instead. JSON schema output format.
inference_geo None Geographic region for inference processing
betas List[AnthropicBetaParam] Beta version flags (sent as anthropic-beta header)

Streaming Variants

Variant stream Field Usage
MessageCreateParamsNonStreaming Literal[False] (optional) Standard request returning a complete BetaMessage
MessageCreateParamsStreaming Required[Literal[True]] SSE streaming request returning incremental events

Usage Examples

from anthropic.types.beta.message_create_params import (
    MessageCreateParamsBase,
    MessageCreateParamsNonStreaming,
    MessageCreateParamsStreaming,
)

# Non-streaming params
params: MessageCreateParamsNonStreaming = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "What is the capital of France?"}
    ],
}

# Streaming params
stream_params: MessageCreateParamsStreaming = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "Tell me a story."}
    ],
    "stream": True,
}

# With extended thinking
thinking_params: MessageCreateParamsNonStreaming = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 16000,
    "messages": [
        {"role": "user", "content": "Solve this complex math problem..."}
    ],
    "thinking": {
        "type": "enabled",
        "budget_tokens": 10000,
    },
}

# With tools
tool_params: MessageCreateParamsNonStreaming = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "What is the weather in Tokyo?"}
    ],
    "tools": [
        {
            "name": "get_weather",
            "description": "Get weather for a city",
            "input_schema": {
                "type": "object",
                "properties": {"city": {"type": "string"}},
                "required": ["city"],
            },
        }
    ],
    "tool_choice": {"type": "auto"},
}

# With system prompt and temperature
full_params: MessageCreateParamsNonStreaming = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 2048,
    "system": "You are a helpful assistant that responds in haiku form.",
    "messages": [
        {"role": "user", "content": "Tell me about the ocean."}
    ],
    "temperature": 0.7,
}

Related Pages

Implements Principle

Part Of

Uses Types

See Also

Page Connections

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