anthropic-sdk-ruby  by anthropics

Ruby SDK for Anthropic AI models

Created 10 months ago
272 stars

Top 94.9% on SourcePulse

GitHubView on GitHub
Project Summary

This Ruby SDK provides a streamlined interface for integrating with the Anthropic REST API within Ruby 3.2.0+ applications. It simplifies access to powerful AI models like Claude, enabling developers to build AI-powered features efficiently.

How It Works

The library leverages Ruby's standard net/http for HTTP communication, enhanced with connection pooling via the connection_pool gem for performance. It offers robust type definitions (Yard, RBS, RBI) for enhanced developer experience and static analysis, particularly with Sorbet.

Quick Start & Requirements

Install via Bundler by adding gem "anthropic", "~> 1.16.0" to your Gemfile. Requires Ruby 3.2.0 or higher. API keys are typically sourced from the ANTHROPIC_API_KEY environment variable. Official documentation is available on RubyDoc and docs.anthropic.com.

Highlighted Details

  • Streaming: Supports Server-Sent Events (SSE) for real-time responses, with convenient helper methods for processing streamed data.
  • Tool Calling: Includes mechanisms for defining structured input schemas and automatically executing tools called by Claude models.
  • Pagination: Automatically handles paginated API responses with iterators, simplifying data retrieval.
  • File Uploads: Flexible file upload capabilities supporting raw content, Pathname, StringIO, and custom Anthropic::FilePart objects.
  • Error Handling & Retries: Comprehensive error handling with specific APIError subclasses. Automatic retries (default 2) with exponential backoff are configured for transient network issues and server errors.
  • Timeouts: Configurable request timeouts (default 600 seconds) to prevent indefinite waits.
  • Cloud Integrations: Native support for AWS Bedrock (Anthropic::BedrockClient) and Google Vertex AI (Anthropic::VertexClient) via additional gems.
  • Advanced Features: Supports sending undocumented parameters and accessing undocumented endpoints via client.request. Anthropic::Client instances are thread-safe with connection pooling.

Maintenance & Community

Feedback and bug reports are encouraged via GitHub issues. A pinned issue serves as a forum for smaller discussions. The project acknowledges early contributors like @alexrudall.

Licensing & Compatibility

The provided README does not specify a software license. This omission requires clarification regarding usage rights, particularly for commercial applications or integration into closed-source projects.

Limitations & Caveats

The library is currently at major version 0, indicating potential for breaking API changes. Anthropic::Client instances are not fork-safe during active HTTP requests. Use of undocumented parameters or endpoints carries a security warning.

Health Check
Last Commit

20 hours ago

Responsiveness

Inactive

Pull Requests (30d)
6
Issues (30d)
2
Star History
10 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.