runapi-seedream 0.2.4 → 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: b7ab6f0090893fffc1225a5772b6f43b64be31b432f5c6c49827fc746051b371
4
- data.tar.gz: b486a1e417fc2a6c7cfed7f90b1ddf4391acb6d04e436ed21292c7de5a20797e
3
+ metadata.gz: d8ca9b02c90b624e837c7652223020526592784b12d0f0a6f54f7afc6d9ed4d7
4
+ data.tar.gz: a7b2b5fe72b6135055d4f0838fd9e704f6222c9cd1410615d6b1ca718af078c2
5
5
  SHA512:
6
- metadata.gz: 35440b09308862129346ac31a2902c7870070ba8232b0bda93d6df730d5828da666d9c1f9443bf2029a67eb60589848f7f6fdd895edbc33882633fb0d20c3635
7
- data.tar.gz: 67ff779b1d23ee0ec88a441910330c98912f029ff4b286f35ffcb1a428661dac1b3a2951f1d5c18cbeaaa8f0487db9b9adce76cf69e130166bfdbf844b55db83
6
+ metadata.gz: f4a3270d5d1920a9151e5d9053aba445e7a07125522e4508a5da35585d9fc69ecbed5681607fe5895bd829ef50b79b8fb16021dfcb7c76174a8e14e5c090cf28
7
+ data.tar.gz: 2f5cfa1042a0b46d66c70586cd95b24e688eac376699708a8806c8c78bc1ee9aa5abce75eb98f5ef32bbc73985aadad9b99ebead702603dbfef2a2d64cbd60a6
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Seedream API Ruby SDK for RunAPI
2
+
3
+ The seedream api Ruby SDK is the language-specific package for Seedream on RunAPI. Use this seedream 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.
4
+
5
+ This seedream api README is the Ruby package guide inside the public `seedream-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/seedream; for API reference, use https://runapi.ai/docs#seedream; for SDK docs, use https://runapi.ai/docs#sdk-seedream.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-seedream
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi-seedream"
17
+
18
+ client = RunApi::Seedream::Client.new
19
+ task = client.text_to_image.create(
20
+ model: "seedream-v4-text-to-image",
21
+ prompt: "A precise product render of a glass teapot on white marble",
22
+ aspect_ratio: "16:9",
23
+ output_resolution: "2k",
24
+ output_count: 3
25
+ )
26
+ status = client.text_to_image.get(task.id)
27
+ ```
28
+
29
+ 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.
30
+
31
+ 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.
32
+
33
+ ## Language notes
34
+
35
+ Use Ruby keyword arguments and the `RunApi::Seedream` error classes when building image jobs, Rails workers, or scripts. The package exposes `text_to_image` for text models and `edit_image` for editing models. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
36
+
37
+ ## Links
38
+
39
+ - Model page: https://runapi.ai/models/seedream
40
+ - SDK docs: https://runapi.ai/docs#sdk-seedream
41
+ - Product docs: https://runapi.ai/docs#seedream
42
+ - Pricing and rate limits: https://runapi.ai/models/seedream/v4-text-to-image
43
+ - Full catalog: https://runapi.ai/models
44
+ - Repository: https://github.com/runapi-ai/seedream-sdk
45
+
46
+ ## License
47
+
48
+ Licensed under the Apache License, Version 2.0.
@@ -2,15 +2,38 @@
2
2
 
3
3
  module RunApi
4
4
  module Seedream
5
- class Client
5
+ # Seedream image generation and editing API client.
6
+ #
7
+ # Three model families with different field requirements:
8
+ # - 4.5: requires aspect_ratio and output_quality
9
+ # - 5-lite: same required fields as 4.5, faster generation
10
+ # - V4: uses output_resolution instead; supports seed and batch output_count
11
+ #
12
+ # @example
13
+ # client = RunApi::Seedream::Client.new(api_key: "your-api-key")
14
+ #
15
+ # # Seedream 4.5
16
+ # result = client.text_to_image.run(
17
+ # model: "seedream-4.5-text-to-image",
18
+ # prompt: "A beautiful product render",
19
+ # aspect_ratio: "16:9", output_quality: "high"
20
+ # )
21
+ #
22
+ # # Seedream V4 with batch output
23
+ # batch = client.text_to_image.run(
24
+ # model: "seedream-v4-text-to-image",
25
+ # prompt: "Minimalist logo design", output_count: 4
26
+ # )
27
+ class Client < RunApi::Core::Client
28
+ # @return [Resources::TextToImage] Text-to-image generation across model versions.
6
29
  attr_reader :text_to_image
