Skip to content

feat(Anthropic): Add beta header for Claude 3.7 Sonnet 128k output #105

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

# for free to join this conversation on GitHub. Already have an account? # 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