runapi-grok-imagine 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: 58e4ae262b66e7ef4d87ebb55d1b2f06538bd98c995d69479020b4c57ee078e5
4
- data.tar.gz: bfb6de17046de4da1688e55726992de2843d8b4d163043f077caf2c6ad5d4d73
3
+ metadata.gz: f1e3242748745f800a98bf97daa49bf3a9257e8cd789fd7ad641bc43bd56e864
4
+ data.tar.gz: 639d984e396f8ca06f774e7e52750b0ec7d23db588ec7670495673ffce3adb14
5
5
  SHA512:
6
- metadata.gz: c40cd80ce506d1031d3c33d0e9c0d0d9bb87cf503f40fb2d58c0a108acc37dda04b442c51dcf75157e9f4dc2baabb43e74812bdfedc561554c63c92e75bfe81a
7
- data.tar.gz: 0ce317911aee0cf7d13911413d8c0b9a03edf61f97bedaa01e7dcfc7ac7a7ffda9f049d636a823259b706d6dd03b5aba2c64ab7d4e5d852af5f611d81b2b0b77
6
+ metadata.gz: cc1472f349ac8211430c488460c74d5b1254069e39006247cdedc94975d86cd48d4fa6098883f876d5b9593b75c1dfbd665fd02bd2e2a237b5bd06722cc032e3
7
+ data.tar.gz: 0dc17d476484b3957c40ec0be32f9ad4c667ee07dd7103630bea6bb5ab8aa592624addf3ba7fbc27ff77834f1dafafd0f526d5fefe53b7786892a7d07b586564
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Grok Imagine API Ruby SDK for RunAPI
1
+ # Grok Imagine Ruby SDK for RunAPI
2
2
 
3
- The grok imagine api Ruby SDK is the language-specific package for Grok Imagine on RunAPI. Use this grok imagine 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 Grok Imagine Ruby SDK is the language-specific package for Grok Imagine on RunAPI. Use this package for image and video 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 grok imagine api README is the Ruby package guide inside the public `grok-imagine-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/grok-imagine; for API reference, use https://runapi.ai/docs#grok-imagine; for SDK docs, use https://runapi.ai/docs#sdk-grok-imagine.
5
+ This README is the Ruby package guide inside the public `grok-imagine-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/grok-imagine; for API reference, use https://runapi.ai/docs#grok-imagine; for SDK docs, use https://runapi.ai/docs#sdk-grok-imagine.
6
6
 
7
7
  ## Install
8
8
 
@@ -13,7 +13,7 @@ gem install runapi-grok-imagine
13
13
  ## Quick start
14
14
 
