runapi-flux-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: c5fc862c9c9b7e20945a3e8c714a4385338ab39157df4f2bca9d9576b0e67f9c
4
- data.tar.gz: 58c1c05e82241145801f4c2d78720fd487c8d5cef7ea2cb9c6abae187c7df08c
3
+ metadata.gz: 0d2f7af4be782a923b65df9f4f52418b1afa976271cca57a99931c313040b1ce
4
+ data.tar.gz: 9f2e464857535f906008da2404a43c5183cc1c5e56cecf174eaedbeb54fff064
5
5
  SHA512:
6
- metadata.gz: 5bc7816e95f93c880838f604b992a1cecd4fa8014fbe848e6c8181a47445055f63c43dc257cfe9caf17b90e399db5ec6fffaa0aec4f15024b6f94b2cebed45f0
7
- data.tar.gz: '0856bee6cebfd10be5691713841bea72b654a5f9068adb9cea1cd51bb46b61e1983a8a3f6254708b49ff2a2eae220c3ebaacd4b0971463a4276bf1cac5d52fbf'
6
+ metadata.gz: 3e4064be7f3a33af749e40c6ae7d0d3a0fadff165f50b97fa00e74f5122195a7f97fc8727a2f19896498c2502ab8ae9c8f3ce03ba23c381358c83f22f356a9c4
7
+ data.tar.gz: 2b0450f7cb1d201d8978a9bcc7f42e4ca3756a07f4e146c6cb563bc1d688e6e246b9ee1490c2843e8566135202ce7bffea63eccfb8f7b4bbe25504ef22352a20
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # Flux API Ruby SDK for RunAPI
1
+ # Flux 2 API Ruby SDK for RunAPI
2
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.
3
+ The Flux 2 Ruby SDK is the language-specific package for Flux 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 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.
5
+ This 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
6
 
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- gem install runapi-flux_2
10
+ gem install runapi-flux-2
11
11
  ```
12
12
 
13
13
  ## Quick start
@@ -27,16 +27,18 @@ status = client.text_to_image.get(task.id)
27
27
  remix = client.remix_image.create(
28
28
  model: "flux-2-pro-remix-image",
29
29
  prompt: "Turn this product shot into a warm editorial photo",
30
- source_image_urls: ["https://example.com/source.jpg"],
30
+ source_image_urls: ["https://cdn.runapi.ai/public/samples/image.jpg"],
31
31
  aspect_ratio: "auto"
32
32
  )
33
33
  ```
34
34
 
35
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
36
 
37
+ 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.
38
+
37
39
  ## Language notes
38
40
 
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.
41
+ Use Ruby keyword arguments and the `RunApi::Flux2` error classes when building image jobs, Rails workers, or scripts. The available resources are `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
42
 
41
43
  ## Links
42
44
 
@@ -2,22 +2,24 @@
2
2
 
3
3
  module RunApi
4
4
  module Flux2
5
- # Flux 2 text-to-image API client.
5
+ # Flux 2 text-to-image and remix API client.
6
+ #
7
+ # Pro and flex tiers for both text-to-image generation and
8
+ # text-guided image remixing.
6
9
  #
7
10
  # @example
8
11
  # client = RunApi::Flux2::Client.new(api_key: "your-api-key")
9
12
  # result = client.text_to_image.run(
10
13
  # model: "flux-2-pro-text-to-image", prompt: "A futuristic cityscape"
11
14
  # )
12
- class Client
13
- # @return [Resources::TextToImage] Text-to-image operations.
14
- attr_reader :text_to_image, :remix_image
15
+ class Client < RunApi::Core::Client
16
+ # @return [Resources::TextToImage] Text-to-image generation operations.
17
+ attr_reader :text_to_image
18
+ # @return [Resources::RemixImage] Image remix operations with text-guided transformations.
19
+ attr_reader :remix_image
15
20
 
16
21
  def initialize(api_key: nil, **options)
17
- @api_key = Core::Auth.resolve_api_key(api_key)
18
-
19
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
20
- http = client_options.http_client || Core::HttpClient.new(client_options)
22
+ super
21
23
  @text_to_image = Resources::TextToImage.new(http)
22
24
  @remix_image = Resources::RemixImage.new(http)
23
25
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Flux2
5
+ CONTRACT = {
6
+ "remix-image" => {
7
+ "models" => ["flux-2-flex-remix-image", "flux-2-pro-remix-image"],
8
+ "fields_by_model" => {
9
+ "flux-2-flex-remix-image" => {
10
+ "aspect_ratio" => {
11
+ "enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3", "auto"]
12
+ },
13
+ "output_resolution" => {
14
+ "enum" => ["1k", "2k"]
15
+ },
16
+ "prompt" => {
17
+ "required" => true
18
+ },
19
+ "source_image_urls" => {
20
+ "required" => true
21
+ }
22
+ },
23
+ "flux-2-pro-remix-image" => {
24
+ "aspect_ratio" => {
25
+ "enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3", "auto"]
26
+ },
27
+ "output_resolution" => {
28
+ "enum" => ["1k", "2k"]
29
+ },
30
+ "prompt" => {
31
+ "required" => true
32
+ },
33
+ "source_image_urls" => {
34
+ "required" => true
35
+ }
36
+ }
37
+ }
38
+ },
39
+ "text-to-image" => {
40
+ "models" => ["flux-2-flex-text-to-image", "flux-2-pro-text-to-image"],
41
+ "fields_by_model" => {
42
+ "flux-2-flex-text-to-image" => {
43
+ "aspect_ratio" => {
44
+ "enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
45
+ },
46
+ "output_resolution" => {
47
+ "enum" => ["1k", "2k"]
48
+ },
49
+ "prompt" => {
50
+ "required" => true
51
+ }
52
+ },
53
+ "flux-2-pro-text-to-image" => {
54
+ "aspect_ratio" => {
55
+ "enum" => ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
56
+ },
57
+ "output_resolution" => {
58
+ "enum" => ["1k", "2k"]
59
+ },
60
+ "prompt" => {
61
+ "required" => true
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }.freeze
67
+ end
68
+ end
@@ -3,6 +3,8 @@
3
3
  module RunApi
4
4
  module Flux2
5
5
  module Resources
6
+ # Flux 2 image remix resource.
7
+ # Transform source images guided by a text prompt.
6
8
  class RemixImage
7
9
  include RunApi::Core::ResourceHelpers
8
10
 
@@ -22,35 +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["remix-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
- 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
34
  end
55
35
  end
56
36
  end
@@ -32,7 +32,7 @@ module RunApi
32
32
  # @return [RunApi::Flux2::Types::TextToImageResponse] task creation result with id
33
33
  def create(**params)
34
34
  params = compact_params(params)
35
- validate_params!(params)
35
+ validate_contract!(CONTRACT["text-to-image"], params)
36
36
  request(:post, ENDPOINT, body: params)
37
37
  end
38
38
 
@@ -43,21 +43,6 @@ module RunApi
43
43
  def get(id)
44
44
  request(:get, "#{ENDPOINT}/#{id}")
45
45
  end
46
-
47
- private
48
-
49
- def validate_params!(params)
50
- raise Core::ValidationError, "model is required" unless param(params, :model)
51
- raise Core::ValidationError, "prompt is required" unless param(params, :prompt)
52
-
53
- model = param(params, :model)
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
- end
57
-
58
- validate_optional!(params, :aspect_ratio, Types::ASPECT_RATIOS)
59
- validate_optional!(params, :output_resolution, Types::OUTPUT_RESOLUTIONS)
60
- end
61
46
  end
62
47
  end
63
48
  end
@@ -2,22 +2,15 @@
2
2
 
3
3
  module RunApi
4
4
  module Flux2
5
+ # Type definitions for Flux 2.
6
+ # Each operation has pro (higher fidelity) and flex (faster, lower cost) tiers.
5
7
  module Types
6
- MODELS = %w[
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
- ].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
12
-
13
- ASPECT_RATIOS = %w[1:1 4:3 3:4 16:9 9:16 3:2 2:3].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
16
-
8
+ # A single generated image with its CDN URL.
17
9
  class Image < RunApi::Core::BaseModel
18
10
  optional :url, String
19
11
  end
20
12
 
13
+ # Generation result. +images+ is populated once +status+ is +"completed"+.
21
14
  class TextToImageResponse < RunApi::Core::TaskResponse
22
15
  required :id, String
23
16
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
@@ -32,9 +25,11 @@ module RunApi
32
25
  required :images, [-> { Image }]
33
26
  end
34
27
 
28
+ # Remix response -- same shape as generation.
35
29
  class RemixImageResponse < TextToImageResponse
36
30
  end
37
31
 
32
+ # Narrowed remix response from +run()+ where +images+ is guaranteed present.
38
33
  class CompletedRemixImageResponse < CompletedTextToImageResponse
39
34
  end
40
35
  end
data/lib/runapi/flux_2.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "runapi/core"
4
4
  require_relative "flux_2/types"
5
+ require_relative "flux_2/contract_gen"
5
6
  require_relative "flux_2/resources/text_to_image"
6
7
  require_relative "flux_2/resources/remix_image"
7
8
  require_relative "flux_2/client"
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.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 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.
25
+ version: 0.2.7
26
+ description: The Flux 2 Ruby SDK is the language-specific package for Flux 2 on RunAPI.
27
+ Use this package for image generation, image editing, and creative production workflows
28
+ when your application needs request bodies, task status lookup, and consistent RunAPI
29
+ errors in Ruby.
30
30
  email:
31
31
  - contact@runapi.ai
32
32
  executables: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/runapi-flux_2.rb
40
40
  - lib/runapi/flux_2.rb
41
41
  - lib/runapi/flux_2/client.rb
42
+ - lib/runapi/flux_2/contract_gen.rb
42
43
  - lib/runapi/flux_2/resources/remix_image.rb
43
44
  - lib/runapi/flux_2/resources/text_to_image.rb
44
45
  - lib/runapi/flux_2/types.rb
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/flux-2
46
47
  licenses:
47
48
  - Apache-2.0
48
49
  metadata:
50
+ runapi_slug: flux-2
49
51
  homepage_uri: https://runapi.ai/models/flux-2
50
52
  documentation_uri: https://github.com/runapi-ai/flux-2-sdk/blob/main/ruby/README.md
51
53
  source_code_uri: https://github.com/runapi-ai/flux-2-sdk
54
+ bug_tracker_uri: https://github.com/runapi-ai/flux-2-sdk/issues
52
55
  changelog_uri: https://github.com/runapi-ai/flux-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: Flux API Ruby SDK for RunAPI
72
+ summary: Flux 2 API Ruby SDK for RunAPI
70
73
  test_files: []