Skip to content

Conversation

@jimjimovich
Copy link
Contributor

This change implements support for Anthropic's output-128k-2025-02-19 beta header, specifically for the claude-3-7-sonnet-20250219 model. Including this header allows users to leverage the increased 128k maximum output token limit available for this model.

This implementation attempts to follow the suggested pattern for provider-specific capabilities, similar to the existing temperature normalization logic:

  • A new method additional_headers_for_model was added to Anthropic::Capabilities to encapsulate the provider-specific logic.
  • The shared Provider#post method was updated to conditionally call this capability method via respond_to? and merge the resulting headers before making the API request.
  • The necessary model_id context is now passed down through the relevant methods (embed, paint, sync_response, stream_response) to post.

This approach avoids overriding shared methods within the provider module and keeps the specific logic contained within the capabilities definition.

Closes #85

This change implements support for Anthropic's `output-128k-2025-02-19` beta header, specifically for the `claude-3-7-sonnet-20250219` model. Including this header allows users to leverage the increased 128k maximum output token limit available for this model.

This implementation attempts to follow the suggested pattern for provider-specific capabilities, similar to the existing temperature normalization logic:
- A new method `additional_headers_for_model` was added to `Anthropic::Capabilities` to encapsulate the provider-specific logic.
- The shared `Provider#post` method was updated to conditionally call this capability method via `respond_to?` and merge the resulting headers before making the API request.
- The necessary `model_id` context is now passed down through the relevant methods (`embed`, `paint`, `sync_response`, `stream_response`) to `post`.

This approach avoids overriding shared methods within the provider module and keeps the specific logic contained within the capabilities definition.

Closes crmne#85
Comment on lines +87 to +96
def post(url, payload, model_id: nil)
request_headers = headers

if model_id && capabilities.respond_to?(:additional_headers_for_model)
additional_headers = capabilities.additional_headers_for_model(model_id)
request_headers = request_headers.merge(additional_headers) unless additional_headers.empty?
end

connection.post url, payload do |req|
req.headers.merge! headers
req.headers.merge! request_headers
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the post method is a bit heavy handed. especially when the post needs to know about the model_id which is a clear violation of SRP

crmne added a commit that referenced this pull request Aug 10, 2025
Enables use of provider-specific features like beta headers while
maintaining proper header precedence for security.

Closes #85, #105
@crmne
Copy link
Owner

crmne commented Aug 10, 2025

Added in 177debc

@crmne crmne closed this Aug 10, 2025
parruda pushed a commit to parruda/ruby_llm that referenced this pull request Nov 18, 2025
Enables use of provider-specific features like beta headers while
maintaining proper header precedence for security.

Closes crmne#85, crmne#105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possibility of adding beta header in Claude

2 participants