LLM.Adapter.Anthropic (LLM v0.1.2)

Copy Markdown View Source

Anthropic Messages API adapter.

Handles the wire format for the /v1/messages endpoint.

Capabilities

  • Streaming via SSE with content block events
  • Tool/use calling with input_json_delta accumulation
  • Extended thinking with thinking content blocks and signatures
  • Model listing (returns hardcoded model list)

Request format

Messages use Anthropic's content block format:

  • Text: %{"type" => "text", "text" => "..."}
  • Tool use: %{"type" => "tool_use", "id" => ..., "name" => ..., "input" => ...}
  • Thinking: %{"type" => "thinking", "thinking" => "...", "signature" => "..."}

System prompts are sent as a top-level "system" field. Developer messages are merged into the system prompt.

SSE events

  • event: content_block_start — new content block (tool use or thinking)
  • event: content_block_delta — incremental text, thinking, or JSON
  • event: content_block_stop — block complete (tool calls emitted here)
  • event: message_delta — stop reason and usage
  • event: message_stop — end of stream