Installation
Install the gem using Bundler or directly with gem install
Quick Start
Make your first API call in minutes
API Reference
Explore all available methods and resources
Examples
Browse real-world code examples
Key Features
The OpenAI Ruby SDK is designed to make working with the OpenAI API seamless and intuitive:Streaming Support
Built-in support for streaming responses using Server-Sent Events (SSE), allowing you to process API responses in real-time as they’re generated.Auto-Pagination
Automatic pagination for list methods withauto_paging_each, so you don’t have to manually request successive pages of results.
Structured Outputs & Function Calling
Powerful helpers withOpenAI::BaseModel, OpenAI::ArrayOf, OpenAI::EnumOf, and OpenAI::UnionOf to define JSON schemas for structured outputs and function calling.
File Upload Support
Flexible file upload handling with support forPathname, StringIO, raw file contents, and more.
Webhook Verification
Built-in methods to verify webhook signatures and parse webhook payloads securely.Error Handling
Comprehensive error classes for all API status codes with automatic retries for transient failures.Type Safety
Full Sorbet, RBS, and RBI type definitions included for a completely type-safe development experience.Concurrency & Connection Pooling
Threadsafe client instances with built-in connection pooling using theconnection_pool gem.
Requirements
- Ruby 3.2.0 or higher
- The standard library’s
net/httpis used as the HTTP transport - Connection pooling via the
connection_poolgem