runapi-gpt-image 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: 5f0f24d53e5a9bb71de80a322a18692628ce317bd934ef4b940be87f7b89c214
4
- data.tar.gz: 34900b290a2914977d76d8c436fd8f2cdd9486583bbf9e9f68d45b09059accee
3
+ metadata.gz: aefd21d6faae0bc4b3b8d5233eeef9015c8377a2aba2e2ab0414aeae082ce8bd
4
+ data.tar.gz: 80a91ab1e6a9066e61cac383a2e241396b09274052c8db4f234d35d44d322d10
5
5
  SHA512:
6
- metadata.gz: 607cb5ba0c1ab470b6851667c0cba9567a1ee79e3dcd314eeb5c76563f555fd861c5428fb5695045c98560d98a5c9ca4e1a05c120cd972c290d5df8d988a8db7
7
- data.tar.gz: 26386b6c23a5a82143d3e9acc2ef9e28fd0340c35aade98202a819796c5ae3ec1f91f21f1788b17540207c276d567de8aaa1a71bcf895a78c2e0e2414f60cea3
6
+ metadata.gz: 6eadbfd617f632ed1ef9c989884b80782a6fe3ca5ac64ec5d9e6f48e515d7d51d5ba6ec8d4f6bd1c2a7cba62949575872eb00be0eb53901b05327a48c8ff0213
7
+ data.tar.gz: 3083b5683b15cf97eba4ae9c7a5cef84b49f6ab16bfe4a9112f136a59b84d57a83ade4df34b18354882d901c2b308c953e81d4bb6aa71533cc300372b7aa6936
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # GPT Image API Ruby SDK for RunAPI
1
+ # GPT Image Ruby SDK for RunAPI
2
2
 
3
- The gpt image api Ruby SDK is the language-specific package for GPT Image on RunAPI. Use this gpt image 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 Ruby SDK is the language-specific package for GPT Image 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 api README is the Ruby package guide inside the public `gpt-image-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/gpt-image; for API reference, use https://runapi.ai/docs#gpt-image; for SDK docs, use https://runapi.ai/docs#sdk-gpt-image.
5
+ This README is the Ruby package guide inside the public `gpt-image-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/gpt-image; for API reference, use https://runapi.ai/docs#gpt-image; for SDK docs, use https://runapi.ai/docs#sdk-gpt-image.
6
6
 
7
7
  ## Install
8
8
 
@@ -16,17 +16,19 @@ gem install runapi-gpt-image
16
16
  require "runapi-gpt-image"
17
17
 
18
18
  client = RunApi::GptImage::Client.new
