runapi-imagen-4 0.2.3 → 0.2.5

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: e32f7352009ab431260c80bd74e785871b09dbe6d154e3bebbc0e4d8f5d78fe6
4
- data.tar.gz: 000d78ebd2300190d80fdc136d85f30c74ee6f3f69485b71ded0398c85646063
3
+ metadata.gz: 4f4e5fd22878c20e6318ec7fc7bdd5e7effe61fae9befa12bffdba5db425a4f7
4
+ data.tar.gz: ec0458e1aae7aa8258c38b5087fd4cdf082eb296a7e7bd310cec8aade7591f49
5
5
  SHA512:
6
- metadata.gz: 8dd8cf252a8f974d694ac1b167e152eb2b3434b46094aae67ebdc60793ec3f90828864a5691acc225ffdab71883dc0233ad38b6afc3352b5b2a7850d27710c56
7
- data.tar.gz: 47b962cddc2b01bbcb27736c19e7c72af79def1b83193e318d79081b241c51485a56489547f4b97717c361b606dc86027c437cdcdefa0b8bc3973736907ec6d7
6
+ metadata.gz: 7bd0e43504a2503944520588dfbc0d54bfdd9853e14d278cc8f8cefe89415e7925ae5b44cf9f966ed3d647b64f5b4800f505da2baf2cffbd375ce8cc624bbd40
7
+ data.tar.gz: f4af6fed80942b5b91c87ea59b4ca1c2779acc988e10f2c1ee744983181aa532cc2d8a1ef514b457e1b97b474112c2895ad8505dc456ebcb4fa6b5eb9a388df9
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Imagen API Ruby SDK for RunAPI
2
+
3
+ The imagen api Ruby SDK is the language-specific package for Imagen 4 on RunAPI. Use this imagen api package for text-to-image, image editing, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
+
5
+ This imagen api README is the Ruby package guide inside the public `imagen4-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/imagen-4; for API reference, use https://runapi.ai/docs#imagen-4; for SDK docs, use https://runapi.ai/docs#sdk-imagen-4.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-imagen4
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi-imagen4"
17
+
18
+ client = RunApi::Imagen4::Client.new
19
+ task = client.generations.create(
20
+ # Pass the Imagen 4 JSON request body from https://runapi.ai/docs#imagen-4.
21
+ )
22
+ status = client.generations.get(task.id)
23
+ ```
24
+
25
+ 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.
26
+
27
+ ## Language notes
28
+
29
+ Use Ruby keyword arguments and the `RunApi::Imagen4` error classes when building image jobs, Rails workers, or scripts. The available resources include generations. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
30
+
31
+ ## Links
32
+
33
+ - Model page: https://runapi.ai/models/imagen-4
34
+ - SDK docs: https://runapi.ai/docs#sdk-imagen-4
35
+ - Product docs: https://runapi.ai/docs#imagen-4
36
+ - Pricing and rate limits: https://runapi.ai/models/imagen-4/imagen-4
37
+ - Provider comparison: https://runapi.ai/providers/google
38
+ - Full catalog: https://runapi.ai/models
39
+ - Repository: https://github.com/runapi-ai/imagen4-sdk
40
+
41
+ ## License
42
+
43
+ Licensed under the Apache License, Version 2.0.
@@ -3,13 +3,14 @@
3
3
  module RunApi
4
4
  module Imagen4
5
5
  class Client
6
- attr_reader :text_to_image
6
+ attr_reader :text_to_image, :remix_image
7
7
 
8
8
  def initialize(api_key: nil, **options)
9
9
  @api_key = Core::Auth.resolve_api_key(api_key)
10
10
  client_options = Core::ClientOptions.new(api_key: @api_key, **options)
11
11
  http = client_options.http_client || Core::HttpClient.new(client_options)
12
12
  @text_to_image = Resources::TextToImage.new(http)
13
+ @remix_image = Resources::RemixImage.new(http)
13
14
  end
14
15
  end