30
+ # @return [Resources::EditImage] Edit source images with a text prompt.
31
+ attr_reader :edit_image
7
32
 
8
33
  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)
34
+ super
13
35
  @text_to_image = Resources::TextToImage.new(http)
36
+ @edit_image = Resources::EditImage.new(http)
14
37
  end
15
38
  end
16
39
  end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Seedream
5
+ module Resources
6
+ # Seedream image editing resource.
7
+ # Modifies source images according to a text prompt.
8
+ # V4 models accept up to 10 source images; 4.5 and 5-lite accept up to 14.
9
+ class EditImage
10
+ include RunApi::Core::ResourceHelpers
11
+
12
+ ENDPOINT = "/api/v1/seedream/edit_image"
13
+ RESPONSE_CLASS = Types::EditImageResponse
14
+ COMPLETED_RESPONSE_CLASS = Types::CompletedEditImageResponse
15
+ PROMPT_MAX_LENGTH = 3000
16
+ V4_PROMPT_MAX_LENGTH = 5000
17
+ PROMPT_MIN_LENGTH_LITE = 3
18
+ V4_OUTPUT_COUNT_RANGE = (1..6)
19
+
20
+ def initialize(http)
21
+ @http = http
22
+ end
23
+
24
+ def run(**params)
25
+ task = create(**params)
26
+ poll_until_complete { get(task.id) }
27
+ end
28
+
29
+ def create(**params)
30
+ params = compact_params(params)
31
+ validate_params!(params)
32
+ request(:post, ENDPOINT, body: params)
33
+ end
34
+
35
+ def get(id)
36
+ request(:get, "#{ENDPOINT}/#{id}")
37
+ end
38
+
39
+ private
40
+
41
+ def validate_params!(params)
42
+ model = param(params, :model)
43
+ raise Core::ValidationError, "model is required" unless model
44
+ unless Types::EDIT_MODELS.include?(model)
45
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::EDIT_MODELS.join(", ")}"
46
+ end
47
+
48
+ prompt = param(params, :prompt)
49
+ raise Core::ValidationError, "prompt is required" unless prompt.is_a?(String) && !prompt.empty?
50
+ max_length = Types::V4_MODELS.include?(model) ? V4_PROMPT_MAX_LENGTH : PROMPT_MAX_LENGTH
51
+ raise Core::ValidationError, "prompt must be at most #{max_length} characters" if prompt.length > max_length
52
+ if Types::LITE_MODELS.include?(model) && prompt.length < PROMPT_MIN_LENGTH_LITE
53
+ raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{PROMPT_MAX_LENGTH} characters"
54
+ end
55
+
56
+ raise Core::ValidationError, "source_image_urls is required" unless field_present?(params, :source_image_urls)
57
+
58
+ if Types::V4_MODELS.include?(model)
59
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
60
+ validate_optional!(params, :output_resolution, Types::V4_OUTPUT_RESOLUTIONS)
61
+ validate_integer_range!(params, :output_count, V4_OUTPUT_COUNT_RANGE)
62
+ validate_integer!(params, :seed)
63
+ else
64
+ validate_required!(params, :aspect_ratio)
65
+ validate_required!(params, :output_quality)
66
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
67
+ validate_optional!(params, :output_quality, Types::OUTPUT_QUALITIES)
68
+ end
69
+ end
70
+
71
+ def validate_required!(params, key)
72
+ raise Core::ValidationError, "#{key} is required" unless field_present?(params, key)
73
+ end
74
+
75
+ def field_present?(params, key)
76
+ value = param(params, key)
77
+ return false if value.nil?
78
+ return value.any? if value.is_a?(Array)
79
+ return !value.empty? if value.respond_to?(:empty?)
80
+
81
+ true
82
+ end
83
+
84
+ def validate_integer!(params, key)
85
+ value = param(params, key)
86
+ return if value.nil?
87
+ return if value.is_a?(Integer)
88
+
89
+ raise Core::ValidationError, "#{key} must be an integer"
90
+ end
91
+
92
+ def validate_integer_range!(params, key, range)
93
+ value = param(params, key)
94
+ return if value.nil?
95
+
96
+ return if value.is_a?(Integer) && range.cover?(value)
97
+
98
+ raise Core::ValidationError, "#{key} must be between #{range.first} and #{range.last}"
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -3,6 +3,9 @@
3
3
  module RunApi
4
4
  module Seedream
5
5
  module Resources
6
+ # Seedream text-to-image generation resource.
7
+ # Field requirements vary by model: 4.5/5-lite require aspect_ratio and
8
+ # output_quality; V4 uses output_resolution and supports seed/output_count.
6
9
  class TextToImage
