Requirements
Before installing, ensure you have:- Ruby 3.2.0 or higher
- RubyGems (comes with Ruby)
- Bundler (recommended for application development)
Installation Methods
Set up your API key
The OpenAI client requires an API key to authenticate requests. You can obtain your API key from the OpenAI Platform.Set your API key as an environment variable:For production applications, consider using a secure secrets management solution or environment configuration tool.
The client will automatically read the API key from the
OPENAI_API_KEY environment variable by default.Require the library
In your Ruby code, require the library:
If you installed the gem directly (not using Bundler), you can simply use
require "openai".