Last active
August 8, 2025 16:49
-
-
Save peterc/e38f5399e7f756f47f70bb6b846c763d to your computer and use it in GitHub Desktop.
Calling GPT-5 from a plain Ruby script using the official OpenAI library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "openai" | |
client = OpenAI::Client.new # assumes valid key in OPENAI_API_KEY | |
begin | |
resp = client.chat.completions.create( | |
model: :"gpt-5-nano", | |
reasoning_effort: :high, | |
verbosity: :low, | |
messages: [{ role: "user", content: "Tell me a joke" }] | |
) | |
puts resp.choices[0].message.content | |
puts "#{resp.usage.completion_tokens} (of which #{resp.usage.completion_tokens_details.reasoning_tokens} were reasoning tokens)" | |
rescue => e | |
puts e.body[:error][:message] | |
end | |
# reasoning_effort can be :minimal, :low, :medium, :high | |
# verbosity can be :low, :medium, :high |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMPORTANT UPDATE! RubyLLM does support GPT-5, I'm just an idiot who didn't read all the documentation. RubyLLM has a registry of models that stands distinct from the specific version you have installed and you can update it! More info at https://rubyllm.com/models/#refreshing-the-registry https://x.com/paolino/status/1953591077480665217
Thanks to @crmne for bringing this to my attention. My little "hack" above will force the issue, however, if for some reason you don't/can't/won't update the registry.