Use Sorbet’s static type checker with the OpenAI Ruby SDK’s comprehensive RBI definitions
The OpenAI Ruby SDK provides comprehensive RBI definitions for use with Sorbet, Ruby’s static type checker. The library has no runtime dependency on sorbet-runtime, so you can use Sorbet for development-time type checking without any performance overhead.
# This works but Sorbet won't catch type errors:openai.chat.completions.create( messages: [{role: "user", content: "Say this is a test"}], model: "gpt-5.2")
You can also construct and splat full parameter objects:
params = OpenAI::Chat::CompletionCreateParams.new( messages: [OpenAI::Chat::ChatCompletionUserMessageParam.new(content: "Say this is a test")], model: "gpt-5.2")openai.chat.completions.create(**params)
Using typed parameter classes helps Sorbet catch errors at development time, such as typos in field names or incorrect types.
Since this library doesn’t depend on sorbet-runtime, it cannot provide T::Enum instances. Instead, the SDK uses tagged symbols — primitives at runtime with rich type information for Sorbet.
# Returns the symbol :"in-memory"puts(OpenAI::Chat::CompletionCreateParams::PromptCacheRetention::IN_MEMORY)# Revealed type: `T.all(OpenAI::Chat::CompletionCreateParams::PromptCacheRetention, Symbol)`T.reveal_type(OpenAI::Chat::CompletionCreateParams::PromptCacheRetention::IN_MEMORY)
The OpenAI Ruby SDK considers improvements to *.rbi and *.rbs type definitions to be non-breaking changes according to SemVer. Type definitions may be refined in patch releases.