Skip to content

Instantly share code, notes, and snippets.

Last active November 5, 2022 07:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Use OpenAI Image API to "draw" a ruby in Ruby
require "json"
require "bundler"
Bundler.require :default
# Gemfile:
# ---
# source ""
# gem "excon"
def generate_image(prompt:)
args = {
"prompt" => prompt,
"n" => 1,
"size" => "1024x1024",
headers = {
"Authorization" => "Bearer #{OPENAI_API_KEY}",
"Content-Type" => "application/json",
response =
body: args.to_json,
headers: headers,
resp = JSON.parse(response.body)
prompt = "one stone, shining stone, multifaceted gem, pyramidal ruby, ruby stone gem top view, light on multifaceted gem faces, gem edges, multicolor, synthwave, red, dark translucent red, color, 4k, hdr, digital art, artstation super trending, incredible detail, hq"
image_url = generate_image prompt: prompt
puts image_url
`open "#{image_url}"` # opens the image on mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment