runapi-imagen-4 0.2.4 → 0.2.6

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: d5f4e885df581cc7e939d349397a8948723856802af80d74a7f90929438d733f
4
- data.tar.gz: 000d78ebd2300190d80fdc136d85f30c74ee6f3f69485b71ded0398c85646063
3
+ metadata.gz: 0bbf9045af4c340dcafd79540eb6ad94787e442eca639d8d274553212b94fe4b
4
+ data.tar.gz: 3dbfbfe5bb5b55cc79425a7c453299cb293805d0069e506dc31062811329fdb6
5
5
  SHA512:
6
- metadata.gz: e4b433e9dab6777d83566a7a86cd7c486a7c69912bd6b1e8cb1c5eb3cf1a2e6082c7a6f6394c308b457f501a669977fdde102cc32a566a3815586ec1efe88e99
7
- data.tar.gz: 47b962cddc2b01bbcb27736c19e7c72af79def1b83193e318d79081b241c51485a56489547f4b97717c361b606dc86027c437cdcdefa0b8bc3973736907ec6d7
6
+ metadata.gz: a88bfe60addfcf7ff41e0dba18c93b3809c57330d837c2dacc5ca1e630edc770cfcddf7ae818632fa13f4c206426824104d1d735740a6a94bb9a9491a9069a74
7
+ data.tar.gz: 600070f645056e36fa40caafcfb165e746ff69a572dcb4da4c9fb5d91bdd801f4cdcc77fff0668968cd01e902f3515f7020cb34ccb9c77d67b128efea0771dde
data/README.md ADDED
@@ -0,0 +1,45 @@
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
+ 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.
28
+
29
+ ## Language notes
30
+
31
+ 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.
32
+
33
+ ## Links
34
+
35
+ - Model page: https://runapi.ai/models/imagen-4
36
+ - SDK docs: https://runapi.ai/docs#sdk-imagen-4
37
+ - Product docs: https://runapi.ai/docs#imagen-4
38
+ - Pricing and rate limits: https://runapi.ai/models/imagen-4/imagen-4
39
+ - Provider comparison: https://runapi.ai/providers/google
40
+ - Full catalog: https://runapi.ai/models
41
+ - Repository: https://github.com/runapi-ai/imagen4-sdk
42
+
43
+ ## License
44
+
45
+ Licensed under the Apache License, Version 2.0.
@@ -2,14 +2,26 @@
2
2
 
3
3
  module RunApi
4
4
  module Imagen4
5
- class Client
5
+ # Imagen 4 text-to-image and remix API client.
6
+ #
7
+ # Three text-to-image quality tiers (imagen-4, imagen-4-fast, imagen-4-ultra)
8
+ # and a dedicated remix model for guided image transformation.
9
+ #
10
+ # @example
11
+ # client = RunApi::Imagen4::Client.new(api_key: "your-api-key")
12
+ # result = client.text_to_image.run(
13
+ # model: "imagen-4", prompt: "A photorealistic mountain landscape"
14
+ # )
15
+ class Client < RunApi::Core::Client
16
+ # @return [Resources::TextToImage] Text-to-image generation across quality tiers.
6
17
  attr_reader :text_to_image
18
+ # @return [Resources::RemixImage] Remix existing images with text-guided transformations.
19
+ attr_reader :remix_image
7
20
 
8
21
  def initialize(api_key: nil, **options)
9
- @api_key = Core::Auth.resolve_api_key(api_key)
10
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
11
- http = client_options.http_client || Core::HttpClient.new(client_options)
22
+ super
12
23
  @text_to_image = Resources::TextToImage.new(http)
24
+ @remix_image = Resources::RemixImage.new(http)
13
25
  end
14
26
  end
15
27
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Imagen4
5
+ module Resources
6
+ # Imagen 4 image remix resource.
7
+ # Transform source images guided by a text prompt (up to 8 source images).
8
+ class RemixImage
9
+ include RunApi::Core::ResourceHelpers
10
+
11
+ ENDPOINT = "/api/v1/imagen_4/remix_image"
12
+ RESPONSE_CLASS = Types::RemixImageResponse
13
+ COMPLETED_RESPONSE_CLASS = Types::CompletedRemixImageResponse
14
+ SOURCE_IMAGE_URLS_MAX = 8
15
+
16
+ def initialize(http)
17
+ @http = http
18
+ end
19
+
20
+ def run(**params)
21
+ task = create(**params)
22
+ poll_until_complete { get(task.id) }
23
+ end
24
+
25
+ def create(**params)
26
+ params = compact_params(params)
27
+ validate_params!(params)
28
+ request(:post, ENDPOINT, body: params)
29
+ end
30
+
31
+ def get(id)
32
+ request(:get, "#{ENDPOINT}/#{id}")
33
+ end
34
+
35
+ private
36
+
37
+ def validate_params!(params)
38
+ model = param(params, :model)
39
+ raise Core::ValidationError, "model is required" unless model
40
+ unless Types::REMIX_MODELS.include?(model)
41
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::REMIX_MODELS.join(", ")}"
42
+ end
43
+ raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
44
+
45
+ validate_source_image_urls!(params)
46
+ validate_optional!(params, :aspect_ratio, Types::PRO_ASPECT_RATIOS)
47
+ validate_optional!(params, :output_resolution, Types::OUTPUT_RESOLUTIONS)
48
+ validate_optional!(params, :output_format, Types::OUTPUT_FORMATS)
49
+ end
50
+
51
+ def validate_source_image_urls!(params)
52
+ urls = param(params, :source_image_urls)
53
+ raise Core::ValidationError, "source_image_urls is required" if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
54
+ return unless urls.respond_to?(:size) && urls.size > SOURCE_IMAGE_URLS_MAX
55
+
56
+ raise Core::ValidationError, "source_image_urls supports up to #{SOURCE_IMAGE_URLS_MAX} images"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -3,14 +3,14 @@
3
3
  module RunApi
