runapi-ideogram-v3 0.2.4 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa5a4f6c6c74bfc6cdaa9bf20a9ee5e32e5d29767cc55fe832176dd39fcc941c
4
- data.tar.gz: adeccc0f2be866d773397005f46603736545f864d4a8a8e16c72e3c06bce0ea1
3
+ metadata.gz: dde03331810a873fb90e94add731e8b5ba2fb708b65793635ba116c62da37097
4
+ data.tar.gz: 30b5662428e00828dbe82f6a86c3d606cd250a1146bc2587bf634bda637985dd
5
5
  SHA512:
6
- metadata.gz: b694267f9dab0786be2f1aa5dbc365aaa4b174bd320356f8f456dd7b7acd8e06ddd24dc1021547945da86e74a2148112797a55762e208379cc2a16b44887674f
7
- data.tar.gz: 02704e5b9736501d2a8ef2d55447d947643843407c1e75f565e7f085cb2388956d00368c33cb3aa98c7af778c17597571bffd6b6be22d52294fb0c9092e635f7
6
+ metadata.gz: 844c94f0cc39f4f591ea2cef59d31f7db91b0a33e0901df371e027b3bb14e80ff12cacb73c295b039894a3236b6f047fee0d9ce6fa7b046b590c6502246677c9
7
+ data.tar.gz: 32848ec85bbdc5d9b57e2e45215260a0652a40053a9d7584061d6aeebabaa8ebc46cf96f831bfd55d7513d9a90b6ed22479e6c0c5842f1948cdb81f6e96db771
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Ideogram API Ruby SDK for RunAPI
2
+
3
+ The ideogram api Ruby SDK is the language-specific package for Ideogram V3 on RunAPI. Use this ideogram api package for text-to-image, character reference generation, edit, remix, reframe, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
+
5
+ This ideogram api README is the Ruby package guide inside the public `ideogram-v3-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/ideogram-v3; for API reference, use https://runapi.ai/docs#ideogram-v3; for SDK docs, use https://runapi.ai/docs#sdk-ideogram-v3.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-ideogram-v3
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi-ideogram-v3"
17
+
18
+ client = RunApi::IdeogramV3::Client.new
19
+ task = client.text_to_image.create(
20
+ model: "ideogram-v3-text-to-image",
21
+ prompt: "A cinematic lakeside at twilight with neon reeds"
22
+ )
23
+ status = client.text_to_image.get(task.id)
24
+ ```
25
+
26
+ Use `create` when you want to submit a task and return quickly, `get` when you need the latest task state, and `run` when a script should create and poll until completion. In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
27
+
28
+ RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
29
+
30
+ ## Language notes
31
+
32
+ Use Ruby keyword arguments and the `RunApi::IdeogramV3` error classes when building image jobs, Rails workers, or scripts. The available resources are `text_to_image`, `edit_image`, `remix_image`, and `reframe_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
33
+
34
+ ## Links
35
+
36
+ - Model page: https://runapi.ai/models/ideogram-v3
37
+ - SDK docs: https://runapi.ai/docs#sdk-ideogram-v3
38
+ - Product docs: https://runapi.ai/docs#ideogram-v3
39
+ - Pricing and rate limits: https://runapi.ai/models/ideogram-v3/text-to-image
40
+ - Provider comparison: https://runapi.ai/providers/ideogram
41
+ - Full catalog: https://runapi.ai/models
42
+ - Repository: https://github.com/runapi-ai/ideogram-v3-sdk
43
+
44
+ ## License
45
+
46
+ Licensed under the Apache License, Version 2.0.
@@ -4,26 +4,31 @@ module RunApi
4
4
  module IdeogramV3
5
5
  # Ideogram V3 image generation API client.
6
6
  #
7
+ # Supports text-to-image, inpaint editing, remix, and reframe operations.
8
+ # Character model variants add character consistency from reference images.
9
+ #
7
10
  # @example
8
11
  # client = RunApi::IdeogramV3::Client.new(api_key: "your-api-key")
9
12
  # result = client.text_to_image.run(
10
13
  # model: "ideogram-v3-text-to-image",
11
14
  # prompt: "A cinematic lakeside at twilight"
12
15
  # )
13
- class Client
14
- # @return [Resources::TextToImage] Text-to-image operations.
15
- # @return [Resources::EditImage] Inpaint-with-mask operations.
16
- # @return [Resources::RemixImage] Image remix operations.
17
- attr_reader :text_to_image, :edit_image, :remix_image
16
+ class Client < RunApi::Core::Client
17
+ # @return [Resources::TextToImage] Text-to-image generation operations.
18
+ attr_reader :text_to_image
19
+ # @return [Resources::EditImage] Inpaint-with-mask editing operations.
20
+ attr_reader :edit_image
21
+ # @return [Resources::RemixImage] Prompt-guided image variation operations.
22
+ attr_reader :remix_image
23
+ # @return [Resources::ReframeImage] Aspect ratio reframing operations.
24
+ attr_reader :reframe_image
18
25
 
19
26
  def initialize(api_key: nil, **options)
20
- @api_key = Core::Auth.resolve_api_key(api_key)
21
-
22
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
23
- http = client_options.http_client || Core::HttpClient.new(client_options)
27
+ super
24
28
  @text_to_image = Resources::TextToImage.new(http)
25
29
  @edit_image = Resources::EditImage.new(http)
26
30
  @remix_image = Resources::RemixImage.new(http)
31
+ @reframe_image = Resources::ReframeImage.new(http)
27
32
  end
28
33
  end
29
34
  end
@@ -3,7 +3,7 @@
3
3
  module RunApi
4
4
  module IdeogramV3
5
5
  module Resources
6
- # Inpaint with mask (model: ideogram-v3-edit).
6
+ # Inpaint editing using a mask to define the regenerated region.
7
7
  class EditImage
8
8
  include RunApi::Core::ResourceHelpers
9
9
 
@@ -36,8 +36,8 @@ module RunApi
36
36
  def validate_params!(params)
37
37
  model = param(params, :model)
38
38
  raise Core::ValidationError, "model is required" unless model
39
- unless model == Types::EDIT_MODEL
40
- raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::EDIT_MODEL}"
39
+ unless [Types::EDIT_MODEL, Types::CHARACTER_EDIT_MODEL].include?(model)
40
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::EDIT_MODEL} or #{Types::CHARACTER_EDIT_MODEL}"
41
41
  end
42
42
 
43
43
  prompt = param(params, :prompt)
@@ -46,10 +46,29 @@ module RunApi
46
46
  raise Core::ValidationError, "prompt must be at most #{PROMPT_MAX_LENGTH} characters"
47
47
  end
48
48
 
49
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
49
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
50
50
  raise Core::ValidationError, "mask_url is required" unless param(params, :mask_url)
51
51
 
52
52
  validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
53
+ validate_character_fields!(params, model)
54
+ end
55
+
56
+ def validate_character_fields!(params, model)
57
+ refs = param(params, :reference_image_urls)
58
+ if model == Types::CHARACTER_EDIT_MODEL
59
+ raise Core::ValidationError, "reference_image_urls is required" unless refs.is_a?(Array) && refs.any?
60
+ validate_optional!(params, :style, Types::CHARACTER_STYLES)
61
+ elsif refs || param(params, :style)
62
+ raise Core::ValidationError, "character edit fields are not supported for #{model}"
63
+ end
64
+ validate_output_count!(params)
65
+ end
66
+
67
+ def validate_output_count!(params)
68
+ return unless (output_count = param(params, :output_count))
69
+ return if Types::OUTPUT_COUNTS.include?(output_count)
70
+
71
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
53
72
  end
54
73
  end
55
74
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module IdeogramV3
5
+ module Resources
6
+ # Extends or crops an image to a new aspect ratio without regenerating content.
7
+ class ReframeImage
8
+ include RunApi::Core::ResourceHelpers
9
+
10
+ ENDPOINT = "/api/v1/ideogram_v3/reframe_image"
11
+ RESPONSE_CLASS = Types::IdeogramResponse
12
+ COMPLETED_RESPONSE_CLASS = Types::CompletedIdeogramResponse
13
+
14
+ def initialize(http)
15
+ @http = http
16
+ end
17
+
18
+ def run(**params)
19
+ task = create(**params)
20
+ poll_until_complete { get(task.id) }
21
+ end
22
+
23
+ def create(**params)
24
+ params = compact_params(params)
25
+ validate_params!(params)
26
+ request(:post, ENDPOINT, body: params)
27
+ end
28
+
29
+ def get(id)
30
+ request(:get, "#{ENDPOINT}/#{id}")
31
+ end
32
+
33
+ private
34
+
35
+ def validate_params!(params)
36
+ model = param(params, :model)
37
+ raise Core::ValidationError, "model is required" unless model
38
+ unless model == Types::REFRAME_MODEL
39
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::REFRAME_MODEL}"
40
+ end
41
+
42
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
43
+ raise Core::ValidationError, "aspect_ratio is required" unless param(params, :aspect_ratio)
44
+
45
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
46
+ validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
47
+ validate_optional!(params, :style, Types::STYLES)
48
+ validate_output_count!(params)
49
+ end
50
+
51
+ def validate_output_count!(params)
52
+ return unless (output_count = param(params, :output_count))
53
+ return if Types::OUTPUT_COUNTS.include?(output_count)
54
+
55
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -3,7 +3,7 @@
3
3
  module RunApi
4
4
  module IdeogramV3
5
5
  module Resources
6
- # Image remix (model: ideogram-v3-remix).
6
+ # Creates a variation of a source image guided by a new text prompt.
7
7
  class RemixImage
8
8
  include RunApi::Core::ResourceHelpers
9
9
 
@@ -12,6 +12,7 @@ module RunApi
12
12
  COMPLETED_RESPONSE_CLASS = Types::CompletedIdeogramResponse
13
13
  PROMPT_MAX_LENGTH = 5000
14
14
  STRENGTH_MIN = 0.01
15
+ CHARACTER_REMIX_STRENGTH_MIN = 0.1
15
16
  STRENGTH_MAX = 1.0
16
17
 
17
18
  def initialize(http)
@@ -38,8 +39,8 @@ module RunApi
38
39
  def validate_params!(params)
39
40
  model = param(params, :model)
40
41
  raise Core::ValidationError, "model is required" unless model
41
- unless model == Types::REMIX_MODEL
42
- raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::REMIX_MODEL}"
42
+ unless [Types::REMIX_MODEL, Types::CHARACTER_REMIX_MODEL].include?(model)
43
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::REMIX_MODEL} or #{Types::CHARACTER_REMIX_MODEL}"
43
44
  end
44
45
 
45
46
  prompt = param(params, :prompt)
@@ -48,25 +49,37 @@ module RunApi
48
49
  raise Core::ValidationError, "prompt must be at most #{PROMPT_MAX_LENGTH} characters"
49
50
  end
50
51
 
51
- raise Core::ValidationError, "image_url is required" unless param(params, :image_url)
52
+ raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
52
53
 
53
54
  validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
54
- validate_optional!(params, :style, Types::STYLES)
55
- validate_optional!(params, :image_size, Types::IMAGE_SIZES)
55
+ style_values = (model == Types::CHARACTER_REMIX_MODEL) ? Types::CHARACTER_STYLES : Types::STYLES
56
+ validate_optional!(params, :style, style_values)
57
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
58
+ validate_character_fields!(params, model)
56
59
 
57
- if (num_images = param(params, :num_images))
58
- unless Types::NUM_IMAGES.include?(num_images.to_s)
59
- raise Core::ValidationError, "Invalid num_images: #{num_images}. Must be one of: #{Types::NUM_IMAGES.join(", ")}"
60
+ if (output_count = param(params, :output_count))
61
+ unless Types::OUTPUT_COUNTS.include?(output_count)
62
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
60
63
  end
61
64
  end
62
65
 
63
66
  if (strength = param(params, :strength))
64
67
  numeric = Float(strength, exception: false)
65
- if numeric.nil? || numeric < STRENGTH_MIN || numeric > STRENGTH_MAX
66
- raise Core::ValidationError, "strength must be between #{STRENGTH_MIN} and #{STRENGTH_MAX}"
68
+ min = (model == Types::CHARACTER_REMIX_MODEL) ? CHARACTER_REMIX_STRENGTH_MIN : STRENGTH_MIN
69
+ if numeric.nil? || numeric < min || numeric > STRENGTH_MAX
70
+ raise Core::ValidationError, "strength must be between #{min} and #{STRENGTH_MAX}"
67
71
  end
68
72
  end
69
73
  end
74
+
75
+ def validate_character_fields!(params, model)
76
+ refs = param(params, :reference_image_urls)
77
+ if model == Types::CHARACTER_REMIX_MODEL
78
+ raise Core::ValidationError, "reference_image_urls is required" unless refs.is_a?(Array) && refs.any?
79
+ elsif refs || param(params, :style_reference_image_urls) || param(params, :reference_mask_urls)
80
+ raise Core::ValidationError, "character remix fields are not supported for #{model}"
81
+ end
82
+ end
70
83
  end
71
84
  end
72
85
  end
@@ -3,7 +3,7 @@
3
3
  module RunApi
4
4
  module IdeogramV3
5
5
  module Resources
6
- # Text-to-image generation (model: ideogram-v3-text-to-image).
6
+ # Generates images from text with configurable speed, style, and aspect ratio.
7
7
  class TextToImage
8
8
  include RunApi::Core::ResourceHelpers
9
9
 
@@ -36,8 +36,8 @@ module RunApi
36
36
  def validate_params!(params)
37
37
  model = param(params, :model)
38
38
  raise Core::ValidationError, "model is required" unless model
39
- unless model == Types::GENERATION_MODEL
40
- raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::GENERATION_MODEL}"
39
+ unless [Types::GENERATION_MODEL, Types::CHARACTER_MODEL].include?(model)
40
+ raise Core::ValidationError, "Invalid model: #{model}. Must be #{Types::GENERATION_MODEL} or #{Types::CHARACTER_MODEL}"
41
41
  end
42
42
 
43
43
  prompt = param(params, :prompt)
@@ -47,8 +47,28 @@ module RunApi
47
47
  end
48
48
 
49
49
  validate_optional!(params, :rendering_speed, Types::RENDERING_SPEEDS)
50
- validate_optional!(params, :style, Types::STYLES)
51
- validate_optional!(params, :image_size, Types::IMAGE_SIZES)
50
+ style_values = (model == Types::CHARACTER_MODEL) ? Types::CHARACTER_STYLES : Types::STYLES
51
+ validate_optional!(params, :style, style_values)
52
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
53
+ validate_character_refs!(params, model)
54
+ validate_output_count!(params)
55
+ end
56
+
57
+ def validate_character_refs!(params, model)
58
+ refs = param(params, :reference_image_urls)
59
+ if model == Types::CHARACTER_MODEL
60
+ raise Core::ValidationError, "reference_image_urls is required" unless refs.is_a?(Array) && refs.any?
61
+ elsif refs
62
+ raise Core::ValidationError, "reference_image_urls is not supported for #{model}"
63
+ end
64
+ end
65
+
66
+ def validate_output_count!(params)
67
+ output_count = param(params, :output_count)
68
+ return unless output_count
69
+ return if Types::OUTPUT_COUNTS.include?(output_count)
70
+
71
+ raise Core::ValidationError, "Invalid output_count: #{output_count}. Must be one of: #{Types::OUTPUT_COUNTS.join(", ")}"
52
72
  end
53
73
  end
54
74
  end
@@ -2,32 +2,44 @@
2
2
 
3
3
  module RunApi
4
4
  module IdeogramV3
5
+ # Type definitions and constants for Ideogram V3.
6
+ # Character model variants add character consistency from reference images.
5
7
  module Types
6
8
  GENERATION_MODEL = "ideogram-v3-text-to-image"
7
9
  EDIT_MODEL = "ideogram-v3-edit"
8
10
  REMIX_MODEL = "ideogram-v3-remix"
11
+ CHARACTER_MODEL = "ideogram-v3-character"
12
+ CHARACTER_EDIT_MODEL = "ideogram-v3-character-edit"
13
+ CHARACTER_REMIX_MODEL = "ideogram-v3-character-remix"
14
+ REFRAME_MODEL = "ideogram-v3-reframe"
9
15
 
10
- RENDERING_SPEEDS = %w[TURBO BALANCED QUALITY].freeze
11
- STYLES = %w[AUTO GENERAL REALISTIC DESIGN].freeze
12
- IMAGE_SIZES = %w[
13
- square square_hd portrait_4_3 portrait_16_9 landscape_4_3 landscape_16_9
14
- ].freeze
15
- NUM_IMAGES = %w[1 2 3 4].freeze
16
+ # Speed-quality tradeoff: turbo is fastest, quality is highest fidelity.
17
+ RENDERING_SPEEDS = %w[turbo balanced quality].freeze
18
+ # Visual style presets for standard (non-character) models.
19
+ STYLES = %w[auto general realistic design].freeze
20
+ # Visual style presets for character-consistency models.
21
+ CHARACTER_STYLES = %w[auto realistic fiction].freeze
22
+ ASPECT_RATIOS = %w[1:1 3:4 9:16 4:3 16:9].freeze
23
+ # Number of images per request (1-4).
24
+ OUTPUT_COUNTS = [1, 2, 3, 4].freeze
16
25
 
26
+ # A single generated image with its CDN URL.
17
27
  class Image < RunApi::Core::BaseModel
18
28
  optional :url, String
19
29
  end
20
30
 
31
+ # Normalized response for all Ideogram V3 endpoints.
32
+ # +images+ is populated once +status+ is +"completed"+.
21
33
  class IdeogramResponse < RunApi::Core::TaskResponse
22
34
  required :id, String
23
35
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
24
- optional :images, [ -> { Image } ]
36
+ optional :images, [-> { Image }]
25
37
  optional :error, String
26
38
  end
27
39
 
28
40
  # Narrowed response returned by `run()` once polling sees `status: "completed"`.
29
41
  class CompletedIdeogramResponse < IdeogramResponse
30
- required :images, [ -> { Image } ]
42
+ required :images, [-> { Image }]
31
43
  end
32
44
  end
33
45
  end
@@ -5,6 +5,7 @@ require_relative "ideogram_v3/types"
5
5
  require_relative "ideogram_v3/resources/text_to_image"
6
6
  require_relative "ideogram_v3/resources/edit_image"
7
7
  require_relative "ideogram_v3/resources/remix_image"
8
+ require_relative "ideogram_v3/resources/reframe_image"
8
9
  require_relative "ideogram_v3/client"
9
10
 
10
11
  module RunApi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-ideogram-v3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,26 +15,32 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.4
18
+ version: 0.2.6
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.2.4
26
- description: RunAPI Ideogram V3 SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.6
26
+ description: The ideogram api Ruby SDK is the language-specific package for Ideogram
27
+ V3 on RunAPI. Use this ideogram api package for text-to-image, character reference
28
+ generation, edit, remix, reframe, and creative production flows when your application
29
+ needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
27
30
  email:
28
31
  - contact@runapi.ai
29
32
  executables: []
30
33
  extensions: []
31
- extra_rdoc_files: []
34
+ extra_rdoc_files:
35
+ - README.md
32
36
  files:
33
37
  - LICENSE
38
+ - README.md
34
39
  - lib/runapi-ideogram_v3.rb
35
40
  - lib/runapi/ideogram_v3.rb
36
41
  - lib/runapi/ideogram_v3/client.rb
37
42
  - lib/runapi/ideogram_v3/resources/edit_image.rb
43
+ - lib/runapi/ideogram_v3/resources/reframe_image.rb
38
44
  - lib/runapi/ideogram_v3/resources/remix_image.rb
39
45
  - lib/runapi/ideogram_v3/resources/text_to_image.rb
40
46
  - lib/runapi/ideogram_v3/types.rb
@@ -43,7 +49,7 @@ licenses:
43
49
  - Apache-2.0
44
50
  metadata:
45
51
  homepage_uri: https://runapi.ai/models/ideogram-v3
46
- documentation_uri: https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/README.md
52
+ documentation_uri: https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/ruby/README.md
47
53
  source_code_uri: https://github.com/runapi-ai/ideogram-v3-sdk
48
54
  changelog_uri: https://github.com/runapi-ai/ideogram-v3-sdk/blob/main/CHANGELOG.md
49
55
  rdoc_options: []
@@ -62,5 +68,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
68
  requirements: []
63
69
  rubygems_version: 4.0.10
64
70
  specification_version: 4
65
- summary: Ideogram V3 API SDKs for JavaScript, Ruby, and Go on RunAPI.
71
+ summary: Ideogram API Ruby SDK for RunAPI
66
72
  test_files: []