Skip to content

Instantly share code, notes, and snippets.

@ftnext
Last active February 12, 2026 15:03
Show Gist options
  • Select an option

  • Save ftnext/c041707004c1dc346df9674186009a7f to your computer and use it in GitHub Desktop.

Select an option

Save ftnext/c041707004c1dc346df9674186009a7f to your computer and use it in GitHub Desktop.
require "faraday"
require "json"
api_key = ENV["GEMINI_API_KEY"]
conn = Faraday.new(
url: "https://generativelanguage.googleapis.com"
)
response = conn.post(
"/v1beta/models/gemini-3-flash-preview:generateContent"
) do |req|
req.headers["Content-type"] = "application/json"
req.headers["x-goog-api-key"] = api_key
req.body = {
contents: [
{
parts: [
{ text: "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?" }
]
}
]
}.to_json
end
json = JSON.parse(response.body)
puts json["candidates"][0]["content"]["parts"][0]["text"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment