runapi-flux 0.1.0__tar.gz

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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 RunAPI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: runapi-flux
3
+ Version: 0.1.0
4
+ Summary: RunAPI Flux SDK for image generation and editing in JavaScript, Python, Ruby, Go, Java, and PHP
5
+ Project-URL: Homepage, https://runapi.ai/models/flux
6
+ Project-URL: Documentation, https://runapi.ai/docs#sdk-flux
7
+ Project-URL: Source, https://github.com/runapi-ai/flux-sdk
8
+ Project-URL: Issues, https://github.com/runapi-ai/flux-sdk/issues
9
+ Project-URL: Changelog, https://github.com/runapi-ai/flux-sdk/blob/main/CHANGELOG.md
10
+ Project-URL: Release Notes, https://github.com/runapi-ai/flux-sdk/releases/tag/python%2Fv0.1.0
11
+ Author-email: RunAPI <contact@runapi.ai>
12
+ License-Expression: Apache-2.0
13
+ License-File: LICENSE
14
+ Keywords: api,flux,flux-2-klein,flux-dev,flux-pro,golang,gradle,image-api,image-editing,image-generation,java,maven,python,ruby,runapi,runapi-ai,sdk,text-to-image,typescript
15
+ Requires-Python: >=3.9
16
+ Requires-Dist: runapi-core>=0.2.3
17
+ Description-Content-Type: text/markdown
18
+
19
+ # Flux API Python SDK for RunAPI
20
+
21
+ The Flux Python SDK is the language-specific package for Flux 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 Python.
22
+
23
+ This README is the Python package guide inside the public `flux-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/flux; for API reference, use https://runapi.ai/docs#flux; for SDK docs, use https://runapi.ai/docs#sdk-flux.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install runapi-flux
29
+ ```
30
+
31
+ ## Quick start
32
+
33
+ ```python
34
+ from runapi.flux import FluxClient
35
+
36
+ client = FluxClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
37
+
38
+ task = client.text_to_image.create(
39
+ model="flux-pro",
40
+ prompt="A cinematic product photo on warm paper",
41
+ aspect_ratio="1:1",
42
+ )
43
+ status = client.text_to_image.get(task.id)
44
+
45
+ remix = client.remix_image.create(
46
+ model="flux-pro",
47
+ prompt="Turn this product shot into a warm editorial photo",
48
+ source_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
49
+ aspect_ratio="1:1",
50
+ )
51
+ ```
52
+
53
+ 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:
54
+
55
+ ```python
56
+ result = client.text_to_image.run(
57
+ model="flux-pro",
58
+ prompt="A futuristic cityscape at dusk",
59
+ )
60
+ print(result.images[0].url)
61
+ ```
62
+
63
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
64
+
65
+ 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.
66
+
67
+ ## Language notes
68
+
69
+ Pass parameters as keyword arguments and catch the `runapi.flux` error classes when building image jobs 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.
70
+
71
+ ## Links
72
+
73
+ - Model page: https://runapi.ai/models/flux
74
+ - SDK docs: https://runapi.ai/docs#sdk-flux
75
+ - Product docs: https://runapi.ai/docs#flux
76
+ - Pricing and rate limits: https://runapi.ai/models/flux/dev
77
+ - Provider comparison: https://runapi.ai/providers/black-forest-labs
78
+ - Full catalog: https://runapi.ai/models
79
+ - Repository: https://github.com/runapi-ai/flux-sdk
80
+
81
+ ## License
82
+
83
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,65 @@
1
+ # Flux API Python SDK for RunAPI
2
+
3
+ The Flux Python SDK is the language-specific package for Flux 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 Python.
4
+
5
+ This README is the Python package guide inside the public `flux-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/flux; for API reference, use https://runapi.ai/docs#flux; for SDK docs, use https://runapi.ai/docs#sdk-flux.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install runapi-flux
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```python
16
+ from runapi.flux import FluxClient
17
+
18
+ client = FluxClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
19
+
20
+ task = client.text_to_image.create(
21
+ model="flux-pro",
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-pro",
29
+ prompt="Turn this product shot into a warm editorial photo",
30
+ source_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
31
+ aspect_ratio="1:1",
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:
36
+
37
+ ```python
38
+ result = client.text_to_image.run(
39
+ model="flux-pro",
40
+ prompt="A futuristic cityscape at dusk",
41
+ )
42
+ print(result.images[0].url)
43
+ ```
44
+
45
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
46
+
47
+ 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.
48
+
49
+ ## Language notes
50
+
51
+ Pass parameters as keyword arguments and catch the `runapi.flux` error classes when building image jobs 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.
52
+
53
+ ## Links
54
+
55
+ - Model page: https://runapi.ai/models/flux
56
+ - SDK docs: https://runapi.ai/docs#sdk-flux
57
+ - Product docs: https://runapi.ai/docs#flux
58
+ - Pricing and rate limits: https://runapi.ai/models/flux/dev
59
+ - Provider comparison: https://runapi.ai/providers/black-forest-labs
60
+ - Full catalog: https://runapi.ai/models
61
+ - Repository: https://github.com/runapi-ai/flux-sdk
62
+
63
+ ## License
64
+
65
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "runapi-flux"
7
+ version = "0.1.0"
8
+ description = "RunAPI Flux SDK for image generation and editing in JavaScript, Python, Ruby, Go, Java, and PHP"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
13
+ keywords = ["runapi", "runapi-ai", "flux", "flux-dev", "flux-pro", "flux-2-klein", "api", "sdk", "typescript", "python", "ruby", "golang", "java", "maven", "gradle", "image-generation", "image-editing", "text-to-image", "image-api"]
14
+ dependencies = ["runapi-core>=0.2.3"]
15
+
16
+ [project.urls]
17
+ Homepage = "https://runapi.ai/models/flux"
18
+ Documentation = "https://runapi.ai/docs#sdk-flux"
19
+ Source = "https://github.com/runapi-ai/flux-sdk"
20
+ Issues = "https://github.com/runapi-ai/flux-sdk/issues"
21
+ Changelog = "https://github.com/runapi-ai/flux-sdk/blob/main/CHANGELOG.md"
22
+ "Release Notes" = "https://github.com/runapi-ai/flux-sdk/releases/tag/python%2Fv0.1.0"
23
+
24
+ [tool.hatch.build.targets.wheel]
25
+ packages = ["src/runapi"]
26
+
27
+ [tool.uv]
28
+ package = true
29
+
30
+ [dependency-groups]
31
+ dev = ["pytest>=8"]
32
+
33
+ [tool.runapi]
34
+ slug = "flux"
@@ -0,0 +1,24 @@
1
+ """Flux client for RunAPI."""
2
+
3
+ from runapi.core import (
4
+ AuthenticationError,
5
+ InsufficientCreditsError,
6
+ NotFoundError,
7
+ RateLimitError,
8
+ TaskFailedError,
9
+ TaskTimeoutError,
10
+ ValidationError,
11
+ )
12
+
13
+ from .client import FluxClient
14
+
15
+ __all__ = [
16
+ "FluxClient",
17
+ "AuthenticationError",
18
+ "RateLimitError",
19
+ "InsufficientCreditsError",
20
+ "NotFoundError",
21
+ "ValidationError",
22
+ "TaskFailedError",
23
+ "TaskTimeoutError",
24
+ ]
@@ -0,0 +1,21 @@
1
+ """Flux client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import ClientOptions, HttpClient, resolve_api_key
8
+
9
+ from .resources.remix_image import RemixImage
10
+ from .resources.text_to_image import TextToImage
11
+
12
+
13
+ class FluxClient:
14
+ """Flux image generation and editing client."""
15
+
16
+ def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
17
+ resolved_api_key = resolve_api_key(api_key)
18
+ client_options = ClientOptions(api_key=resolved_api_key, **options)
19
+ http = client_options.http_client or HttpClient(client_options)
20
+ self.text_to_image = TextToImage(http)
21
+ self.remix_image = RemixImage(http)
@@ -0,0 +1,93 @@
1
+ CONTRACT = {
2
+ "remix-image": {
3
+ "models": ["flux-dev", "flux-pro"],
4
+ "fields_by_model": {
5
+ "flux-dev": {
6
+ "aspect_ratio": {
7
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
8
+ },
9
+ "output_count": {
10
+ "enum": [1],
11
+ "type": "integer"
12
+ },
13
+ "prompt": {
14
+ "required": True,
15
+ "min": 3,
16
+ "max": 5000,
17
+ "length": True
18
+ },
19
+ "source_image_url": {
20
+ "required": True
21
+ }
22
+ },
23
+ "flux-pro": {
24
+ "aspect_ratio": {
25
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
26
+ },
27
+ "output_count": {
28
+ "enum": [1],
29
+ "type": "integer"
30
+ },
31
+ "prompt": {
32
+ "required": True,
33
+ "min": 3,
34
+ "max": 5000,
35
+ "length": True
36
+ },
37
+ "source_image_url": {
38
+ "required": True
39
+ }
40
+ }
41
+ }
42
+ },
43
+ "text-to-image": {
44
+ "models": ["flux-2-klein", "flux-dev", "flux-pro"],
45
+ "fields_by_model": {
46
+ "flux-2-klein": {
47
+ "aspect_ratio": {
48
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
49
+ },
50
+ "output_count": {
51
+ "enum": [1],
52
+ "type": "integer"
53
+ },
54
+ "prompt": {
55
+ "required": True,
56
+ "min": 3,
57
+ "max": 5000,
58
+ "length": True
59
+ }
60
+ },
61
+ "flux-dev": {
62
+ "aspect_ratio": {
63
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
64
+ },
65
+ "output_count": {
66
+ "enum": [1],
67
+ "type": "integer"
68
+ },
69
+ "prompt": {
70
+ "required": True,
71
+ "min": 3,
72
+ "max": 5000,
73
+ "length": True
74
+ }
75
+ },
76
+ "flux-pro": {
77
+ "aspect_ratio": {
78
+ "enum": ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"]
79
+ },
80
+ "output_count": {
81
+ "enum": [1],
82
+ "type": "integer"
83
+ },
84
+ "prompt": {
85
+ "required": True,
86
+ "min": 3,
87
+ "max": 5000,
88
+ "length": True
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ from .remix_image import RemixImage
2
+ from .text_to_image import TextToImage
3
+
4
+ __all__ = ["RemixImage", "TextToImage"]
@@ -0,0 +1,28 @@
1
+ """Flux prompt-guided image editing resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import RequestOptions, Resource
8
+
9
+ from ..contract_gen import CONTRACT
10
+ from ..types import CompletedRemixImageResponse, RemixImageResponse
11
+
12
+
13
+ class RemixImage(Resource):
14
+ ENDPOINT = "/api/v1/flux/remix_image"
15
+ RESPONSE_CLASS = RemixImageResponse
16
+ COMPLETED_RESPONSE_CLASS = CompletedRemixImageResponse
17
+
18
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
19
+ task = self.create(options=options, **params)
20
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
21
+
22
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
23
+ compacted = self._compact_params(params)
24
+ self._validate_contract(CONTRACT["remix-image"], compacted)
25
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
26
+
27
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
28
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
@@ -0,0 +1,28 @@
1
+ """Flux text-to-image resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import RequestOptions, Resource
8
+
9
+ from ..contract_gen import CONTRACT
10
+ from ..types import CompletedTextToImageResponse, TextToImageResponse
11
+
12
+
13
+ class TextToImage(Resource):
14
+ ENDPOINT = "/api/v1/flux/text_to_image"
15
+ RESPONSE_CLASS = TextToImageResponse
16
+ COMPLETED_RESPONSE_CLASS = CompletedTextToImageResponse
17
+
18
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
19
+ task = self.create(options=options, **params)
20
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
21
+
22
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
23
+ compacted = self._compact_params(params)
24
+ self._validate_contract(CONTRACT["text-to-image"], compacted)
25
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
26
+
27
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
28
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
@@ -0,0 +1,26 @@
1
+ """Flux response models."""
2
+
3
+ from runapi.core import BaseModel, TaskResponse, optional, required
4
+
5
+
6
+ class Image(BaseModel):
7
+ url = optional(str)
8
+
9
+
10
+ class TextToImageResponse(TaskResponse):
11
+ id = required(str)
12
+ status = optional(str, enum=lambda: TaskResponse.Status.ALL)
13
+ images = optional([lambda: Image])
14
+ error = optional(str)
15
+
16
+
17
+ class CompletedTextToImageResponse(TextToImageResponse):
18
+ images = required([lambda: Image])
19
+
20
+
21
+ class RemixImageResponse(TextToImageResponse):
22
+ pass
23
+
24
+
25
+ class CompletedRemixImageResponse(CompletedTextToImageResponse):
26
+ pass
@@ -0,0 +1,85 @@
1
+ import pytest
2
+
3
+ from runapi.core.errors import ValidationError
4
+ from runapi.flux import FluxClient
5
+ from runapi.flux.types import RemixImageResponse, TextToImageResponse
6
+
7
+
8
+ class FakeHttp:
9
+ def __init__(self, *responses):
10
+ self._responses = list(responses)
11
+ self.calls = []
12
+
13
+ def request(self, method, path, body=None, options=None):
14
+ self.calls.append((method, path, body))
15
+ if self._responses:
16
+ return self._responses.pop(0)
17
+ return {"id": "task-1186", "status": "processing"}
18
+
19
+
20
+ def test_exposes_resources_and_posts_flat_generation_params():
21
+ http = FakeHttp({"id": "task-1186", "status": "processing"})
22
+ client = FluxClient(api_key="test-key", http_client=http)
23
+
24
+ result = client.text_to_image.create(
25
+ model="flux-dev",
26
+ prompt="A studio product photograph",
27
+ aspect_ratio="16:9",
28
+ output_count=1,
29
+ )
30
+
31
+ assert isinstance(result, TextToImageResponse)
32
+ assert http.calls == [(
33
+ "post",
34
+ "/api/v1/flux/text_to_image",
35
+ {"model": "flux-dev", "prompt": "A studio product photograph", "aspect_ratio": "16:9", "output_count": 1},
36
+ )]
37
+
38
+
39
+ def test_posts_one_source_image_and_uses_public_lookup_path():
40
+ http = FakeHttp(
41
+ {"id": "task-1186", "status": "processing"},
42
+ {"id": "task-1186", "status": "completed", "images": [{"url": "https://cdn.runapi.ai/public/samples/result.jpg"}]},
43
+ )
44
+ client = FluxClient(api_key="test-key", http_client=http)
45
+
46
+ created = client.remix_image.create(
47
+ model="flux-pro",
48
+ prompt="Replace the background",
49
+ source_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
50
+ )
51
+ result = client.remix_image.get(created.id)
52
+
53
+ assert isinstance(result, RemixImageResponse)
54
+ assert http.calls[0] == (
55
+ "post",
56
+ "/api/v1/flux/remix_image",
57
+ {
58
+ "model": "flux-pro",
59
+ "prompt": "Replace the background",
60
+ "source_image_url": "https://cdn.runapi.ai/public/samples/image.jpg",
61
+ },
62
+ )
63
+ assert http.calls[1] == ("get", "/api/v1/flux/remix_image/task-1186", None)
64
+
65
+
66
+ @pytest.mark.parametrize(
67
+ ("resource", "params", "message"),
68
+ [
69
+ ("text_to_image", {"model": "flux-2-klein", "prompt": "A product photo", "output_count": 2}, "output_count must be one of"),
70
+ (
71
+ "remix_image",
72
+ {
73
+ "model": "flux-dev",
74
+ "prompt": "Replace the background",
75
+ "source_image_url": None,
76
+ },
77
+ "source_image_url is required",
78
+ ),
79
+ ],
80
+ )
81
+ def test_generated_contract_rejects_unsupported_shapes(resource, params, message):
82
+ client = FluxClient(api_key="test-key", http_client=FakeHttp())
83
+
84
+ with pytest.raises(ValidationError, match=message):
85
+ getattr(client, resource).create(**params)