claude/types/message

Types

A complete message returned by the API.

pub type Message {
  Message(
    id: String,
    role: Role,
    content: List(content.ContentBlock),
    model: String,
    stop_reason: option.Option(StopReason),
    stop_sequence: option.Option(String),
    usage: Usage,
  )
}

Constructors

The content of a message parameter — either a plain string or structured blocks.

pub type MessageContent {
  StringContent(String)
  BlockContent(List(content.ContentBlockParam))
}

Constructors

A message parameter sent to the API.

pub type MessageParam {
  MessageParam(role: Role, content: MessageContent)
}

Constructors

The role of a message participant.

pub type Role {
  User
  Assistant
}

Constructors

  • User
  • Assistant

Why the model stopped generating.

pub type StopReason {
  EndTurn
  ToolUseStop
  MaxTokens
  StopSequence
  PauseTurn
  Refusal
}

Constructors

  • EndTurn
  • ToolUseStop
  • MaxTokens
  • StopSequence
  • PauseTurn
  • Refusal

Token usage information.

pub type Usage {
  Usage(
    input_tokens: Int,
    output_tokens: Int,
    cache_creation_input_tokens: option.Option(Int),
    cache_read_input_tokens: option.Option(Int),
  )
}

Constructors

  • Usage(
      input_tokens: Int,
      output_tokens: Int,
      cache_creation_input_tokens: option.Option(Int),
      cache_read_input_tokens: option.Option(Int),
    )

Values

pub fn content_to_params(
  content: List(content.ContentBlock),
) -> List(content.ContentBlockParam)

Convert API response content blocks to content block params. Maps Text -> TextParam, ToolUse -> ToolUseParam, Thinking -> ThinkingParam, RedactedThinking -> RedactedThinkingParam, ServerToolUse -> ServerToolUseParam. WebSearchResult blocks are filtered out as they have no corresponding param type.

pub fn new_assistant_blocks(
  blocks: List(content.ContentBlockParam),
) -> MessageParam

Create an assistant message with structured content blocks.

pub fn new_user(text: String) -> MessageParam

Create a user message with plain text content.

pub fn new_user_blocks(
  blocks: List(content.ContentBlockParam),
) -> MessageParam

Create a user message with structured content blocks.

Search Document