openai/openai-ruby
Official Ruby SDK for typed OpenAI API calls, streaming, and realtime sessions
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
openai-ruby is an external-API client, not an inference runtime. Ruby applications use OpenAI::Client to submit requests through resource methods such as responses.create. The default OpenAI::NetHTTPClient wraps standard-library Net::HTTP with connection_pool. YARD docstrings, RBS signatures, and RBI definitions serve different parts of the Ruby tooling ecosystem, while generated models represent known server events.
The transport boundary is explicit: an injected http_client implements execute(request) and returns an OpenAI::HTTPClient::Response whose body can be enumerated in byte chunks. The SDK owns authentication, redirects, and API-level retries; the adapter owns deadlines at the transport level, pooling, and connection lifecycle. The SDK does not close injected transports. For persistent sessions, block-scoped responses.connect and realtime.connect expose WebSocket interfaces with the optional async-websocket dependency.
Key Capabilities & Differentiators
Responses supports regular requests, SSE streaming, structured output through OpenAI::BaseModel, and function calls whose execution and result submission are handled by the application. A persistent Responses WebSocket supports sequential and multiplexed turns with stream_id; unrecognized event types remain visible as UnknownServerEvent. Realtime covers server-side text, committed-turn transcription, one-turn voice, and sideband control of WebRTC or SIP calls. WebRTC call creation preserves the SDP answer and the Location header used to attach a sideband connection.
List methods offer automatic or explicit pagination. Uploads can use paths or in-memory values, with OpenAI::FilePart supplying filenames and MIME types for format-sensitive endpoints. Vector-store helpers can upload concurrently and check the 2,000-file batch limit before sending requests. Polling defaults to a 30-minute deadline and falls back to a five-second interval when the API does not recommend one. Beta Agents helpers collect final results, parse typed output, and download hosted artifacts from the exact result turn.
Trade-offs & Limitations
Compared with calling REST through a general-purpose Ruby HTTP client, the SDK reduces integration work around typed responses, pagination, polling, and streaming. Direct HTTP gives a team tighter control over transport behavior if it is willing to maintain those pieces. Compared with a local inference stack, the gem removes model-serving hardware and runtime work from the Ruby host, but introduces a dependency on API availability, network latency, and service pricing. Its Apache-2.0 license covers the SDK, not API entitlements or data-processing terms.
Failure handling still belongs partly to the application. Responses WebSockets require one reader and serialized writes; they do not automatically reconnect or retry an ambiguous write. Raw IO uploads disable retries because the SDK cannot assume they are rewindable. Vector-store batches are not transactional, so an upload failure can leave earlier successful uploads behind. Helpers may return terminal failed or cancelled resources without raising. Hosted file helpers are not a filesystem sandbox, and interrupted downloads may leave partial output.
Hardware & Deployment Guide
Run Ruby 3.3 or later, add gem "openai", "~> 1.4.0" through Bundler, and configure API credentials. OpenAI::Client reads OPENAI_API_KEY by default; Kubernetes deployments can instead configure OpenAI::Auth::WorkloadIdentity with a service-account token provider. Install async-websocket only if using WebSockets. FFmpeg and FFplay are optional for local audio capture and playback, not prerequisites for ordinary API calls.
Deploy this gem inside the application rather than as a standalone model server. It requires network access to the API, not local model weights or a GPU. Size the host for concurrent requests, open streams, file buffers, and connection usage. The v1.3.0 release added spend alerts and response compaction fields; v1.3.1 documented Evals and saved-prompt deprecations; v1.4.0 added health alert rules and notification retrieval. Check those changes against the API features your application uses when upgrading.
Net::HTTP by default; injectable execute(request) transport with enumerable response bodies.async-websocket for persistent Responses and Realtime sessions.OpenAI::BaseModel defines structured output schemas.Ruby 3.3+ services that call the OpenAI API and need typed responses, streaming, or file ingestion without maintaining a low-level client.
You need offline or self-hosted inference, cannot upgrade an older Ruby runtime, or require WebSocket reconnect and replay to be managed by the client.
Quick Start & Installation
export OPENAI_CLIENT_CERTIFICATE_CHAIN=/secure/path/client-chain.pem export OPENAI_CLIENT_KEY=/secure/path/client-key.pem export IDENTITY_PROVIDER_ID=idp_example export SERVICE_ACCOUNT_ID=svc_acct_example ruby examples/x509_workload_identity.rb
Comparison vs. Top LLMs & Inference Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| openai-ruby ★ | 481 | +2 | Ruby | Apache-2.0 | Official Ruby SDK for typed OpenAI API calls, streaming, and realtime sessions |
| transformers | 169.6k | +337 | Python | Apache-2.0 | A PyTorch model-definition SDK for unified inference and training across modalit |
| pytorch | 105.9k | +299 | Python | — | Python-first tensor SDK for GPU-accelerated training and inference |
| qlib | 50.8k | +197 | Python | MIT | Modular Python framework for quant research, from market data to backtests |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/openai/openai-ruby.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about openai-ruby
How should a Ruby service choose between a regular request, SSE, and a WebSocket?
OpenAI::Client and use responses.create for a complete response or responses.stream for SSE. Use responses.connect with the optional async-websocket gem when you need a persistent connection. Assign one reader per connection, serialize writes, and handle disconnects explicitly: the SDK does not reconnect or replay a write whose delivery is uncertain.Does the SDK require a GPU, and what determines host resource usage?
Can we use the gem commercially and deploy it on our own infrastructure?
When should we call the REST API directly instead of using the gem?
http_client instead: the SDK retains API authentication, redirects, and API-level retries, while your adapter enforces timeouts and manages its own connections.Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy