runapi-flux-2 0.2.4 → 0.2.5

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: 56c69158fdf9a626666619b7457f16f9a562589eacec46f7358435e3a6cdbd26
4
- data.tar.gz: 4c085ddbf1ccdea5bc7df3302801767049b10a62cb802e07415effd6afa9d822
3
+ metadata.gz: c5fc862c9c9b7e20945a3e8c714a4385338ab39157df4f2bca9d9576b0e67f9c
4
+ data.tar.gz: 58c1c05e82241145801f4c2d78720fd487c8d5cef7ea2cb9c6abae187c7df08c
5
5
  SHA512:
6
- metadata.gz: a475f504bddc3d7319543bab106eb725de27c9c253b3fd435006cb377bde9c10e7fac49a077376f6e733d13b33f86123f8100acb4d66dfeff264b5746cc9f25c
7
- data.tar.gz: c858a93fef4b6227e33a8b70645f7bd63d7f1ebe9b758ddb14eba5de3cdcaf7096fe1b72054c0d818e5e9f9f3d36dca7b44e70fcb4e7b35285598622b6810e00
6
+ metadata.gz: 5bc7816e95f93c880838f604b992a1cecd4fa8014fbe848e6c8181a47445055f63c43dc257cfe9caf17b90e399db5ec6fffaa0aec4f15024b6f94b2cebed45f0
7
+ data.tar.gz: '0856bee6cebfd10be5691713841bea72b654a5f9068adb9cea1cd51bb46b61e1983a8a3f6254708b49ff2a2eae220c3ebaacd4b0971463a4276bf1cac5d52fbf'
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Flux API Ruby SDK for RunAPI
2
+
3
+ The flux api Ruby SDK is the language-specific package for Flux 2 on RunAPI. Use this flux api package for text-to-image, remix-image, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
+
5
+ This flux api README is the Ruby package guide inside the public `flux-2-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/flux-2; for API reference, use https://runapi.ai/docs#flux-2; for SDK docs, use https://runapi.ai/docs#sdk-flux-2.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ gem install runapi-flux_2
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require "runapi/flux_2"
17
+
18
+ client = RunApi::Flux2::Client.new
19
+
20
+ task = client.text_to_image.create(
21
+ model: "flux-2-pro-text-to-image",
22
+ prompt: "A cinematic product photo on warm paper",
23
+ aspect_ratio: "1:1"
24
+ )
25
+ status = client.text_to_image.get(task.id)
26
+
27
+ remix = client.remix_image.create(
28
+ model: "flux-2-pro-remix-image",
29
+ prompt: "Turn this product shot into a warm editorial photo",
30
+ source_image_urls: ["https://example.com/source.jpg"],
31
+ aspect_ratio: "auto"
32
+ )
33
+ ```
34
+
35
+ 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.
36
+
37
+ ## Language notes
38
+
39
+ Use Ruby keyword arguments and the `RunApi::Flux2` error classes when building image jobs, Rails workers, or scripts. The available resources include `text_to_image` and `remix_image`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
40
+
41
+ ## Links
42
+
43
+ - Model page: https://runapi.ai/models/flux-2
44
+ - SDK docs: https://runapi.ai/docs#sdk-flux-2
45
+ - Product docs: https://runapi.ai/docs#flux-2
46
+ - Pricing and rate limits: https://runapi.ai/models/flux-2/pro-text-to-image
47
+ - Provider comparison: https://runapi.ai/providers/black-forest-labs
48
+ - Full catalog: https://runapi.ai/models
49
+ - Repository: https://github.com/runapi-ai/flux-2-sdk
50
+
51
+ ## License
52
+
53
+ Licensed under the Apache License, Version 2.0.
@@ -11,7 +11,7 @@ module RunApi
11
11
  # )
12
12
  class Client
13
13
  # @return [Resources::TextToImage] Text-to-image operations.
14
- attr_reader :text_to_image
14
+ attr_reader :text_to_image, :remix_image
15
15
 
16
16
  def initialize(api_key: nil, **options)
17
17
  @api_key = Core::Auth.resolve_api_key(api_key)
@@ -19,6 +19,7 @@ module RunApi
19
19
  client_options = Core::ClientOptions.new(api_key: @api_key, **options)
20
20
  http = client_options.http_client || Core::HttpClient.new(client_options)
21
21
  @text_to_image = Resources::TextToImage.new(http)
22
+ @remix_image = Resources::RemixImage.new(http)
22
23
  end
23
24
  end
24
25
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Flux2
5
+ module Resources
6
+ class RemixImage
7
+ include RunApi::Core::ResourceHelpers
8
+
9
+ ENDPOINT = "/api/v1/flux_2/remix_image"
10
+
11
+ RESPONSE_CLASS = Types::RemixImageResponse
12
+ COMPLETED_RESPONSE_CLASS = Types::CompletedRemixImageResponse
13
+
14
+ def initialize(http)
15
+ @http = http
16
+ end
17
+
18
+ def run(**params)
19
+ task = create(**params)
20
+ poll_until_complete { get(task.id) }
21
+ end
22
+
23
+ def create(**params)
24
+ params = compact_params(params)
25
+ validate_params!(params)
26
+ request(:post, ENDPOINT, body: params)
27
+ end
28
+
29
+ def get(id)
30
+ request(:get, "#{ENDPOINT}/#{id}")
31
+ end
32
+
33
+ private
34
+
35
+ def validate_params!(params)
36
+ model = param(params, :model)
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
+
42
+ prompt = param(params, :prompt)
43
+ raise Core::ValidationError, "prompt is required" unless prompt
44
+
45
+ validate_optional!(params, :aspect_ratio, Types::REMIX_ASPECT_RATIOS)
46
+ validate_optional!(params, :output_resolution, Types::OUTPUT_RESOLUTIONS)
47
+ validate_source_image_urls!(params)
48
+ end
49
+
50
+ def validate_source_image_urls!(params)
51
+ urls = param(params, :source_image_urls)
52
+ raise Core::ValidationError, "source_image_urls is required" if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -51,30 +51,12 @@ module RunApi
51
51
  raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
52
52
 
53
53
  model = param(params, :model)
54
- unless Types::MODELS.include?(model)
55
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::MODELS.join(", ")}"
54
+ unless Types::TEXT_TO_IMAGE_MODELS.include?(model)
55
+ raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::TEXT_TO_IMAGE_MODELS.join(", ")}"
56
56
  end
57
57
 
58
- validate_aspect_ratio!(params, model)
59
- validate_optional!(params, :resolution, Types::RESOLUTIONS)
60
- validate_input_urls!(params, model)
61
- end
62
-
63
- def validate_aspect_ratio!(params, model)
64
- return unless param(params, :aspect_ratio)
65
-
66
- allowed = Types::I2I_MODELS.include?(model) ? Types::ASPECT_RATIOS_I2I : Types::ASPECT_RATIOS
67
- value = param(params, :aspect_ratio)
68
- unless allowed.include?(value)
69
- raise Core::ValidationError, "Invalid aspect_ratio: #{value}. Must be one of: #{allowed.join(", ")}"
70
- end
71
- end
72
-
73
- def validate_input_urls!(params, model)
74
- return unless Types::I2I_MODELS.include?(model)
75
-
76
- urls = param(params, :input_urls)
77
- raise Core::ValidationError, "input_urls is required for image-to-image models" if urls.nil? || (urls.respond_to?(:empty?) && urls.empty?)
58
+ validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
59
+ validate_optional!(params, :output_resolution, Types::OUTPUT_RESOLUTIONS)
78
60
  end
79
61
  end
80
62
  end
@@ -4,14 +4,15 @@ module RunApi
4
4
  module Flux2
5
5
  module Types
