runapi-imagen-4 0.2.5 → 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 +4 -4
- data/README.md +10 -8
- data/lib/runapi/imagen_4/client.rb +16 -5
- data/lib/runapi/imagen_4/contract_gen.rb +66 -0
- data/lib/runapi/imagen_4/resources/remix_image.rb +4 -13
- data/lib/runapi/imagen_4/resources/text_to_image.rb +7 -13
- data/lib/runapi/imagen_4/types.rb +4 -9
- data/lib/runapi/imagen_4.rb +1 -0
- metadata +11 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea234432febf88c1855e89f392cd149536bbe684e53ff1925ae96cef7389860c
|
|
4
|
+
data.tar.gz: 01eaf089e6d251e3bb5c96c17b9f1a228bf8fca32869040796f1d961d42a96a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6192d061bdd620f15a8cf5436aaa2c53c6a0ec8a780650f10c92f46be7cc112a1398e6cb2769dca74f16df7b92bb3b4a53927fb6f77eb0075a2c4f978eb1ebca
|
|
7
|
+
data.tar.gz: 5cba0828fa53be275b8e835b310a163d1d6b7fce906f3579b9a0f43509724138d5c40e58887c3ee8c1c1dc73dff89bc1a61aaf3faee378c7ca0f86e1eba510de
|
data/README.md
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
# Imagen API Ruby SDK for RunAPI
|
|
1
|
+
# Imagen 4 API Ruby SDK for RunAPI
|
|
2
2
|
|
|
3
|
-
The
|
|
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
|
|
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-
|
|
10
|
+
gem install runapi-imagen-4
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Quick start
|
|
14
14
|
|
|
15
15
|
```ruby
|
|
16
|
-
require "runapi-
|
|
16
|
+
require "runapi-imagen-4"
|
|
17
17
|
|
|
18
18
|
client = RunApi::Imagen4::Client.new
|
|
19
|
-
task = client.
|
|
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.
|
|
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.
|
|
26
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
|
+
|
|
27
29
|
## Language notes
|
|
28
30
|
|
|
29
|
-
Use Ruby keyword arguments and the `RunApi::Imagen4` error classes when building image jobs, Rails workers, or scripts. The available resources
|
|
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.
|
|
30
32
|
|
|
31
33
|
## Links
|
|
32
34
|
|
|
@@ -2,13 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Imagen4
|
|
5
|
-
|
|
6
|
-
|
|
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.
|
|
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
|
-
|
|
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)
|
|
13
24
|
@remix_image = Resources::RemixImage.new(http)
|
|
14
25
|
end
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
"output_count" => {
|
|
33
|
+
"type" => "integer"
|
|
34
|
+
},
|
|
35
|
+
"seed" => {
|
|
36
|
+
"type" => "integer"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"imagen-4-fast" => {
|
|
40
|
+
"aspect_ratio" => {
|
|
41
|
+
"enum" => ["1:1", "16:9", "9:16", "3:4", "4:3"]
|
|
42
|
+
},
|
|
43
|
+
"output_count" => {
|
|
44
|
+
"enum" => [1, 2, 3, 4],
|
|
45
|
+
"type" => "integer"
|
|
46
|
+
},
|
|
47
|
+
"seed" => {
|
|
48
|
+
"type" => "integer"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"imagen-4-ultra" => {
|
|
52
|
+
"aspect_ratio" => {
|
|
53
|
+
"enum" => ["1:1", "16:9", "9:16", "3:4", "4:3"]
|
|
54
|
+
},
|
|
55
|
+
"output_count" => {
|
|
56
|
+
"type" => "integer"
|
|
57
|
+
},
|
|
58
|
+
"seed" => {
|
|
59
|
+
"type" => "integer"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}.freeze
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module Imagen4
|
|
5
5
|
module Resources
|
|
6
|
+
# Imagen 4 image remix resource.
|
|
7
|
+
# Transform source images guided by a text prompt (up to 8 source images).
|
|
6
8
|
class RemixImage
|
|
7
9
|
include RunApi::Core::ResourceHelpers
|
|
8
10
|
|
|
@@ -33,22 +35,11 @@ module RunApi
|
|
|
33
35
|
private
|
|
34
36
|
|
|
35
37
|
def validate_params!(params)
|
|
36
|
-
|
|
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)
|
|
38
|
+
validate_contract!(CONTRACT["remix-image"], params)
|
|
42
39
|
|
|
43
|
-
|
|
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
|
|
40
|
+
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
48
41
|
|
|
49
|
-
def validate_source_image_urls!(params)
|
|
50
42
|
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
43
|
return unless urls.respond_to?(:size) && urls.size > SOURCE_IMAGE_URLS_MAX
|
|
53
44
|
|
|
54
45
|
raise Core::ValidationError, "source_image_urls supports up to #{SOURCE_IMAGE_URLS_MAX} images"
|
|
@@ -3,6 +3,8 @@
|
|
|
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
|
|
|
@@ -32,21 +34,13 @@ module RunApi
|
|
|
32
34
|
private
|
|
33
35
|
|
|
34
36
|
def validate_params!(params)
|
|
35
|
-
|
|
36
|
-
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
37
|
-
|
|
38
|
-
model = param(params, :model)
|
|
39
|
-
raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::MODELS.join(", ")}" unless Types::MODELS.include?(model)
|
|
37
|
+
validate_contract!(CONTRACT["text-to-image"], params)
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def validate_text_params!(params, model)
|
|
45
|
-
validate_optional!(params, :aspect_ratio, Types::TEXT_ASPECT_RATIOS)
|
|
46
|
-
return unless param(params, :output_count)
|
|
39
|
+
raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
|
|
47
40
|
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
if param(params, :output_count) && param(params, :model) != "imagen-4-fast"
|
|
42
|
+
raise Core::ValidationError, "output_count is only supported for imagen-4-fast"
|
|
43
|
+
end
|
|
50
44
|
end
|
|
51
45
|
end
|
|
52
46
|
end
|
|
@@ -2,16 +2,11 @@
|
|
|
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
|
-
|
|
7
|
-
REMIX_MODELS = %w[imagen-4-pro-remix-image].freeze
|
|
8
|
-
MODELS = (TEXT_MODELS + REMIX_MODELS).freeze
|
|
9
|
-
TEXT_ASPECT_RATIOS = %w[1:1 16:9 9:16 3:4 4:3].freeze
|
|
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
|
|
11
|
-
OUTPUT_RESOLUTIONS = %w[1k 2k 4k].freeze
|
|
12
|
-
OUTPUT_FORMATS = %w[png jpg].freeze
|
|
13
|
-
OUTPUT_COUNTS = [1, 2, 3, 4].freeze
|
|
14
|
-
|
|
9
|
+
# A generated image with its CDN URL and optional unprocessed origin URL.
|
|
15
10
|
class Image < RunApi::Core::BaseModel
|
|
16
11
|
optional :url, String
|
|
17
12
|
optional :origin_url, String
|
data/lib/runapi/imagen_4.rb
CHANGED
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
|
+
version: 0.2.7
|
|
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.
|
|
18
|
+
version: 0.2.7
|
|
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.
|
|
26
|
-
description: The
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
version: 0.2.7
|
|
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: []
|