15
16
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Imagen4
5
+ module Resources
6
+ class RemixImage
7
+ include RunApi::Core::ResourceHelpers
8
+
9
+ ENDPOINT = "/api/v1/imagen_4/remix_image"
10
+ RESPONSE_CLASS = Types::RemixImageResponse
11
+ COMPLETED_RESPONSE_CLASS = Types::CompletedRemixImageResponse
12
+ SOURCE_IMAGE_URLS_MAX = 8
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 Types::REMIX_MODELS.include?(model)
39
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::REMIX_MODELS.join(", ")}"
40
+ end
41
+ raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
42
+
43
+ validate_source_image_urls!(params)
44
+ validate_optional!(params, :aspect_ratio, Types::PRO_ASPECT_RATIOS)
45
+ validate_optional!(params, :output_resolution, Types::OUTPUT_RESOLUTIONS)
46
+ validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
47
+ end
48
+
49
+ def validate_source_image_urls!(params)
50
+ urls = param(params, :source_image_urls)
51
+ raise Core::ValidationError, "source_image_urls is required" if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
52
+ return unless urls.respond_to?(:size) && urls.size > SOURCE_IMAGE_URLS_MAX
53
+
54
+ raise Core::ValidationError, "source_image_urls supports up to #{SOURCE_IMAGE_URLS_MAX} images"
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -9,8 +9,6 @@ module RunApi
9
9
  ENDPOINT = "/api/v1/imagen_4/text_to_image"
10
10
  RESPONSE_CLASS = Types::TextToImageResponse
11
11
  COMPLETED_RESPONSE_CLASS = Types::CompletedTextToImageResponse
12
- TEXT_ONLY_FIELDS = %i[negative_prompt seed num_images].freeze
13
- PRO_ONLY_FIELDS = %i[image_input resolution output_format].freeze
14
12
 
15
13
  def initialize(http)
16
14
  @http = http
@@ -40,35 +38,15 @@ module RunApi
40
38
  model = param(params, :model)
41
39
  raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::MODELS.join(", ")}" unless Types::MODELS.include?(model)
42
40
 
43
- text_model?(model) ? validate_text_params!(params, model) : validate_pro_params!(params, model)
41
+ validate_text_params!(params, model)
44
42
  end
45
43
 
46
44
  def validate_text_params!(params, model)
47
- reject_present!(params, PRO_ONLY_FIELDS, model)
48
45
  validate_optional!(params, :aspect_ratio, Types::TEXT_ASPECT_RATIOS)
49
- return unless param(params, :num_images)
46
+ return unless param(params, :output_count)
50
47
 
51
- raise Core::ValidationError, "num_images is only supported for imagen-4-fast" unless model == "imagen-4-fast"
52
- validate_optional!(params, :num_images, Types::NUM_IMAGES)
53
- end
54
-
55
- def validate_pro_params!(params, model)
56
- reject_present!(params, TEXT_ONLY_FIELDS, model)
57
- validate_optional!(params, :aspect_ratio, Types::PRO_ASPECT_RATIOS)
58
- validate_optional!(params, :resolution, Types::RESOLUTIONS)
59
- validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
60
- return unless param(params, :image_input)&.size.to_i > 8
61
-
62
- raise Core::ValidationError, "image_input supports up to 8 images"
63
- end
64
-
65
- def reject_present!(params, fields, model)
66
- invalid = fields.find { |field| param(params, field) }
67
- raise Core::ValidationError, "#{invalid} is not supported for #{model}" if invalid
68
- end
69
-
70
- def text_model?(model)
71
- Types::TEXT_MODELS.include?(model)
48
+ raise Core::ValidationError, "output_count is only supported for imagen-4-fast" unless model == "imagen-4-fast"
49
+ validate_optional!(params, :output_count, Types::OUTPUT_COUNTS)
72
50
  end
73
51
  end
74
52
  end
@@ -4,22 +4,34 @@ module RunApi
4
4
  module Imagen4
5
5
  module Types
