anthropic4s
GitHub

Reference Requests and replies

Message

The model's reply: its content blocks, why it stopped, and what it cost.

Reference#

Message#

model · Message.scala
final case class Message private (
    id: String,
    model: Model,
    content: List[ContentBlock],
    stopReason: Option[StopReason],
    stopSequence: Option[String],
    stopDetails: Option[StopDetails],
    usage: Usage,
    extras: JsonObject
)

Caveats

Helpers#

model · Message.scala
def text: String
def toolUses: List[ContentBlock.ToolUse]
def toParam: MessageParam
def isRefusal: Boolean

StopReason#

model · enums.scala
val EndTurn: StopReason      = of("end_turn")
val MaxTokens: StopReason    = of("max_tokens")
val StopSequence: StopReason = of("stop_sequence")
val ToolUse: StopReason      = of("tool_use")
val PauseTurn: StopReason    = of("pause_turn")
val Refusal: StopReason      = of("refusal")

Usage#

model · Usage.scala
final case class Usage private (
    inputTokens: Long,
    outputTokens: Long,
    cacheCreationInputTokens: Long,
    cacheReadInputTokens: Long,
    serviceTier: Option[String],
    extras: JsonObject
)
def totalInputTokens: Long

totalInputTokens is everything the model read: fresh input plus cache writes and cache reads.

Caveats

Every signature and example on this page is copied, character for character, from the public source of anthropic4s and its Scaladoc. The complete API, every type included, is in the Scaladoc of each module.