runapi-gpt-image-2 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93e24a0cc8419599b2adea4066cf690d2181f89e2b2644834373e971d542f38d
4
- data.tar.gz: 7389dcf5a964ca44a6ecc6a377d1b989711503df69a267815ca41a0388691ae3
3
+ metadata.gz: e679c62e55353ec2c36187098975de7770b69c8407f994aacdb5ea17a794c351
4
+ data.tar.gz: 9286a4d151ae82e9df3b045f1c241b4c738bac936c550c8bcfc4b9cf3b2e5d67
5
5
  SHA512:
6
- metadata.gz: 8e0439329c6d4f35c72539f1f6fae4ed3a8948e0a848f2a3ca14451632f9e50a119491251c4c3c21fe1ff77cba5c087374ee56ac3d6cbb4301abc94228025516
7
- data.tar.gz: 197a2fb299f84efa8a5a004765913658cc7112dade20daa15f1b1e4a53a6c712d3bb102dcc1d4903326d5bf707a9168f7c4631687869dc43f53d0017eaa6e990
6
+ metadata.gz: eb53d80ad81e29e7339bfb845b78fb50f9554d62473559609999deac7c2f55ecebb5041ce296cafe7db807dfd9dab2c8463baaeb35a5b372a27e6b6dfefd29c8
7
+ data.tar.gz: 3685800e58e240512d0533f895ede39d1445c2f00971442aa6000e6b1f3d7ee8c21a2289bec4a49955b81706cd3a33b6f82802859be7fbec8ed47e4e81de014e
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # GPT Image 2 API Ruby SDK for RunAPI
1
+ # GPT Image 2 Ruby SDK for RunAPI
2
2
 
3
- The gpt image 2 api Ruby SDK is the language-specific package for GPT Image 2 on RunAPI. Use this gpt image 2 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 GPT Image 2 Ruby SDK is the language-specific package for GPT Image 2 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 gpt image 2 api README is the Ruby package guide inside the public `gpt-image-2-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/gpt-image-2; for API reference, use https://runapi.ai/docs#gpt-image-2; for SDK docs, use https://runapi.ai/docs#sdk-gpt-image-2.
5
+ This README is the Ruby package guide inside the public `gpt-image-2-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/gpt-image-2; for API reference, use https://runapi.ai/docs#gpt-image-2; for SDK docs, use https://runapi.ai/docs#sdk-gpt-image-2.
6
6
 
7
7
  ## Install
8
8
 
@@ -16,17 +16,19 @@ gem install runapi-gpt-image-2
16
16
  require "runapi-gpt-image-2"
17
17
 
18
18
  client = RunApi::GptImage2::Client.new
