openai/openai-ruby

Official Ruby SDK for the OpenAI API

What it solves

This library provides a seamless way for Ruby developers to integrate OpenAI's REST API into their applications. It handles the complexities of API communication, including authentication, connection pooling, and data formatting, so you can focus on building features rather than managing HTTP requests.

How it works

The library acts as a client wrapper for the OpenAI API. You initialize a client with your API key and use it to call various services like chat completions, file uploads, or real-time WebSocket sessions. It includes built-in support for streaming responses, automatic tool execution, and paginated data retrieval, all while providing type safety through Yard, RBS, and RBI.

Who it’s for

This project is for Ruby developers (using version 3.3.0 or higher) who need to build applications that interact with OpenAI's models, whether for simple text generation, complex agentic workflows, or real-time voice and text interactions.

Highlights

  • Automatic Tool Runner: Simplifies the process of defining, executing, and returning results for function-calling tools.
  • Streaming Support: Native handling for Server-Sent Events (SSE) and WebSocket-based real-time communication.
  • Type Safety: Includes comprehensive types and docstrings for better developer experience and IDE support.
  • Advanced Transport: Allows for custom HTTP clients, including support for mutual TLS (mTLS) and connection pooling.
  • Convenient Utilities: Features automatic pagination for list methods and polling helpers for long-running file processing tasks.

Related

  • Project
  • Project
  • Project
  • Project
  • Project