7
10
  include RunApi::Core::ResourceHelpers
8
11
 
@@ -10,7 +13,9 @@ module RunApi
10
13
  RESPONSE_CLASS = Types::TextToImageResponse
11
14
  COMPLETED_RESPONSE_CLASS = Types::CompletedTextToImageResponse
12
15
  PROMPT_MAX_LENGTH = 3000
16
+ V4_PROMPT_MAX_LENGTH = 5000
13
17
  PROMPT_MIN_LENGTH_LITE = 3
18
+ V4_OUTPUT_COUNT_RANGE = (1..6)
14
19
 
15
20
  def initialize(http)
16
21
  @http = http
@@ -36,28 +41,32 @@ module RunApi
36
41
  def validate_params!(params)
37
42
  model = param(params, :model)
38
43
  raise Core::ValidationError, "model is required" unless model
39
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::MODELS.join(", ")}" unless Types::MODELS.include?(model)
44
+ unless Types::TEXT_TO_IMAGE_MODELS.include?(model)
45
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::TEXT_TO_IMAGE_MODELS.join(", ")}"
46
+ end
40
47
 
41
48
  prompt = param(params, :prompt)
42
49
  raise Core::ValidationError, "prompt is required" unless prompt.is_a?(String) && !prompt.empty?
43
- raise Core::ValidationError, "prompt must be at most #{PROMPT_MAX_LENGTH} characters" if prompt.length > PROMPT_MAX_LENGTH
50
+ max_length = Types::V4_MODELS.include?(model) ? V4_PROMPT_MAX_LENGTH : PROMPT_MAX_LENGTH
51
+ raise Core::ValidationError, "prompt must be at most #{max_length} characters" if prompt.length > max_length
44
52
  if Types::LITE_MODELS.include?(model) && prompt.length < PROMPT_MIN_LENGTH_LITE
45
53
  raise Core::ValidationError, "prompt must be between #{PROMPT_MIN_LENGTH_LITE} and #{PROMPT_MAX_LENGTH} characters"
46
54
  end
47
55
 
48
- validate_required!(params, :aspect_ratio)
49
- validate_required!(params, :quality)
50
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
51
- validate_optional!(params, :quality, Types::QUALITIES)
52
-
53
- if Types::IMAGE_MODELS.include?(model)
54
- raise Core::ValidationError, "image_urls is required" unless field_present?(params, :image_urls)
55
- elsif field_present?(params, :image_urls)
56
- raise Core::ValidationError, "image_urls is not supported for #{model}"
56
+ if Types::V4_MODELS.include?(model)
57
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
58
+ validate_optional!(params, :output_resolution, Types::V4_OUTPUT_RESOLUTIONS)
59
+ validate_integer_range!(params, :output_count, V4_OUTPUT_COUNT_RANGE)
60
+ validate_integer!(params, :seed)
61
+ else
62
+ validate_required!(params, :aspect_ratio)
63
+ validate_required!(params, :output_quality)
64
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
65
+ validate_optional!(params, :output_quality, Types::OUTPUT_QUALITIES)
57
66
  end
58
67
 
59
- if field_present?(params, :nsfw_checker) && !Types::LITE_MODELS.include?(model)
60
- raise Core::ValidationError, "nsfw_checker is not supported for #{model}"
68
+ if field_present?(params, :source_image_urls)
69
+ raise Core::ValidationError, "source_image_urls is not supported for #{model}"
61
70
  end
62
71
  end
63
72
 
@@ -73,6 +82,23 @@ module RunApi
73
82
 
74
83
  true
75
84
  end
85
+
86
+ def validate_integer!(params, key)
87
+ value = param(params, key)
88
+ return if value.nil?
89
+ return if value.is_a?(Integer)
90
+
91
+ raise Core::ValidationError, "#{key} must be an integer"
92
+ end
93
+
94
+ def validate_integer_range!(params, key, range)
95
+ value = param(params, key)
96
+ return if value.nil?
97
+
98
+ return if value.is_a?(Integer) && range.cover?(value)
99
+
100
+ raise Core::ValidationError, "#{key} must be between #{range.first} and #{range.last}"
101
+ end
76
102
  end
77
103
  end
78
104
  end
@@ -2,17 +2,25 @@
2
2
 
3
3
  module RunApi
4
4
  module Seedream
5
+ # Seedream type constants and response models.
6
+ # Model families differ in supported params: 4.5/5-lite require aspect_ratio
7
+ # and output_quality; V4 uses output_resolution and supports seed/output_count.
5
8
  module Types
