Reference Requests and replies
Message
The model's reply: its content blocks, why it stopped, and what it cost.
Reference#
Message#
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
- Always check
stopReasonbefore trustingcontent: aRefusalorMaxTokensstop means the content is absent or cut short.
Helpers#
def text: String
def toolUses: List[ContentBlock.ToolUse]
def toParam: MessageParam
def isRefusal: Boolean
text: all text blocks joined together. Thinking and tool blocks are not included.toolUses: the tool calls the model asked for.toParam: the reply as an assistant message, to continue the conversation.isRefusal: whether the model refused.
StopReason#
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#
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
Usageis a catsMonoid: the usage of a whole agent run isturns.foldMap(_.usage).
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.