# Repository Briefing: openai/openai-ruby
> Source: https://repoforai.com/repo/openai/openai-ruby (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/openai/openai-ruby
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Ruby
- **License**: Apache-2.0
- **Engineering Health**: A+ (92/100 · Maintenance 35/35 · Adoption 17/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v1.5.0 (2026-12-03) — https://github.com/openai/openai-ruby/releases
- **Review Snapshot**: 2026-12-02 (Note: v1.5.0 on 2026-12-03 shipped after this review; verify latest release notes)
- **Deployment / Stack Signals**: API
- **Momentum**: 481 ★ total (+0 24h / +2 7d) · 68 forks
- **When to Use**: Best for: Ruby 3.3+ services that call the OpenAI API and need typed responses, streaming, or file ingestion without maintaining a low-level client. Skip if: 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.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Transport: Pooled `Net::HTTP` by default; injectable `execute(request)` transport with enumerable response bodies.
- Streaming: SSE for Responses and optional `async-websocket` for persistent Responses and Realtime sessions.
- Typing: RBS and RBI support Ruby type tooling; `OpenAI::BaseModel` defines structured output schemas.
- WebSocket lifecycle: Responses supports multiplexed turns, preserves unrecognized event types, and leaves reconnection and replay to callers.
- Ingestion: Vector-store helpers support concurrent uploads, check the 2,000-file batch limit before starting, and default to a 30-minute polling deadline.
- Hosted artifacts: Beta Agents helpers select artifacts from an exact result turn and stream downloads to a local path or writer.
```

## Quick Start / Clone
```bash
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
```