15
15
  ```ruby
16
- require "runapi-grok-imagine"
16
+ require "runapi/grok_imagine"
17
17
 
18
18
  client = RunApi::GrokImagine::Client.new
19
19
  task = client.text_to_video.create(
@@ -28,14 +28,16 @@ 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::GrokImagine` error classes when building image jobs, Rails workers, or scripts. The available resources include text to videos, image to videos, text to images, image to images, extensions, and upscales. 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::GrokImagine` error classes when building media jobs, Rails workers, or scripts. The available resources are `text_to_video`, `image_to_video`, `text_to_image`, `edit_image`, `extensions`, and `upscales`; use `grok-imagine-video-1.5-preview` with either video resource for the preview model. 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
 
35
35
  - Model page: https://runapi.ai/models/grok-imagine
36
36
  - SDK docs: https://runapi.ai/docs#sdk-grok-imagine
37
37
  - Product docs: https://runapi.ai/docs#grok-imagine
38
- - Pricing and rate limits: https://runapi.ai/models/grok-imagine/text-to-video
38
+ - Video 1.5 Preview pricing and rate limits: https://runapi.ai/models/grok-imagine/video-1.5-preview
39
+ - Text-to-video pricing and rate limits: https://runapi.ai/models/grok-imagine/text-to-video
40
+ - Image-to-video pricing and rate limits: https://runapi.ai/models/grok-imagine/image-to-video
39
41
  - Provider comparison: https://runapi.ai/providers/xai
40
42
  - Full catalog: https://runapi.ai/models
41
43
  - Repository: https://github.com/runapi-ai/grok-imagine-sdk
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module GrokImagine
5
+ CONTRACT = {
6
+ "edit-image" => {
7
+ "models" => ["grok-imagine-edit-image"],
8
+ "fields_by_model" => {
9
+ "grok-imagine-edit-image" => {
10
+ "source_image_url" => {
11
+ "required" => true
12
+ }
13
+ }
14
+ }
15
+ },
16
+ "extend" => {
17
+ "models" => [],
18
+ "fields_by_model" => {
19
+ "_" => {
20
+ "extension_duration_seconds" => {
21
+ "enum" => [6, 10],
22
+ "type" => "integer"
23
+ },
24
+ "start_seconds" => {
25
+ "type" => "integer"
26
+ }
27
+ }
28
+ }
29
+ },
30
+ "image-to-video" => {
31
+ "models" => ["grok-imagine-image-to-video", "grok-imagine-video-1.5-preview"],
32
+ "fields_by_model" => {
33
+ "grok-imagine-image-to-video" => {
34
+ "aspect_ratio" => {
35
+ "enum" => ["2:3", "3:2", "1:1", "16:9", "9:16"]
36
+ },
37
+ "duration_seconds" => {
38
+ "type" => "integer"
39
+ },
40
+ "index" => {
41
+ "type" => "integer"
42
+ },
43
+ "motion_style" => {
44
+ "enum" => ["fun", "normal", "spicy"]
45
+ },
46
+ "output_resolution" => {
47
+ "enum" => ["480p", "720p"]
48
+ }
49
+ },
50
+ "grok-imagine-video-1.5-preview" => {
51
+ "aspect_ratio" => {
52
+ "enum" => ["1:1", "16:9", "9:16", "3:2", "2:3", "auto"]
53
+ },
54
+ "duration_seconds" => {
55
+ "min" => 1,
56
+ "max" => 15,
57
+ "type" => "integer"
58
+ },
59
+ "index" => {
60
+ "type" => "integer"
61
+ },
62
+ "output_resolution" => {
63
+ "enum" => ["480p", "720p"]
64
+ },
65
+ "prompt" => {
66
+ "min" => 1,
67
+ "max" => 4096,
68
+ "length" => true
69
+ },
70
+ "source_image_urls" => {
71
+ "required" => true
72
+ }
73
+ }
74
+ },
75
+ "rules" => [{
76
+ "when" => {
77
+ "model" => "grok-imagine-video-1.5-preview"
78
+ },
79
+ "forbidden" => ["source_task_id", "index", "motion_style", "enable_safety_checker"]
80
+ }]
81
+ },
82
+ "text-to-image" => {
83
+ "models" => ["grok-imagine-text-to-image"],
84
+ "fields_by_model" => {
85
+ "grok-imagine-text-to-image" => {
86
+ "aspect_ratio" => {
87
+ "enum" => ["2:3", "3:2", "1:1", "16:9", "9:16"]
88
+ }
89
+ }
90
+ }
91
+ },
92
+ "text-to-video" => {
93
+ "models" => ["grok-imagine-text-to-video", "grok-imagine-video-1.5-preview"],
94
+ "fields_by_model" => {
95
+ "grok-imagine-text-to-video" => {
96
+ "aspect_ratio" => {
97
+ "enum" => ["2:3", "3:2", "1:1", "16:9", "9:16"]
98
+ },
99
+ "duration_seconds" => {
100
+ "type" => "integer"
101
+ },
102
+ "motion_style" => {
103
+ "enum" => ["fun", "normal", "spicy"]
104
+ },
105
+ "output_resolution" => {
106
+ "enum" => ["480p", "720p"]
107
+ }
108
+ },
109
+ "grok-imagine-video-1.5-preview" => {
110
+ "aspect_ratio" => {
111
+ "enum" => ["1:1", "16:9", "9:16", "3:2", "2:3", "auto"]
112
+ },
113
+ "duration_seconds" => {
114
+ "min" => 1,
115
+ "max" => 15,
116
+ "type" => "integer"
117
+ },
118
+ "output_resolution" => {
119
+ "enum" => ["480p", "720p"]
120
+ },
121
+ "prompt" => {
122
+ "required" => true,
123
+ "min" => 1,
124
+ "max" => 4096,
125
+ "length" => true
126
+ }
127
+ }
128
+ },
129
+ "rules" => [{
130
+ "when" => {
131
+ "model" => "grok-imagine-video-1.5-preview"
132
+ },
133
+ "forbidden" => ["motion_style", "enable_safety_checker"]
134
+ }]
135
+ },
136
+ "upscale-image" => {
137
+ "models" => [],
138
+ "fields_by_model" => {
139
+ "_" => {}
140
+ }
141
+ }
142
+ }.freeze
143
+ end
144
+ end
@@ -16,25 +16,25 @@ 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) == Types::EDIT_IMAGE_MODEL
37
+ validate_contract!(CONTRACT["edit-image"], params)
38
38
  raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
39
39
  end
40
40
  end
@@ -17,19 +17,19 @@ 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
@@ -17,25 +17,25 @@ 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
- raise Core::ValidationError, "model is required" unless param(params, :model) == Types::IMAGE_TO_VIDEO_MODEL
38
+ validate_contract!(CONTRACT["image-to-video"], params)
39
39
 
40
40
  source_image_urls = param(params, :source_image_urls)
41
41
  source_task_id = param(params, :source_task_id)
@@ -57,10 +57,6 @@ module RunApi
57
57
  end
58
58
  end
59
59
 
60
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
61
- validate_optional!(params, :motion_style, Types::MOTION_STYLES)
62
- validate_optional!(params, :output_resolution, Types::RESOLUTIONS)
63
-
64
60
  if param(params, :motion_style).to_s == "spicy" && source_image_urls && !source_image_urls.empty?
65
61
  raise Core::ValidationError, "spicy motion_style requires a source_task_id source image."
66
62
  end
@@ -16,27 +16,26 @@ 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) == Types::TEXT_TO_IMAGE_MODEL
37
+ validate_contract!(CONTRACT["text-to-image"], params)
38
38
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
39
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
40
39
  end
41
40
  end
42
41
  end
@@ -16,35 +16,33 @@ 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) == Types::TEXT_TO_VIDEO_MODEL
37
+ validate_contract!(CONTRACT["text-to-video"], params)
38
38
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
39
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
40
- validate_optional!(params, :motion_style, Types::MOTION_STYLES)
41
- validate_optional!(params, :output_resolution, Types::RESOLUTIONS)
42
39
 
43
40
  duration_seconds = param(params, :duration_seconds)
44
41
  if duration_seconds
45
42
  int = duration_seconds.to_i
46
- unless Types::DURATION_RANGE.cover?(int)
47
- raise Core::ValidationError, "duration_seconds must be an integer between 6 and 30"
43
+ range = (param(params, :model) == Types::PREVIEW_MODEL) ? Types::PREVIEW_DURATION_RANGE : Types::DURATION_RANGE
44
+ unless range.cover?(int)
45
+ raise Core::ValidationError, "duration_seconds must be an integer between #{range.min} and #{range.max}"
48
46
  end
49
47
  end
50
48
  end
@@ -17,19 +17,19 @@ 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
@@ -3,15 +3,9 @@
3
3
  module RunApi
4
4
  module GrokImagine
5
5
  module Types
6
- TEXT_TO_VIDEO_MODEL = "grok-imagine-text-to-video"
7
- IMAGE_TO_VIDEO_MODEL = "grok-imagine-image-to-video"
8
- TEXT_TO_IMAGE_MODEL = "grok-imagine-text-to-image"
9
- EDIT_IMAGE_MODEL = "grok-imagine-edit-image"
10
-
11
- ASPECT_RATIOS = %w[2:3 3:2 1:1 16:9 9:16].freeze
12
- MOTION_STYLES = %w[fun normal spicy].freeze
13
- RESOLUTIONS = %w[480p 720p].freeze
14
6
  DURATION_RANGE = (6..30)
7
+ PREVIEW_MODEL = "grok-imagine-video-1.5-preview"
8
+ PREVIEW_DURATION_RANGE = (1..15)
15
9
  EXTENSION_DURATION_SECONDS = [6, 10].freeze
16
10
  INDEX_RANGE = (0..5)
17
11
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "runapi/core"
4
4
  require_relative "grok_imagine/types"
5
+ require_relative "grok_imagine/contract_gen"
5
6
  require_relative "grok_imagine/resources/text_to_video"
6
7
  require_relative "grok_imagine/resources/image_to_video"
7
8
  require_relative "grok_imagine/resources/text_to_image"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-grok-imagine
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.11
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 grok imagine api Ruby SDK is the language-specific package for Grok
27
- Imagine on RunAPI. Use this grok imagine api package for text-to-image, image editing,
28
- and creative production flows when your application needs JSON request bodies, task
29
- status lookup, and consistent RunAPI errors in Ruby.
25
+ version: 0.2.11
26
+ description: The Grok Imagine Ruby SDK is the language-specific package for Grok Imagine
27
+ on RunAPI. Use this package for image and video generation, image editing, and creative
28
+ production workflows when your application needs request bodies, task status lookup,
29
+ and consistent RunAPI errors in Ruby.
30
30
  email:
31
31
  - contact@runapi.ai
32
32
  executables: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/runapi-grok_imagine.rb
40
40
  - lib/runapi/grok_imagine.rb
41
41
  - lib/runapi/grok_imagine/client.rb
42
+ - lib/runapi/grok_imagine/contract_gen.rb
42
43
  - lib/runapi/grok_imagine/resources/edit_image.rb
43
44
  - lib/runapi/grok_imagine/resources/extensions.rb
44
45
  - lib/runapi/grok_imagine/resources/image_to_video.rb
@@ -50,9 +51,11 @@ homepage: https://runapi.ai/models/grok-imagine
50
51
  licenses:
51
52
  - Apache-2.0
52
53
  metadata:
54
+ runapi_slug: grok-imagine
53
55
  homepage_uri: https://runapi.ai/models/grok-imagine
54
56
  documentation_uri: https://github.com/runapi-ai/grok-imagine-sdk/blob/main/ruby/README.md
55
57
  source_code_uri: https://github.com/runapi-ai/grok-imagine-sdk
58
+ bug_tracker_uri: https://github.com/runapi-ai/grok-imagine-sdk/issues
56
59
  changelog_uri: https://github.com/runapi-ai/grok-imagine-sdk/blob/main/CHANGELOG.md
57
60
  rdoc_options: []
58
61
  require_paths:
@@ -70,5 +73,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
73
  requirements: []
71
74
  rubygems_version: 4.0.10
72
75
  specification_version: 4
73
- summary: Grok Imagine API Ruby SDK for RunAPI
76
+ summary: Grok Imagine Ruby SDK for RunAPI
74
77
  test_files: []