AnthropicMessageBuilderExtension extension

Extension to add Anthropic-specific functionality to MessageBuilder

Content Handling: When using .anthropicConfig().cache() followed by .text(), content is handled as follows:

  • The .cache() method prepares caching for the next .text() call
  • The following .text() call applies the text content to the cached block
  • Cached content appears in message.extensions'anthropic' for provider-specific processing
  • During API conversion, cached text blocks are sent with appropriate cache_control

Example:

final message = MessageBuilder.system()
    .text('System instructions')
    .anthropicConfig((anthropic) => anthropic.cache(ttl: AnthropicCacheTtl.oneHour))
    .text('More content')
    .build();
// All text content gets cache_control applied in _buildRequestBody
on

Methods

anthropicConfig(void configure(AnthropicMessageBuilder)) MessageBuilder

Available on MessageBuilder, provided by the AnthropicMessageBuilderExtension extension

Configure Anthropic-specific features