19
- task = client.generations.create(
19
+ task = client.text_to_image.create(
20
20
  # Pass the GPT Image JSON request body from https://runapi.ai/docs#gpt-image.
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::GptImage` 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::GptImage` 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,7 +2,9 @@
2
2
 
3
3
  module RunApi
4
4
  module GptImage
5
- # GPT Image 1.5 image generation API client.
5
+ # GPT Image 1.5 generation and editing API client.
6
+ #
7
+ # Both aspect_ratio and quality are required for all operations.
6
8
  #
7
9
  # @example
8
10
  # client = RunApi::GptImage::Client.new(api_key: "your-api-key")
@@ -18,17 +20,14 @@ module RunApi
18
20
  # prompt: "Transform into oil painting",
19
21
  # source_image_urls: ["https://cdn.runapi.ai/public/samples/photo.jpg"]
20
22
  # )
21
- class Client
23
+ class Client < RunApi::Core::Client
22
24
  # @return [Resources::TextToImage] Text-to-image generation operations.
23
25
  attr_reader :text_to_image
24
26
  # @return [Resources::EditImage] Image edit operations.
25
27
  attr_reader :edit_image
26
28
 
27
29
  def initialize(api_key: nil, **options)
28
- @api_key = Core::Auth.resolve_api_key(api_key)
29
-
30
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
31
- http = client_options.http_client || Core::HttpClient.new(client_options)
30
+ super
32
31
  @text_to_image = Resources::TextToImage.new(http)
33
32
  @edit_image = Resources::EditImage.new(http)
34
33
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module GptImage
5
+ CONTRACT = {
6
+ "edit-image" => {
7
+ "models" => ["gpt-image-1.5"],
8
+ "fields_by_model" => {
9
+ "gpt-image-1.5" => {
10
+ "aspect_ratio" => {
11
+ "enum" => ["1:1", "2:3", "3:2"],
12
+ "required" => true
13
+ },
14
+ "prompt" => {
15
+ "required" => true
16
+ },
17
+ "quality" => {
18
+ "enum" => ["medium", "high"],
19
+ "required" => true
20
+ },
21
+ "source_image_urls" => {
22
+ "required" => true
23
+ }
24
+ }
25
+ }
26
+ },
27
+ "text-to-image" => {
28
+ "models" => ["gpt-image-1.5"],
29
+ "fields_by_model" => {
30
+ "gpt-image-1.5" => {
31
+ "aspect_ratio" => {
32
+ "enum" => ["1:1", "2:3", "3:2"],
33
+ "required" => true
34
+ },
35
+ "prompt" => {
36
+ "required" => true
37
+ },
38
+ "quality" => {
39
+ "enum" => ["medium", "high"],
40
+ "required" => true
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }.freeze
46
+ end
47
+ end
@@ -31,7 +31,7 @@ module RunApi
31
31
  # @return [RunApi::GptImage::Types::EditImageResponse] task creation result with id
32
32
  def create(**params)
33
33
  params = compact_params(params)
34
- validate_params!(params)
34
+ validate_contract!(CONTRACT["edit-image"], params)
35
35
  request(:post, ENDPOINT, body: params)
36
36
  end
37
37
 
@@ -42,28 +42,6 @@ module RunApi
42
42
  def get(id)
43
43
  request(:get, "#{ENDPOINT}/#{id}")
44
44
  end
45
-
46
- private
47
-
48
- def validate_params!(params)
49
- raise Core::ValidationError, "model is required" unless param(params, :model)
50
- raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
51
-
52
- model = param(params, :model)
53
- unless Types::EDIT_MODELS.include?(model)
54
- raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::EDIT_MODELS.join(", ")}"
55
- end
56
-
57
- urls = param(params, :source_image_urls)
58
- if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
59
- raise Core::ValidationError, "source_image_urls is required for image editing"
60
- end
61
-
62
- raise Core::ValidationError, "aspect_ratio is required" unless param(params, :aspect_ratio)
63
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
64
- raise Core::ValidationError, "quality is required" unless param(params, :quality)
65
- validate_optional!(params, :quality, Types::QUALITY_VALUES)
66
- end
67
45
  end
68
46
  end
69
47
  end
@@ -31,7 +31,7 @@ module RunApi
31
31
  # @return [RunApi::GptImage::Types::TextToImageResponse] task creation result with id
32
32
  def create(**params)
33
33
  params = compact_params(params)
34
- validate_params!(params)
34
+ validate_contract!(CONTRACT["text-to-image"], params)
35
35
  request(:post, ENDPOINT, body: params)
36
36
  end
37
37
 
@@ -42,23 +42,6 @@ module RunApi
42
42
  def get(id)
43
43
  request(:get, "#{ENDPOINT}/#{id}")
44
44
  end
45
-
46
- private
47
-
48
- def validate_params!(params)
49
- raise Core::ValidationError, "model is required" unless param(params, :model)
50
- raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
51
-
52
- model = param(params, :model)
53
- unless Types::GENERATION_MODELS.include?(model)
54
- raise Core::ValidationError, "Invalid model: #{model}. Must be: #{Types::GENERATION_MODELS.join(", ")}"
55
- end
56
-
57
- raise Core::ValidationError, "aspect_ratio is required" unless param(params, :aspect_ratio)
58
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
59
- raise Core::ValidationError, "quality is required" unless param(params, :quality)
60
- validate_optional!(params, :quality, Types::QUALITY_VALUES)
61
- end
62
45
  end
63
46
  end
64
47
  end
@@ -2,18 +2,15 @@
2
2
 
3
3
  module RunApi
4
4
  module GptImage
5
+ # Type definitions and constants for GPT Image 1.5.
6
+ # Both aspect_ratio and quality are required for all operations.
5
7
  module Types
6
- MODELS = %w[gpt-image-1.5].freeze
7
- GENERATION_MODELS = MODELS
8
- EDIT_MODELS = MODELS
9
-
10
- ASPECT_RATIOS = %w[1:1 2:3 3:2].freeze
11
- QUALITY_VALUES = %w[medium high].freeze
12
-
8
+ # A single generated image with its CDN URL.
13
9
  class Image < RunApi::Core::BaseModel
14
10
  optional :url, String
15
11
  end
16
12
 
13
+ # Generation result. +images+ is populated once +status+ is +"completed"+.
17
14
  class TextToImageResponse < RunApi::Core::TaskResponse
18
15
  required :id, String
19
16
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
@@ -21,6 +18,7 @@ module RunApi
21
18
  optional :error, String
22
19
  end
23
20
 
21
+ # Edit response -- same shape as generation.
24
22
  EditImageResponse = TextToImageResponse
25
23
 
26
24
  # Narrowed response returned by `run()` methods once polling observes
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "runapi/core"
4
4
  require_relative "gpt_image/types"
5
+ require_relative "gpt_image/contract_gen"
5
6
  require_relative "gpt_image/resources/text_to_image"
6
7
  require_relative "gpt_image/resources/edit_image"
7
8
  require_relative "gpt_image/client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-gpt-image
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 api Ruby SDK is the language-specific package for GPT Image
27
- on RunAPI. Use this gpt image api package for text-to-image, image editing, and
28
- 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 Ruby SDK is the language-specific package for GPT Image
27
+ on 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-gpt_image.rb
40
40
  - lib/runapi/gpt_image.rb
41
41
  - lib/runapi/gpt_image/client.rb
42
+ - lib/runapi/gpt_image/contract_gen.rb
42
43
  - lib/runapi/gpt_image/resources/edit_image.rb
43
44
  - lib/runapi/gpt_image/resources/text_to_image.rb
44
45
  - lib/runapi/gpt_image/types.rb
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/gpt-image
46
47
  licenses:
47
48
  - Apache-2.0
48
49
  metadata:
50
+ runapi_slug: gpt-image
49
51
  homepage_uri: https://runapi.ai/models/gpt-image
50
52
  documentation_uri: https://github.com/runapi-ai/gpt-image-sdk/blob/main/ruby/README.md
51
53
  source_code_uri: https://github.com/runapi-ai/gpt-image-sdk
54
+ bug_tracker_uri: https://github.com/runapi-ai/gpt-image-sdk/issues
52
55
  changelog_uri: https://github.com/runapi-ai/gpt-image-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 API Ruby SDK for RunAPI
72
+ summary: GPT Image Ruby SDK for RunAPI
70
73
  test_files: []