Official Ruby SDK for the OpenAI API
open sourceApache-2.0self-hostablefree
The OpenAI Ruby SDK is OpenAI's official Ruby library for the OpenAI API, published as the openai gem (OpenAI took over the gem name in 2025; versions 0.3.0 and older are an unrelated earlier client). It covers the Responses and Chat Completions APIs with Server-Sent Events streaming, structured outputs and function calling from OpenAI::BaseModel classes whose results come back parsed into Ruby objects, a chat completions tool runner, Realtime and Responses WebSockets, files, pagination and webhook verification. It ships Yard, RBS and RBI types for Sorbet, retries and timeouts, uses net/http with connection pooling, and can reach OpenAI models through Azure OpenAI, Amazon Bedrock and Google Vertex AI. It's generated from the API spec and released often, still under 0.x version numbers.
Problems it solves
- send prompts to GPT from a background job in Ruby
- stream chat completion tokens to the browser from a Ruby backend
- get JSON back from the model that matches a Ruby class and parse it into objects
- let the model call my Ruby methods as tools and loop until it answers
- verify that a webhook really came from OpenAI in my Rails controller
- type-check my OpenAI calls in Ruby with Sorbet or RBS
- use OpenAI models through Azure or Amazon Bedrock from Ruby with the same client
- a Ruby client for OpenAI's realtime voice API over WebSockets
- upload files and wait for vector store ingestion from a Ruby script
- which Ruby gem is OpenAI's own and not a community wrapper
Features
- Responses API and Chat Completions
- SSE streaming (responses.stream, chat.completions.stream)
- structured outputs and function calling with OpenAI::BaseModel, ArrayOf, EnumOf and UnionOf, parsed results
- structured-output models from Sorbet T::Struct classes
- automatic chat completions tool runner
- Realtime WebSocket sessions and WebRTC calls; Responses WebSockets
- auto-paginating list methods
- file uploads and vector store ingestion polling
- webhook unwrap and signature verification
- configurable retries and timeouts, request IDs and request logging
View 4 more
- Yard, RBS and RBI type definitions
- providers for Azure OpenAI, Amazon Bedrock and Google Vertex AI; workload identity authentication
- fiber scheduler support and custom HTTP clients
- beta Agents sessions with typed final output
Limitations
Alternatives
The same job
These do what OpenAI Ruby SDK does.
- RubyLLM The Ruby AI framework
- ruby-openai Use the OpenAI API with Ruby
