runapi-imagen-4 0.2.6 → 0.2.8

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: 0bbf9045af4c340dcafd79540eb6ad94787e442eca639d8d274553212b94fe4b
4
- data.tar.gz: 3dbfbfe5bb5b55cc79425a7c453299cb293805d0069e506dc31062811329fdb6
3
+ metadata.gz: 5263659ace45593a8ec56856209acf33bdd3fc74e365233a57fd4eb0734da662
4
+ data.tar.gz: 267689f4d80d6f6eb9e60c14bafe491d07020b299b6f9e3b2eea8b8813c8c4b9
5
5
  SHA512:
6
- metadata.gz: a88bfe60addfcf7ff41e0dba18c93b3809c57330d837c2dacc5ca1e630edc770cfcddf7ae818632fa13f4c206426824104d1d735740a6a94bb9a9491a9069a74
7
- data.tar.gz: 600070f645056e36fa40caafcfb165e746ff69a572dcb4da4c9fb5d91bdd801f4cdcc77fff0668968cd01e902f3515f7020cb34ccb9c77d67b128efea0771dde
6
+ metadata.gz: 8e2c70344452ea99e8a103f5c34e12d8f75d32ef19e062f5056dc0327dfe0bb6ceb1a63d0d7f7c577e206cf63a58433a0b67cd85c12b9ed2e7bb84b2827641db
7
+ data.tar.gz: 6d7539f159e7ec94f0c6ea779ca019258a6e6d723bee1227a1db5eff8370a8206769370789c1581f837b9f1cba2e3ee0e7ef7a52522e01d53833433b35d39767
data/README.md CHANGED
@@ -1,25 +1,25 @@
1
- # Imagen API Ruby SDK for RunAPI
1
+ # Imagen 4 API Ruby SDK for RunAPI
2
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.
3
+ The Imagen 4 Ruby SDK is the language-specific package for Imagen 4 on RunAPI. Use this package for image generation, image editing, and creative production workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
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.
5
+ This README is the Ruby package guide inside the public `imagen-4-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
6
 
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- gem install runapi-imagen4
10
+ gem install runapi-imagen-4
11
11
  ```
12
12
 
13
13
  ## Quick start
14
14
 
15
15
  ```ruby
16
- require "runapi-imagen4"
16
+ require "runapi/imagen_4"
17
17
 
18
18
  client = RunApi::Imagen4::Client.new
19
- task = client.generations.create(
19
+ task = client.text_to_image.create(
20
20
  # Pass the Imagen 4 JSON request body from https://runapi.ai/docs#imagen-4.
21
21
  )
22
- status = client.generations.get(task.id)
22
+ status = client.text_to_image.get(task.id)
23
23
  ```
24
24
 
25
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.
@@ -28,7 +28,7 @@ RunAPI-generated file URLs are temporary. Download and store generated images, v
28
28
 
29
29
  ## Language notes