6
6
  TEXT_MODELS = %w[imagen-4 imagen-4-fast imagen-4-ultra].freeze
7
- MODELS = (TEXT_MODELS + %w[imagen-4-pro-image-to-image]).freeze
7
+ REMIX_MODELS = %w[imagen-4-pro-remix-image].freeze
8
+ MODELS = (TEXT_MODELS + REMIX_MODELS).freeze
8
9
  TEXT_ASPECT_RATIOS = %w[1:1 16:9 9:16 3:4 4:3].freeze
9
10
  PRO_ASPECT_RATIOS = %w[1:1 2:3 3:2 3:4 4:3 4:5 5:4 9:16 16:9 21:9 auto].freeze
10
- RESOLUTIONS = %w[1K 2K 4K].freeze
11
+ OUTPUT_RESOLUTIONS = %w[1k 2k 4k].freeze
11
12
  OUTPUT_FORMATS = %w[png jpg].freeze
12
- NUM_IMAGES = %w[1 2 3 4].freeze
13
+ OUTPUT_COUNTS = [1, 2, 3, 4].freeze
14
+
15
+ class Image < RunApi::Core::BaseModel
16
+ optional :url, String
17
+ optional :origin_url, String
18
+ end
13
19
 
14
20
  class TextToImageResponse < RunApi::Core::TaskResponse
15
21
  required :id, String
16
22
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
17
- optional :result_urls, [ String ]
23
+ optional :images, [-> { Image }]
18
24
  optional :error, String
19
25
  end
20
26
 
21
27
  class CompletedTextToImageResponse < TextToImageResponse
22
- required :result_urls, [ String ]
28
+ required :images, [-> { Image }]
29
+ end
30
+
31
+ class RemixImageResponse < TextToImageResponse
32
+ end
33
+
34
+ class CompletedRemixImageResponse < CompletedTextToImageResponse
23
35
  end
24
36
  end
25
37
  end
@@ -3,4 +3,5 @@
3
3
  require "runapi/core"
4
4
  require_relative "imagen_4/types"
5
5
  require_relative "imagen_4/resources/text_to_image"
6
+ require_relative "imagen_4/resources/remix_image"
6
7
  require_relative "imagen_4/client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-imagen-4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,31 +15,41 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.3
18
+ version: 0.2.5
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.3
26
- description: RunAPI Imagen 4 SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.5
26
+ description: The imagen api Ruby SDK is the language-specific package for Imagen 4
27
+ on RunAPI. Use this imagen api package for text-to-image, image editing, and creative
28
+ production flows when your application needs JSON request bodies, task status lookup,
29
+ 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-imagen_4.rb
35
40
  - lib/runapi/imagen_4.rb
36
41
  - lib/runapi/imagen_4/client.rb
42
+ - lib/runapi/imagen_4/resources/remix_image.rb
37
43
  - lib/runapi/imagen_4/resources/text_to_image.rb
38
44
  - lib/runapi/imagen_4/types.rb
39
45
  homepage: https://runapi.ai/models/imagen-4
40
46
  licenses:
41
47
  - Apache-2.0
42
- metadata: {}
48
+ metadata:
49
+ homepage_uri: https://runapi.ai/models/imagen-4
50
+ documentation_uri: https://github.com/runapi-ai/imagen-4-sdk/blob/main/ruby/README.md
51
+ source_code_uri: https://github.com/runapi-ai/imagen-4-sdk
52
+ changelog_uri: https://github.com/runapi-ai/imagen-4-sdk/blob/main/CHANGELOG.md
43
53
  rdoc_options: []
44
54
  require_paths:
45
55
  - lib
@@ -56,5 +66,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
66
  requirements: []
57
67
  rubygems_version: 4.0.10
58
68
  specification_version: 4
59
- summary: Imagen 4 API SDKs for JavaScript, Ruby, and Go on RunAPI.
69
+ summary: Imagen API Ruby SDK for RunAPI
60
70
  test_files: []