6
6
  MODELS = %w[
7
- flux-2-pro-text-to-image flux-2-pro-image-to-image
8
- flux-2-flex-text-to-image flux-2-flex-image-to-image
7
+ flux-2-pro-text-to-image flux-2-pro-remix-image
8
+ flux-2-flex-text-to-image flux-2-flex-remix-image
9
9
  ].freeze
10
- I2I_MODELS = %w[flux-2-pro-image-to-image flux-2-flex-image-to-image].freeze
10
+ TEXT_TO_IMAGE_MODELS = %w[flux-2-pro-text-to-image flux-2-flex-text-to-image].freeze
11
+ REMIX_MODELS = %w[flux-2-pro-remix-image flux-2-flex-remix-image].freeze
11
12
 
12
13
  ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16 3:2 2:3].freeze
13
- ASPECT_RATIOS_I2I = %w[1:1 4:3 3:4 16:9 9:16 3:2 2:3 auto].freeze
14
- RESOLUTIONS = %w[1K 2K].freeze
14
+ REMIX_ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16 3:2 2:3 auto].freeze
15
+ OUTPUT_RESOLUTIONS = %w[1k 2k].freeze
15
16
 
16
17
  class Image < RunApi::Core::BaseModel
17
18
  optional :url, String
@@ -20,7 +21,7 @@ module RunApi
20
21
  class TextToImageResponse < RunApi::Core::TaskResponse
21
22
  required :id, String
22
23
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
23
- optional :images, [ -> { Image } ]
24
+ optional :images, [-> { Image }]
24
25
  optional :error, String
25
26
  end
26
27
 
@@ -28,7 +29,13 @@ module RunApi
28
29
  # `status: "completed"`. `images` is required so consumers never have to
29
30
  # null-check it on a successful task.
30
31
  class CompletedTextToImageResponse < TextToImageResponse
31
- required :images, [ -> { Image } ]
32
+ required :images, [-> { Image }]
33
+ end
34
+
35
+ class RemixImageResponse < TextToImageResponse
36
+ end
37
+
38
+ class CompletedRemixImageResponse < CompletedTextToImageResponse
32
39
  end
33
40
  end
34
41
  end
data/lib/runapi/flux_2.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "runapi/core"
4
4
  require_relative "flux_2/types"
5
5
  require_relative "flux_2/resources/text_to_image"
6
+ require_relative "flux_2/resources/remix_image"
6
7
  require_relative "flux_2/client"
7
8
 
8
9
  module RunApi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-flux-2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
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.5
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 Flux 2 SDK for JavaScript, Ruby, and Go
25
+ version: 0.2.5
26
+ description: The flux api Ruby SDK is the language-specific package for Flux 2 on
27
+ RunAPI. Use this flux api package for text-to-image, remix-image, and creative production
28
+ flows when your application needs JSON request bodies, task status lookup, and consistent
29
+ 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-flux_2.rb
35
40
  - lib/runapi/flux_2.rb
36
41
  - lib/runapi/flux_2/client.rb
42
+ - lib/runapi/flux_2/resources/remix_image.rb
37
43
  - lib/runapi/flux_2/resources/text_to_image.rb
38
44
  - lib/runapi/flux_2/types.rb
39
45
  homepage: https://runapi.ai/models/flux-2
@@ -41,7 +47,7 @@ licenses:
41
47
  - Apache-2.0
42
48
  metadata:
43
49
  homepage_uri: https://runapi.ai/models/flux-2
44
- documentation_uri: https://github.com/runapi-ai/flux-2-sdk/blob/main/README.md
50
+ documentation_uri: https://github.com/runapi-ai/flux-2-sdk/blob/main/ruby/README.md
45
51
  source_code_uri: https://github.com/runapi-ai/flux-2-sdk
46
52
  changelog_uri: https://github.com/runapi-ai/flux-2-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: Flux 2 API SDKs for JavaScript, Ruby, and Go on RunAPI.
69
+ summary: Flux API Ruby SDK for RunAPI
64
70
  test_files: []