openai-ruby  by openai

Official Ruby SDK for the OpenAI API

created 5 months ago
303 stars

Top 87.9% on SourcePulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This Ruby SDK provides a convenient interface to the OpenAI REST API, targeting Ruby developers building applications that leverage AI models for tasks like text generation, image editing, and webhook processing. It simplifies API interactions, offering features like streaming responses, automatic pagination, and robust error handling, enabling efficient integration of OpenAI's capabilities into Ruby projects.

How It Works

The library utilizes Ruby's standard net/http for HTTP transport, enhanced with connection pooling via the connection_pool gem for efficient resource management. It supports Server-Sent Events (SSE) for streaming responses and provides auto-paginating iterators for list endpoints, abstracting away manual page management. For structured outputs and function calling, it includes helper classes like OpenAI::BaseModel and OpenAI::ArrayOf to define and parse JSON schemas.

Quick Start & Requirements

  • Install via Bundler: gem "openai", "~> 0.16.0"
  • Requires Ruby 3.2.0 or higher.
  • API key is required, typically set via the OPENAI_API_KEY environment variable.
  • Documentation: RubyDoc

Highlighted Details

  • Comprehensive type definitions for Yard, RBS, and RBI, with Sorbet integration.
  • Built-in webhook verification and payload parsing.
  • Support for sending file uploads via Pathname, StringIO, or raw content.
  • Automatic retries with exponential backoff for transient errors.
  • Thread-safe client instances with per-instance connection pools.

Maintenance & Community

The project follows SemVer conventions. As it is in major version 0, APIs may change. Contributions are welcome via the contributing documentation.

Licensing & Compatibility

The library is available under the MIT license, permitting commercial use and integration with closed-source applications.

Limitations & Caveats

The library is in major version 0, indicating potential for breaking changes. Client instances are not fork-safe if HTTP requests are in flight during a fork.

Health Check
Last commit

1 day ago

Responsiveness

1 day

Pull Requests (30d)
6
Issues (30d)
4
Star History
26 stars in the last 30 days

Explore Similar Projects

Starred by Adam Wolff Adam Wolff(Claude Code Core; MTS at Anthropic), Samuel Colvin Samuel Colvin(Author of Pydantic, Pydantic Logfire, PydanticAI), and
5 more.

anthropic-sdk-python by anthropics

0.9%
2k
Python SDK for Anthropic's REST API
created 2 years ago
updated 1 day ago
Feedback? Help us improve.