19
- task = client.generations.create(
19
+ task = client.text_to_image.create(
20
20
  # Pass the GPT Image 2 JSON request body from https://runapi.ai/docs#gpt-image-2.
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.
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::GptImage2` error classes when building image jobs, Rails workers, or scripts. The available resources include generations, and edits. 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::GptImage2` error classes when building image jobs, Rails workers, or scripts. The available resources are `text_to_image` and `edit_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,14 +2,31 @@
2
2
 
3
3
  module RunApi
4
4
  module GptImage2
5
- class Client
6
- attr_reader :text_to_image, :edit_image
5
+ # GPT Image 2 generation and editing API client.
6
+ #
7
+ # Supports up to 4k output resolution and 'auto' aspect ratio.
8
+ #
9
+ # @example
10
+ # client = RunApi::GptImage2::Client.new(api_key: "your-api-key")
11
+ #
12
+ # # Text-to-image
13
+ # result = client.text_to_image.run(
14
+ # model: "gpt-image-2", prompt: "A futuristic cityscape"
15
+ # )
16
+ #
17
+ # # Edit image
18
+ # edited = client.edit_image.run(
19
+ # model: "gpt-image-2", prompt: "Transform into oil painting",
20
+ # source_image_urls: ["https://cdn.runapi.ai/public/samples/image.jpg"]
21
+ # )
22
+ class Client < RunApi::Core::Client
23
+ # @return [Resources::TextToImage] Text-to-image generation operations.
24
+ attr_reader :text_to_image
25
+ # @return [Resources::EditImage] Prompt-guided image editing operations.
26
+ attr_reader :edit_image
7
27
 
8
28
  def initialize(api_key: nil, **options)
9
- @api_key = Core::Auth.resolve_api_key(api_key)
10
-
11
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
12
- http = client_options.http_client || Core::HttpClient.new(client_options)
29
+ super
13
30
  @text_to_image = Resources::TextToImage.new(http)
14
31
  @edit_image = Resources::EditImage.new(http)
15
32
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module GptImage2
5
+ CONTRACT = {
6
+ "edit-image" => {
7
+ "models" => ["gpt-image-2"],
8
+ "fields_by_model" => {
9
+ "gpt-image-2" => {
10
+ "aspect_ratio" => {
11
+ "enum" => ["auto", "1:1", "3:2", "2:3", "4:3", "3:4", "5:4", "4:5", "16:9", "9:16", "2:1", "1:2", "3:1", "1:3", "21:9", "9:21"]
12
+ },
13
+ "output_resolution" => {
14
+ "enum" => ["1k", "2k", "4k"]
15
+ },
16
+ "prompt" => {
17
+ "required" => true
18
+ },
19
+ "source_image_urls" => {
20
+ "required" => true
21
+ }
22
+ }
23
+ }
24
+ },
25
+ "text-to-image" => {
26
+ "models" => ["gpt-image-2"],
27
+ "fields_by_model" => {
28
+ "gpt-image-2" => {
29
+ "aspect_ratio" => {
30
+ "enum" => ["auto", "1:1", "3:2", "2:3", "4:3", "3:4", "5:4", "4:5", "16:9", "9:16", "2:1", "1:2", "3:1", "1:3", "21:9", "9:21"]
31
+ },
32
+ "output_resolution" => {
33
+ "enum" => ["1k", "2k", "4k"]
34
+ },
35
+ "prompt" => {
36
+ "required" => true
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }.freeze
42
+ end
43
+ end
@@ -3,6 +3,8 @@
3
3
  module RunApi
4
4
  module GptImage2
5
5
  module Resources
6
+ # GPT Image 2 prompt-guided image editing resource.
7
+ # Apply text-guided edits to source images (up to 16).
6
8
  class EditImage
7
9
  include RunApi::Core::ResourceHelpers
8
10
 
@@ -22,33 +24,13 @@ module RunApi
22
24
 
23
25
  def create(**params)
24
26
  params = compact_params(params)
25
- validate_params!(params)
27
+ validate_contract!(CONTRACT["edit-image"], params)
26
28
  request(:post, ENDPOINT, body: params)
27
29
  end
28
30
 
29
31
  def get(id)
30
32
  request(:get, "#{ENDPOINT}/#{id}")
31
33
  end
32
-
33
- private
34
-
35
- def validate_params!(params)
36
- raise Core::ValidationError, "model is required" unless param(params, :model)
37
- raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
38
-
39
- model = param(params, :model)
40
- unless Types::EDIT_MODELS.include?(model)
41
- raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::EDIT_MODELS.join(", ")}"
42
- end
43
-
44
- urls = param(params, :source_image_urls)
45
- if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
46
- raise Core::ValidationError, "source_image_urls is required for edit image requests"
47
- end
48
-
49
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
50
- validate_optional!(params, :output_resolution, Types::RESOLUTIONS)
51
- end
52
34
  end
53
35
  end
54
36
  end
@@ -3,6 +3,8 @@
3
3
  module RunApi
4
4
  module GptImage2
5
5
  module Resources
6
+ # GPT Image 2 text-to-image generation resource.
7
+ # Generate images from text with up to 4k output resolution.
6
8
  class TextToImage
7
9
  include RunApi::Core::ResourceHelpers
8
10
 
@@ -22,28 +24,13 @@ module RunApi
22
24
 
23
25
  def create(**params)
24
26
  params = compact_params(params)
25
- validate_params!(params)
27
+ validate_contract!(CONTRACT["text-to-image"], params)
26
28
  request(:post, ENDPOINT, body: params)
27
29
  end
28
30
 
29
31
  def get(id)
30
32
  request(:get, "#{ENDPOINT}/#{id}")
31
33
  end
32
-
33
- private
34
-
35
- def validate_params!(params)
36
- raise Core::ValidationError, "model is required" unless param(params, :model)
37
- raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
38
-
39
- model = param(params, :model)
40
- unless Types::GENERATION_MODELS.include?(model)
41
- raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::GENERATION_MODELS.join(", ")}"
42
- end
43
-
44
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
45
- validate_optional!(params, :output_resolution, Types::RESOLUTIONS)
46
- end
47
34
  end
48
35
  end
49
36
  end
@@ -2,18 +2,14 @@
2
2
 
3
3
  module RunApi
4
4
  module GptImage2
5
+ # Type definitions for GPT Image 2.
5
6
  module Types
6
- MODELS = %w[gpt-image-2].freeze
7
- GENERATION_MODELS = MODELS
8
- EDIT_MODELS = MODELS
9
-
10
- ASPECT_RATIOS = %w[auto 1:1 9:16 16:9 4:3 3:4].freeze
11
- RESOLUTIONS = %w[1k 2k 4k].freeze
12
-
7
+ # A single generated image with its CDN URL.
13
8
  class Image < RunApi::Core::BaseModel
14
9
  optional :url, String
15
10
  end
16
11
 
12
+ # Generation result. +images+ is populated once +status+ is +"completed"+.
17
13
  class TextToImageResponse < RunApi::Core::TaskResponse
18
14
  required :id, String
19
15
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
@@ -21,8 +17,10 @@ module RunApi
21
17
  optional :error, String
22
18
  end
23
19
 
20
+ # Edit response -- same shape as generation.
24
21
  EditImageResponse = TextToImageResponse
25
22
 
23
+ # Narrowed response from +run()+ where +images+ is guaranteed present.
26
24
  class CompletedTextToImageResponse < TextToImageResponse
27
25
  required :images, [-> { Image }]
28
26
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "runapi/core"
4
4
  require_relative "gpt_image_2/types"
5
+ require_relative "gpt_image_2/contract_gen"
5
6
  require_relative "gpt_image_2/resources/text_to_image"
6
7
  require_relative "gpt_image_2/resources/edit_image"
7
8
  require_relative "gpt_image_2/client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-gpt-image-2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
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.5
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.5
26
- description: The gpt image 2 api Ruby SDK is the language-specific package for GPT
27
- Image 2 on RunAPI. Use this gpt image 2 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.7
26
+ description: The GPT Image 2 Ruby SDK is the language-specific package for GPT Image
27
+ 2 on RunAPI. Use this package for image 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-gpt_image_2.rb
40
40
  - lib/runapi/gpt_image_2.rb
41
41
  - lib/runapi/gpt_image_2/client.rb
42
+ - lib/runapi/gpt_image_2/contract_gen.rb
42
43
  - lib/runapi/gpt_image_2/resources/edit_image.rb
43
44
  - lib/runapi/gpt_image_2/resources/text_to_image.rb
44
45
  - lib/runapi/gpt_image_2/types.rb
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/gpt-image-2
46
47
  licenses:
47
48
  - Apache-2.0
48
49
  metadata:
50
+ runapi_slug: gpt-image-2
49
51
  homepage_uri: https://runapi.ai/models/gpt-image-2
50
52
  documentation_uri: https://github.com/runapi-ai/gpt-image-2-sdk/blob/main/ruby/README.md
51
53
  source_code_uri: https://github.com/runapi-ai/gpt-image-2-sdk
54
+ bug_tracker_uri: https://github.com/runapi-ai/gpt-image-2-sdk/issues
52
55
  changelog_uri: https://github.com/runapi-ai/gpt-image-2-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: GPT Image 2 API Ruby SDK for RunAPI
72
+ summary: GPT Image 2 Ruby SDK for RunAPI
70
73
  test_files: []