Skip to main content
The OpenAI Ruby SDK ships with comprehensive RBS type signature definitions in the sig/ directory. RBS is Ruby’s standard type signature format, supported by multiple type checkers including Steep.

What is RBS?

RBS is Ruby’s official type signature language. It provides a way to describe the structure of Ruby programs with type definitions in separate .rbs files.

RBS Files Location

The SDK includes RBS signatures in the sig/ directory of the gem:
sig/
├── openai.rbs
├── openai/
│   ├── client.rbs
│   ├── errors.rbs
│   ├── models.rbs
│   └── resources/
│       ├── chat.rbs
│       ├── completions.rbs
│       └── ...

Using RBS with Steep

Steep is the primary type checker for RBS. Here’s how to set it up:
1

Install Steep

Add Steep to your Gemfile:
gem 'steep'
Then run:
bundle install
2

Initialize Steep

Create a Steepfile in your project root:
# Steepfile
target :app do
  check "lib"
  signature "sig"
  
  library "openai"
end
3

Run Type Checking

Run Steep to check your code:
bundle exec steep check

Type-Safe Code Examples

With RBS signatures, type checkers can verify your OpenAI API usage:
require 'openai'

client = OpenAI::Client.new(api_key: ENV["OPENAI_API_KEY"])

# Steep knows the parameter types
completion = client.chat.completions.create(
  messages: [{ role: "user", content: "Hello!" }],
  model: "gpt-5.2"
)

# Steep knows the response structure
content = completion.choices[0].message.content
# Type: String | nil

Type Errors Caught by Steep

Steep will catch common errors:
# Error: Type mismatch
client.chat.completions.create(
  messages: "invalid",  # Should be an Array
  model: "gpt-5.2"
)

# Error: Method not found
response = client.invalid_method()

# Error: No such field
completion.nonexistent_field

Editor Integration

Many editors support RBS through language servers:

VS Code

Install the Ruby LSP extension, which supports RBS type checking.

RubyMine

RubyMine has built-in support for RBS type signatures.

Vim/Neovim

Use the ruby-lsp with your LSP client of choice.

RBS vs RBI (Sorbet)

The OpenAI Ruby SDK provides both RBS and RBI (Sorbet) type definitions:

RBS

Ruby’s standard format
  • Used by Steep
  • Official Ruby signature format
  • Located in sig/ directory
  • Community standard

RBI (Sorbet)

Sorbet’s format
  • Used by Sorbet
  • Runtime type checking option
  • Located in rbi/ directory
  • Tagged symbols for enums
Choose based on your type checker:
  • Use RBS with Steep or other RBS-compatible tools
  • Use RBI with Sorbet
You can use both! They describe the same API and are kept in sync.

Generating RBS for Your Code

If you’re building applications with the OpenAI SDK, you can generate RBS signatures for your own code using typeprof:
# Generate RBS from your Ruby code
bundle exec typeprof lib/my_openai_wrapper.rb > sig/my_openai_wrapper.rbs

Type Definition Updates

The OpenAI Ruby SDK considers improvements to *.rbs and *.rbi type definitions to be non-breaking changes according to SemVer. Type signatures may be refined in patch releases to improve accuracy.

Sorbet Types

Sorbet RBI type definitions

BaseModel

BaseModel conveniences

RBS Documentation

Official RBS documentation

Steep Documentation

Steep type checker docs

Build docs developers (and LLMs) love