6
9
  MODELS = %w[
7
10
  seedream-4.5-text-to-image
8
11
  seedream-4.5-edit
9
12
  seedream-5-lite-text-to-image
10
- seedream-5-lite-image-to-image
13
+ seedream-5-lite-edit
14
+ seedream-v4-text-to-image
15
+ seedream-v4-edit
11
16
  ].freeze
12
- IMAGE_MODELS = %w[seedream-4.5-edit seedream-5-lite-image-to-image].freeze
13
- LITE_MODELS = %w[seedream-5-lite-text-to-image seedream-5-lite-image-to-image].freeze
17
+ TEXT_TO_IMAGE_MODELS = %w[seedream-4.5-text-to-image seedream-5-lite-text-to-image seedream-v4-text-to-image].freeze
18
+ EDIT_MODELS = %w[seedream-4.5-edit seedream-5-lite-edit seedream-v4-edit].freeze
19
+ LITE_MODELS = %w[seedream-5-lite-text-to-image seedream-5-lite-edit].freeze
20
+ V4_MODELS = %w[seedream-v4-text-to-image seedream-v4-edit].freeze
14
21
  ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16 2:3 3:2 21:9].freeze
15
- QUALITIES = %w[basic high].freeze
22
+ OUTPUT_QUALITIES = %w[basic high].freeze
23
+ V4_OUTPUT_RESOLUTIONS = %w[1k 2k 4k].freeze
16
24
 
17
25
  class Image < RunApi::Core::BaseModel
18
26
  optional :url, String
@@ -21,16 +29,20 @@ module RunApi
21
29
  class TextToImageResponse < RunApi::Core::TaskResponse
22
30
  required :id, String
23
31
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
24
- optional :images, [ -> { Image } ]
32
+ optional :images, [-> { Image }]
25
33
  optional :error, String
26
34
  end
27
35
 
36
+ EditImageResponse = TextToImageResponse
37
+
28
38
  # Narrowed response returned by `text_to_image.run()` once polling observes
29
39
  # `status: "completed"`. `images` is required so consumers never have to
30
40
  # null-check it on a successful task.
31
41
  class CompletedTextToImageResponse < TextToImageResponse
32
- required :images, [ -> { Image } ]
42
+ required :images, [-> { Image }]
33
43
  end
44
+
45
+ CompletedEditImageResponse = CompletedTextToImageResponse
34
46
  end
35
47
  end
36
48
  end
@@ -3,6 +3,7 @@
3
3
  require "runapi/core"
4
4
  require_relative "seedream/types"
5
5
  require_relative "seedream/resources/text_to_image"
6
+ require_relative "seedream/resources/edit_image"
6
7
  require_relative "seedream/client"
7
8
 
8
9
  module RunApi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-seedream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,25 +15,31 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.4
18
+ version: 0.2.6
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.4
26
- description: RunAPI Seedream SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.6
26
+ description: The seedream api Ruby SDK is the language-specific package for Seedream
27
+ on RunAPI. Use this seedream 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.
27
30
  email:
28
31
  - contact@runapi.ai
29
32
  executables: []
30
33
  extensions: []
31
- extra_rdoc_files: []
34
+ extra_rdoc_files:
35
+ - README.md
32
36
  files:
33
37
  - LICENSE
38
+ - README.md
34
39
  - lib/runapi-seedream.rb
35
40
  - lib/runapi/seedream.rb
36
41
  - lib/runapi/seedream/client.rb
42
+ - lib/runapi/seedream/resources/edit_image.rb
37
43
  - lib/runapi/seedream/resources/text_to_image.rb
38
44
  - lib/runapi/seedream/types.rb
39
45
  homepage: https://runapi.ai/models/seedream
@@ -41,7 +47,7 @@ licenses:
41
47
  - Apache-2.0
42
48
  metadata:
43
49
  homepage_uri: https://runapi.ai/models/seedream
44
- documentation_uri: https://github.com/runapi-ai/seedream-sdk/blob/main/README.md
50
+ documentation_uri: https://github.com/runapi-ai/seedream-sdk/blob/main/ruby/README.md
45
51
  source_code_uri: https://github.com/runapi-ai/seedream-sdk
46
52
  changelog_uri: https://github.com/runapi-ai/seedream-sdk/blob/main/CHANGELOG.md
47
53
  rdoc_options: []
@@ -60,5 +66,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
66
  requirements: []
61
67
  rubygems_version: 4.0.10
62
68
  specification_version: 4
63
- summary: Seedream API SDKs for JavaScript, Ruby, and Go on RunAPI.
69
+ summary: Seedream API Ruby SDK for RunAPI
64
70
  test_files: []