30
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.
31
+ Use Ruby keyword arguments and the `RunApi::Imagen4` error classes when building image jobs, Rails workers, or scripts. The available resources are `text_to_image` and `remix_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
32
32
 
33
33
  ## Links
34
34
 
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Imagen4
5
+ CONTRACT = {
6
+ "remix-image" => {
7
+ "models" => ["imagen-4-pro-remix-image"],
8
+ "fields_by_model" => {
9
+ "imagen-4-pro-remix-image" => {
10
+ "aspect_ratio" => {
11
+ "enum" => ["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9", "auto"]
12
+ },
13
+ "output_format" => {
14
+ "enum" => ["png", "jpg"]
15
+ },
16
+ "output_resolution" => {
17
+ "enum" => ["1k", "2k", "4k"]
18
+ },
19
+ "source_image_urls" => {
20
+ "required" => true
21
+ }
22
+ }
23
+ }
24
+ },
25
+ "text-to-image" => {
26
+ "models" => ["imagen-4", "imagen-4-fast", "imagen-4-ultra"],
27
+ "fields_by_model" => {
28
+ "imagen-4" => {
29
+ "aspect_ratio" => {
30
+ "enum" => ["1:1", "16:9", "9:16", "3:4", "4:3"]
31
+ },
32
+ "seed" => {
33
+ "type" => "integer"
34
+ }
35
+ },
36
+ "imagen-4-fast" => {
37
+ "aspect_ratio" => {
38
+ "enum" => ["1:1", "16:9", "9:16", "3:4", "4:3", "auto"]
39
+ },
40
+ "seed" => {
41
+ "type" => "integer"
42
+ }
43
+ },
44
+ "imagen-4-ultra" => {
45
+ "aspect_ratio" => {
46
+ "enum" => ["1:1", "16:9", "9:16", "3:4", "4:3"]
47
+ },
48
+ "seed" => {
49
+ "type" => "integer"
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }.freeze
55
+ end
56
+ end
@@ -17,40 +17,29 @@ module RunApi
17
17
  @http = http
18
18
  end
19
19
 
20
- def run(**params)
21
- task = create(**params)
22
- poll_until_complete { get(task.id) }
20
+ def run(options: nil, **params)
21
+ task = create(options: options, **params)
22
+ poll_until_complete { get(task.id, options: options) }
23
23
  end
24
24
 
25
- def create(**params)
25
+ def create(options: nil, **params)
26
26
  params = compact_params(params)
27
27
  validate_params!(params)
28
- request(:post, ENDPOINT, body: params)
28
+ request(:post, ENDPOINT, body: params, options: options)
29
29
  end
30
30
 
31
- def get(id)
32
- request(:get, "#{ENDPOINT}/#{id}")
31
+ def get(id, options: nil)
32
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
33
33
  end
34
34
 
35
35
  private
36
36
 
37
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)
38
+ validate_contract!(CONTRACT["remix-image"], params)
44
39
 
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
40
+ raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
50
41
 
51
- def validate_source_image_urls!(params)
52
42
  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
43
  return unless urls.respond_to?(:size) && urls.size > SOURCE_IMAGE_URLS_MAX
55
44
 
56
45
  raise Core::ValidationError, "source_image_urls supports up to #{SOURCE_IMAGE_URLS_MAX} images"
@@ -4,7 +4,7 @@ module RunApi
4
4
  module Imagen4
5
5
  module Resources
6
6
  # Imagen 4 text-to-image generation resource.
7
- # Generate images from text with three quality tiers; imagen-4-fast supports batch output.
7
+ # Generate images from text with three quality tiers.
8
8
  class TextToImage
9
9
  include RunApi::Core::ResourceHelpers
10
10
 
@@ -16,39 +16,27 @@ module RunApi
16
16
  @http = http
17
17
  end
18
18
 
19
- def run(**params)
20
- task = create(**params)
21
- poll_until_complete { get(task.id) }
19
+ def run(options: nil, **params)
20
+ task = create(options: options, **params)
21
+ poll_until_complete { get(task.id, options: options) }
22
22
  end
23
23
 
24
- def create(**params)
24
+ def create(options: nil, **params)
25
25
  params = compact_params(params)
26
26
  validate_params!(params)
27
- request(:post, ENDPOINT, body: params)
27
+ request(:post, ENDPOINT, body: params, options: options)
28
28
  end
29
29
 
30
- def get(id)
31
- request(:get, "#{ENDPOINT}/#{id}")
30
+ def get(id, options: nil)
31
+ request(:get, "#{ENDPOINT}/#{id}", options: options)
32
32
  end
33
33
 
34
34
  private
35
35
 
36
36
  def validate_params!(params)
37
- raise Core::ValidationError, "model is required" unless param(params, :model)
38
- raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
39
-
40
- model = param(params, :model)
41
- raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::MODELS.join(", ")}" unless Types::MODELS.include?(model)
42
-
43
- validate_text_params!(params, model)
44
- end
45
-
46
- def validate_text_params!(params, model)
47
- validate_optional!(params, :aspect_ratio, Types::TEXT_ASPECT_RATIOS)
48
- return unless param(params, :output_count)
37
+ validate_contract!(CONTRACT["text-to-image"], params)
49
38
 
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)
39
+ raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
52
40
  end
53
41
  end
54
42
  end
@@ -6,17 +6,6 @@ module RunApi
6
6
  # Text-to-image supports three quality tiers; remix accepts source images
7
7
  # with extended aspect ratios, resolution, and format control.
8
8
  module Types
9
- TEXT_MODELS = %w[imagen-4 imagen-4-fast imagen-4-ultra].freeze
10
- REMIX_MODELS = %w[imagen-4-pro-remix-image].freeze
11
- MODELS = (TEXT_MODELS + REMIX_MODELS).freeze
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.
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
15
- OUTPUT_RESOLUTIONS = %w[1k 2k 4k].freeze
16
- OUTPUT_FORMATS = %w[png jpg].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
9
  # A generated image with its CDN URL and optional unprocessed origin URL.
21
10
  class Image < RunApi::Core::BaseModel
22
11
  optional :url, String
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "runapi/core"
4
4
  require_relative "imagen_4/types"
5
+ require_relative "imagen_4/contract_gen"
5
6
  require_relative "imagen_4/resources/text_to_image"
6
7
  require_relative "imagen_4/resources/remix_image"
7
8
  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.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,18 +15,18 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.6
18
+ version: 0.2.10
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.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.
25
+ version: 0.2.10
26
+ description: The Imagen 4 Ruby SDK is the language-specific package for Imagen 4 on
27
+ RunAPI. Use this package for image generation, image editing, and creative production
28
+ workflows when your application needs request bodies, task status lookup, and consistent
29
+ RunAPI errors in Ruby.
30
30
  email:
31
31
  - contact@runapi.ai
32
32
  executables: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/runapi-imagen_4.rb
40
40
  - lib/runapi/imagen_4.rb
41
41
  - lib/runapi/imagen_4/client.rb
42
+ - lib/runapi/imagen_4/contract_gen.rb
42
43
  - lib/runapi/imagen_4/resources/remix_image.rb
43
44
  - lib/runapi/imagen_4/resources/text_to_image.rb
44
45
  - lib/runapi/imagen_4/types.rb
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/imagen-4
46
47
  licenses:
47
48
  - Apache-2.0
48
49
  metadata:
50
+ runapi_slug: imagen-4
49
51
  homepage_uri: https://runapi.ai/models/imagen-4
50
52
  documentation_uri: https://github.com/runapi-ai/imagen-4-sdk/blob/main/ruby/README.md
51
53
  source_code_uri: https://github.com/runapi-ai/imagen-4-sdk
54
+ bug_tracker_uri: https://github.com/runapi-ai/imagen-4-sdk/issues
52
55
  changelog_uri: https://github.com/runapi-ai/imagen-4-sdk/blob/main/CHANGELOG.md
53
56
  rdoc_options: []
54
57
  require_paths:
@@ -66,5 +69,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
69
  requirements: []
67
70
  rubygems_version: 4.0.10
68
71
  specification_version: 4
69
- summary: Imagen API Ruby SDK for RunAPI
72
+ summary: Imagen 4 API Ruby SDK for RunAPI
70
73
  test_files: []