Skip to content

Ruby 4 compatibility issues #147

@arielvalentin

Description

@arielvalentin

CGI has been removed from the standard library and must be required as a gem dependency1. This requires users to add the CGI dependency explicitly when using the Anthropic SDK in a standalone Ruby library otherwise the gem fails with a runtime error2:

NoMethodError: undefined method 'parse' for class CGI
      /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/anthropic-1.16.2/lib/anthropic/internal/util.rb:275:in 'Anthropic::Internal::Util.decode_query'
      /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/anthropic-1.16.2/lib/anthropic/internal/util.rb:296:in 'Anthropic::Internal::Util.parse_uri'
      /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/anthropic-1.16.2/lib/anthropic/internal/transport/base_client.rb:209:in 'Anthropic::Internal::Transport::BaseClient#initialize'
      /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/anthropic-1.16.2/lib/anthropic/client.rb:126:in 'Anthropic::Client#initialize'

Ideally the anthropic SDK should declare the CGI gem as a dependency to avoid requiring users to explicitly add transitive dependencies in their Gemfiles or gemspecs.

Footnotes

  1. https://www.ruby-lang.org/en/news/2025/12/25/ruby-4-0-0-released/#stdlib-compatibility-issues

  2. https://github.com/open-telemetry/opentelemetry-ruby-contrib/actions/runs/20697089280/job/59413961169?pr=1903#step:3:181

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions