Method: Stability::Client#generate_core

Defined in:
lib/stability/client.rb

#generate_core(prompt, options: {}, json: false) ⇒ Object

Performs a text-to-image generation request to the Stability API using Stable Image Core.

Parameters:

  • prompt (String)

    Descriptive prompt for the desired output image. Elements, colors, and subjects should be well-defined for optimal results. Use the format (word:weight) to control the weight of specific words, e.g., “The sky was a crisp (blue:0.3) and (green:0.8)” indicates a sky more green than blue.

  • options (Hash) (defaults to: {})

    Additional options for the request:

    • aspect_ratio [String] Specifies the aspect ratio of the generated image. Options: “16:9”, “1:1” (default), “21:9”, “2:3”, “3:2”, “4:5”, “5:4”, “9:16”, “9:21”

    • negative_prompt [String] Describes elements to be excluded from the image. Max 10000 characters.

    • seed [Integer] Controls the randomness of generation, where 0 uses a random seed. Range: 0 (default) to 4294967294

    • style_preset [String] Guides the image model towards a particular visual style. Options: “3d-model”, “analog-film”, “anime”, “cinematic”, “comic-book”, “digital-art”, “enhance”, “fantasy-art”,

      "isometric", "line-art", "low-poly", "modeling-compound", "neon-punk", "origami", "photographic",
      "pixel-art", "tile-texture"
      
    • output_format [String] Specifies the format of the generated image. Options: “jpeg”, “png” (default), “webp”

  • json (Boolean) (defaults to: false)

    Specifies whether to return the response as a JSON object containing a base64 encoded image or as image bytes directly. Default is false (image bytes directly).



48
49
50
51
52
53
54
55
# File 'lib/stability/client.rb', line 48

def generate_core(prompt, options: {}, json: false)
  headers = { "Accept" => json ? "application/json" : "image/*" }
  parameters = { prompt: }.merge(options)
  multipart_post(path: "/stable-image/generate/core", headers:, parameters:).tap do |response|
    raise ServerError, "Empty response from Stability. Might be worth retrying once or twice." if response.blank?
    raise ServerError, response.dig("error", "message") if response.dig("error", "message").present?
  end.with_indifferent_access
end