4
4
  module Imagen4
5
5
  module Resources
6
+ # Imagen 4 text-to-image generation resource.
7
+ # Generate images from text with three quality tiers; imagen-4-fast supports batch output.
6
8
  class TextToImage
7
9
  include RunApi::Core::ResourceHelpers
8
10
 
9
11
  ENDPOINT = "/api/v1/imagen_4/text_to_image"
10
12
  RESPONSE_CLASS = Types::TextToImageResponse
11
13
  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
14
 
15
15
  def initialize(http)
16
16
  @http = http
@@ -40,35 +40,15 @@ module RunApi
40
40
  model = param(params, :model)
41
41
  raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::MODELS.join(", ")}" unless Types::MODELS.include?(model)
42
42
 
43
- text_model?(model) ? validate_text_params!(params, model) : validate_pro_params!(params, model)
43
+ validate_text_params!(params, model)
44
44
  end
45
45
 
46
46
  def validate_text_params!(params, model)
47
- reject_present!(params, PRO_ONLY_FIELDS, model)
48
47
  validate_optional!(params, :aspect_ratio, Types::TEXT_ASPECT_RATIOS)
49
- return unless param(params, :num_images)
48
+ return unless param(params, :output_count)
50
49
 
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)
50
+ raise Core::ValidationError, "output_count is only supported for imagen-4-fast" unless model == "imagen-4-fast"
51
+ validate_optional!(params, :output_count, Types::OUTPUT_COUNTS)
72
52
  end
73
53
  end
74
54
  end
@@ -2,24 +2,42 @@
2
2
 
3
3
  module RunApi
4
4
  module Imagen4
5
+ # Imagen 4 type constants and response models.
6
+ # Text-to-image supports three quality tiers; remix accepts source images
7
+ # with extended aspect ratios, resolution, and format control.
5
8
  module Types
6
9
  TEXT_MODELS = %w[imagen-4 imagen-4-fast imagen-4-ultra].freeze
7
- MODELS = (TEXT_MODELS + %w[imagen-4-pro-image-to-image]).freeze
10
+ REMIX_MODELS = %w[imagen-4-pro-remix-image].freeze
11
+ MODELS = (TEXT_MODELS + REMIX_MODELS).freeze
8
12
  TEXT_ASPECT_RATIOS = %w[1:1 16:9 9:16 3:4 4:3].freeze
13
+ # Extended aspect ratios for remix, including "auto" which infers from source images.
9
14
  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
15
+ OUTPUT_RESOLUTIONS = %w[1k 2k 4k].freeze
11
16
  OUTPUT_FORMATS = %w[png jpg].freeze
12
- NUM_IMAGES = %w[1 2 3 4].freeze
17
+ # Batch sizes for imagen-4-fast (the only model supporting multi-image output).
18
+ OUTPUT_COUNTS = [1, 2, 3, 4].freeze
19
+
20
+ # A generated image with its CDN URL and optional unprocessed origin URL.
21
+ class Image < RunApi::Core::BaseModel
22
+ optional :url, String
23
+ optional :origin_url, String
24
+ end
13
25
 
14
26
  class TextToImageResponse < RunApi::Core::TaskResponse
15
27
  required :id, String
16
28
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
17
- optional :result_urls, [ String ]
29
+ optional :images, [-> { Image }]
18
30
  optional :error, String
19
31
  end
20
32
 
21
33
  class CompletedTextToImageResponse < TextToImageResponse
22
- required :result_urls, [ String ]
34
+ required :images, [-> { Image }]
35
+ end
36
+
37
+ class RemixImageResponse < TextToImageResponse
38
+ end
39
+
40
+ class CompletedRemixImageResponse < CompletedTextToImageResponse
23
41
  end
24
42
  end
25
43
  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.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,25 +15,31 @@ 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 Imagen 4 SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.6
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
@@ -41,7 +47,7 @@ licenses:
41
47
  - Apache-2.0
42
48
  metadata:
43
49
  homepage_uri: https://runapi.ai/models/imagen-4
44
- documentation_uri: https://github.com/runapi-ai/imagen-4-sdk/blob/main/README.md
50
+ documentation_uri: https://github.com/runapi-ai/imagen-4-sdk/blob/main/ruby/README.md
45
51
  source_code_uri: https://github.com/runapi-ai/imagen-4-sdk
46
52
  changelog_uri: https://github.com/runapi-ai/imagen-4-sdk/blob/main/CHANGELOG.md
47
53
  rdoc_options: []
@@ -60,5 +66,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
66
  requirements: []
61
67
  rubygems_version: 4.0.10
62
68
  specification_version: 4
63
- summary: Imagen 4 API SDKs for JavaScript, Ruby, and Go on RunAPI.
69
+ summary: Imagen API Ruby SDK for RunAPI
64
70
  test_files: []