@runapi.ai/flux-kontext 0.2.0
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.
- package/LICENSE +201 -0
- package/README.md +43 -0
- package/dist/index.d.mts +75 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +72 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
- package/skills/flux-kontext/README.md +52 -0
- package/skills/flux-kontext/SKILL.md +175 -0
package/LICENSE
ADDED
|
@@ -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 [yyyy] [name of copyright owner]
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Flux Kontext API JavaScript SDK for RunAPI
|
|
2
|
+
|
|
3
|
+
The flux kontext api JavaScript SDK is the language-specific package for Flux Kontext on RunAPI. Use this flux kontext api package for text-to-image, image-to-image, edit, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in JavaScript.
|
|
4
|
+
|
|
5
|
+
This flux kontext api README is the JavaScript package guide inside the public `flux-kontext-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/flux-kontext; for API reference, use https://runapi.ai/docs#flux-kontext; for SDK docs, use https://runapi.ai/docs#sdk-flux-kontext.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @runapi.ai/flux-kontext
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { FluxKontextClient } from '@runapi.ai/flux-kontext';
|
|
17
|
+
|
|
18
|
+
const client = new FluxKontextClient();
|
|
19
|
+
const task = await client.generations.create({
|
|
20
|
+
// Pass the Flux Kontext JSON request body from https://runapi.ai/docs#flux-kontext.
|
|
21
|
+
});
|
|
22
|
+
const status = await client.generations.get(task.id);
|
|
23
|
+
```
|
|
24
|
+
|
|
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
|
+
|
|
27
|
+
## Language notes
|
|
28
|
+
|
|
29
|
+
Use the TypeScript types in `src/types.ts` and the resource classes under `src/resources` when building image applications. The available resources include generations. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
|
|
30
|
+
|
|
31
|
+
## Links
|
|
32
|
+
|
|
33
|
+
- Model page: https://runapi.ai/models/flux-kontext
|
|
34
|
+
- SDK docs: https://runapi.ai/docs#sdk-flux-kontext
|
|
35
|
+
- Product docs: https://runapi.ai/docs#flux-kontext
|
|
36
|
+
- Pricing and rate limits: https://runapi.ai/models/flux-kontext/pro
|
|
37
|
+
- Provider comparison: https://runapi.ai/providers/black-forest-labs
|
|
38
|
+
- Full catalog: https://runapi.ai/models
|
|
39
|
+
- Repository: https://github.com/runapi-ai/flux-kontext-sdk
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
Licensed under the Apache License, Version 2.0.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AsyncTaskStatus, HttpClient, RequestOptions, PollingOptions, ClientOptions } from '@runapi.ai/core';
|
|
2
|
+
export { AuthenticationError, InsufficientCreditsError, NetworkError, NotFoundError, RateLimitError, RunApiError, ServiceUnavailableError, TaskFailedError, TaskTimeoutError, TimeoutError, ValidationError } from '@runapi.ai/core';
|
|
3
|
+
|
|
4
|
+
type FluxKontextModel = 'flux-kontext-pro' | 'flux-kontext-max';
|
|
5
|
+
type AspectRatio = '21:9' | '16:9' | '4:3' | '1:1' | '3:4' | '9:16';
|
|
6
|
+
type OutputFormat = 'jpeg' | 'png';
|
|
7
|
+
interface TextToImageParams {
|
|
8
|
+
model: FluxKontextModel;
|
|
9
|
+
prompt: string;
|
|
10
|
+
callback_url?: string;
|
|
11
|
+
aspect_ratio?: AspectRatio;
|
|
12
|
+
output_format?: OutputFormat;
|
|
13
|
+
input_image?: string;
|
|
14
|
+
/** Auto-translate prompt to English (default: true). */
|
|
15
|
+
enable_translation?: boolean;
|
|
16
|
+
prompt_upsampling?: boolean;
|
|
17
|
+
safety_tolerance?: number;
|
|
18
|
+
upload_cn?: boolean;
|
|
19
|
+
watermark?: string;
|
|
20
|
+
}
|
|
21
|
+
interface TaskCreateResponse {
|
|
22
|
+
id: string;
|
|
23
|
+
}
|
|
24
|
+
interface Image {
|
|
25
|
+
url: string;
|
|
26
|
+
origin_url?: string;
|
|
27
|
+
}
|
|
28
|
+
interface TextToImageResponse {
|
|
29
|
+
id: string;
|
|
30
|
+
status: AsyncTaskStatus;
|
|
31
|
+
images?: Image[];
|
|
32
|
+
error?: string;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolved response returned by `textToImage.run()` after polling sees
|
|
37
|
+
* `status: 'completed'`. Narrows the base response so `images` is guaranteed
|
|
38
|
+
* non-optional in user code.
|
|
39
|
+
*/
|
|
40
|
+
type CompletedTextToImageResponse = TextToImageResponse & {
|
|
41
|
+
status: 'completed';
|
|
42
|
+
images: Image[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
declare class TextToImage {
|
|
46
|
+
private readonly http;
|
|
47
|
+
constructor(http: HttpClient);
|
|
48
|
+
run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedTextToImageResponse>;
|
|
49
|
+
create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse>;
|
|
50
|
+
get(id: string, options?: RequestOptions): Promise<TextToImageResponse>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Flux Kontext text-to-image API client.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const client = new FluxKontextClient({
|
|
59
|
+
* apiKey: 'your-api-key',
|
|
60
|
+
* baseUrl: 'https://runapi.ai',
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* const result = await client.textToImage.run({
|
|
64
|
+
* model: 'flux-kontext-pro',
|
|
65
|
+
* prompt: 'A futuristic cityscape at night',
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare class FluxKontextClient {
|
|
70
|
+
/** Text-to-image operations. */
|
|
71
|
+
readonly textToImage: TextToImage;
|
|
72
|
+
constructor(options?: ClientOptions);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { type AspectRatio, type CompletedTextToImageResponse, FluxKontextClient, type FluxKontextModel, type Image, type OutputFormat, type TaskCreateResponse, type TextToImageParams, type TextToImageResponse };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AsyncTaskStatus, HttpClient, RequestOptions, PollingOptions, ClientOptions } from '@runapi.ai/core';
|
|
2
|
+
export { AuthenticationError, InsufficientCreditsError, NetworkError, NotFoundError, RateLimitError, RunApiError, ServiceUnavailableError, TaskFailedError, TaskTimeoutError, TimeoutError, ValidationError } from '@runapi.ai/core';
|
|
3
|
+
|
|
4
|
+
type FluxKontextModel = 'flux-kontext-pro' | 'flux-kontext-max';
|
|
5
|
+
type AspectRatio = '21:9' | '16:9' | '4:3' | '1:1' | '3:4' | '9:16';
|
|
6
|
+
type OutputFormat = 'jpeg' | 'png';
|
|
7
|
+
interface TextToImageParams {
|
|
8
|
+
model: FluxKontextModel;
|
|
9
|
+
prompt: string;
|
|
10
|
+
callback_url?: string;
|
|
11
|
+
aspect_ratio?: AspectRatio;
|
|
12
|
+
output_format?: OutputFormat;
|
|
13
|
+
input_image?: string;
|
|
14
|
+
/** Auto-translate prompt to English (default: true). */
|
|
15
|
+
enable_translation?: boolean;
|
|
16
|
+
prompt_upsampling?: boolean;
|
|
17
|
+
safety_tolerance?: number;
|
|
18
|
+
upload_cn?: boolean;
|
|
19
|
+
watermark?: string;
|
|
20
|
+
}
|
|
21
|
+
interface TaskCreateResponse {
|
|
22
|
+
id: string;
|
|
23
|
+
}
|
|
24
|
+
interface Image {
|
|
25
|
+
url: string;
|
|
26
|
+
origin_url?: string;
|
|
27
|
+
}
|
|
28
|
+
interface TextToImageResponse {
|
|
29
|
+
id: string;
|
|
30
|
+
status: AsyncTaskStatus;
|
|
31
|
+
images?: Image[];
|
|
32
|
+
error?: string;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolved response returned by `textToImage.run()` after polling sees
|
|
37
|
+
* `status: 'completed'`. Narrows the base response so `images` is guaranteed
|
|
38
|
+
* non-optional in user code.
|
|
39
|
+
*/
|
|
40
|
+
type CompletedTextToImageResponse = TextToImageResponse & {
|
|
41
|
+
status: 'completed';
|
|
42
|
+
images: Image[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
declare class TextToImage {
|
|
46
|
+
private readonly http;
|
|
47
|
+
constructor(http: HttpClient);
|
|
48
|
+
run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedTextToImageResponse>;
|
|
49
|
+
create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse>;
|
|
50
|
+
get(id: string, options?: RequestOptions): Promise<TextToImageResponse>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Flux Kontext text-to-image API client.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const client = new FluxKontextClient({
|
|
59
|
+
* apiKey: 'your-api-key',
|
|
60
|
+
* baseUrl: 'https://runapi.ai',
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* const result = await client.textToImage.run({
|
|
64
|
+
* model: 'flux-kontext-pro',
|
|
65
|
+
* prompt: 'A futuristic cityscape at night',
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare class FluxKontextClient {
|
|
70
|
+
/** Text-to-image operations. */
|
|
71
|
+
readonly textToImage: TextToImage;
|
|
72
|
+
constructor(options?: ClientOptions);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { type AspectRatio, type CompletedTextToImageResponse, FluxKontextClient, type FluxKontextModel, type Image, type OutputFormat, type TaskCreateResponse, type TextToImageParams, type TextToImageResponse };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AuthenticationError: () => import_core3.AuthenticationError,
|
|
24
|
+
FluxKontextClient: () => FluxKontextClient,
|
|
25
|
+
InsufficientCreditsError: () => import_core3.InsufficientCreditsError,
|
|
26
|
+
NetworkError: () => import_core3.NetworkError,
|
|
27
|
+
NotFoundError: () => import_core3.NotFoundError,
|
|
28
|
+
RateLimitError: () => import_core3.RateLimitError,
|
|
29
|
+
RunApiError: () => import_core3.RunApiError,
|
|
30
|
+
ServiceUnavailableError: () => import_core3.ServiceUnavailableError,
|
|
31
|
+
TaskFailedError: () => import_core3.TaskFailedError,
|
|
32
|
+
TaskTimeoutError: () => import_core3.TaskTimeoutError,
|
|
33
|
+
TimeoutError: () => import_core3.TimeoutError,
|
|
34
|
+
ValidationError: () => import_core3.ValidationError
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/client.ts
|
|
39
|
+
var import_core2 = require("@runapi.ai/core");
|
|
40
|
+
|
|
41
|
+
// src/resources/text-to-image.ts
|
|
42
|
+
var import_core = require("@runapi.ai/core");
|
|
43
|
+
var import_internal = require("@runapi.ai/core/internal");
|
|
44
|
+
var ENDPOINT = "/api/v1/flux_kontext/text_to_image";
|
|
45
|
+
var TextToImage = class {
|
|
46
|
+
constructor(http) {
|
|
47
|
+
this.http = http;
|
|
48
|
+
}
|
|
49
|
+
http;
|
|
50
|
+
async run(params, options) {
|
|
51
|
+
const { id } = await this.create(params, options);
|
|
52
|
+
const response = await (0, import_internal.pollUntilComplete)(() => this.get(id, options), {
|
|
53
|
+
maxWaitMs: options?.maxWaitMs,
|
|
54
|
+
pollIntervalMs: options?.pollIntervalMs
|
|
55
|
+
});
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
async create(params, options) {
|
|
59
|
+
return this.http.request("POST", ENDPOINT, {
|
|
60
|
+
body: (0, import_core.compactParams)(params),
|
|
61
|
+
...options
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async get(id, options) {
|
|
65
|
+
return this.http.request("GET", `${ENDPOINT}/${id}`, {
|
|
66
|
+
...options
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/client.ts
|
|
72
|
+
var FluxKontextClient = class {
|
|
73
|
+
/** Text-to-image operations. */
|
|
74
|
+
textToImage;
|
|
75
|
+
constructor(options = {}) {
|
|
76
|
+
const http = (0, import_core2.createHttpClient)(options);
|
|
77
|
+
this.textToImage = new TextToImage(http);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/index.ts
|
|
82
|
+
var import_core3 = require("@runapi.ai/core");
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
AuthenticationError,
|
|
86
|
+
FluxKontextClient,
|
|
87
|
+
InsufficientCreditsError,
|
|
88
|
+
NetworkError,
|
|
89
|
+
NotFoundError,
|
|
90
|
+
RateLimitError,
|
|
91
|
+
RunApiError,
|
|
92
|
+
ServiceUnavailableError,
|
|
93
|
+
TaskFailedError,
|
|
94
|
+
TaskTimeoutError,
|
|
95
|
+
TimeoutError,
|
|
96
|
+
ValidationError
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/resources/text-to-image.ts"],"sourcesContent":["export { FluxKontextClient } from './client';\nexport * from './types';\n\n// Re-export core errors for convenience\nexport {\n RunApiError,\n AuthenticationError,\n InsufficientCreditsError,\n NotFoundError,\n ValidationError,\n RateLimitError,\n ServiceUnavailableError,\n NetworkError,\n TimeoutError,\n TaskTimeoutError,\n TaskFailedError,\n} from '@runapi.ai/core';\n","import { createHttpClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\n\n/**\n * Flux Kontext text-to-image API client.\n *\n * @example\n * ```typescript\n * const client = new FluxKontextClient({\n * apiKey: 'your-api-key',\n * baseUrl: 'https://runapi.ai',\n * });\n *\n * const result = await client.textToImage.run({\n * model: 'flux-kontext-pro',\n * prompt: 'A futuristic cityscape at night',\n * });\n * ```\n */\nexport class FluxKontextClient {\n /** Text-to-image operations. */\n public readonly textToImage: TextToImage;\n\n constructor(options: ClientOptions = {}) {\n const http = createHttpClient(options);\n this.textToImage = new TextToImage(http);\n }\n}\n","import type { HttpClient, RequestOptions, PollingOptions } from '@runapi.ai/core';\nimport { compactParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport type {\n CompletedTextToImageResponse,\n TextToImageParams,\n TextToImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_kontext/text_to_image';\n\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n async run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedTextToImageResponse> {\n const { id } = await this.create(params, options);\n const response = await pollUntilComplete<TextToImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n return response as CompletedTextToImageResponse;\n }\n\n async create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body: compactParams(params),\n ...options,\n });\n }\n\n async get(id: string, options?: RequestOptions): Promise<TextToImageResponse> {\n return this.http.request<TextToImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAAqD;;;ACCrD,kBAA8B;AAC9B,sBAAkC;AAQlC,IAAM,WAAW;AAEV,IAAM,cAAN,MAAkB;AAAA,EACvB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA,EAE7B,MAAM,IAAI,QAA2B,SAAkF;AACrH,UAAM,EAAE,GAAG,IAAI,MAAM,KAAK,OAAO,QAAQ,OAAO;AAChD,UAAM,WAAW,UAAM,mCAAuC,MAAM,KAAK,IAAI,IAAI,OAAO,GAAG;AAAA,MACzF,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,IAC3B,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAO,QAA2B,SAAuD;AAC7F,WAAO,KAAK,KAAK,QAA4B,QAAQ,UAAU;AAAA,MAC7D,UAAM,2BAAc,MAAM;AAAA,MAC1B,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,IAAY,SAAwD;AAC5E,WAAO,KAAK,KAAK,QAA6B,OAAO,GAAG,QAAQ,IAAI,EAAE,IAAI;AAAA,MACxE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;ADjBO,IAAM,oBAAN,MAAwB;AAAA;AAAA,EAEb;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,WAAO,+BAAiB,OAAO;AACrC,SAAK,cAAc,IAAI,YAAY,IAAI;AAAA,EACzC;AACF;;;ADvBA,IAAAC,eAYO;","names":["import_core","import_core"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { createHttpClient } from "@runapi.ai/core";
|
|
3
|
+
|
|
4
|
+
// src/resources/text-to-image.ts
|
|
5
|
+
import { compactParams } from "@runapi.ai/core";
|
|
6
|
+
import { pollUntilComplete } from "@runapi.ai/core/internal";
|
|
7
|
+
var ENDPOINT = "/api/v1/flux_kontext/text_to_image";
|
|
8
|
+
var TextToImage = class {
|
|
9
|
+
constructor(http) {
|
|
10
|
+
this.http = http;
|
|
11
|
+
}
|
|
12
|
+
http;
|
|
13
|
+
async run(params, options) {
|
|
14
|
+
const { id } = await this.create(params, options);
|
|
15
|
+
const response = await pollUntilComplete(() => this.get(id, options), {
|
|
16
|
+
maxWaitMs: options?.maxWaitMs,
|
|
17
|
+
pollIntervalMs: options?.pollIntervalMs
|
|
18
|
+
});
|
|
19
|
+
return response;
|
|
20
|
+
}
|
|
21
|
+
async create(params, options) {
|
|
22
|
+
return this.http.request("POST", ENDPOINT, {
|
|
23
|
+
body: compactParams(params),
|
|
24
|
+
...options
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async get(id, options) {
|
|
28
|
+
return this.http.request("GET", `${ENDPOINT}/${id}`, {
|
|
29
|
+
...options
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/client.ts
|
|
35
|
+
var FluxKontextClient = class {
|
|
36
|
+
/** Text-to-image operations. */
|
|
37
|
+
textToImage;
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
const http = createHttpClient(options);
|
|
40
|
+
this.textToImage = new TextToImage(http);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// src/index.ts
|
|
45
|
+
import {
|
|
46
|
+
RunApiError,
|
|
47
|
+
AuthenticationError,
|
|
48
|
+
InsufficientCreditsError,
|
|
49
|
+
NotFoundError,
|
|
50
|
+
ValidationError,
|
|
51
|
+
RateLimitError,
|
|
52
|
+
ServiceUnavailableError,
|
|
53
|
+
NetworkError,
|
|
54
|
+
TimeoutError,
|
|
55
|
+
TaskTimeoutError,
|
|
56
|
+
TaskFailedError
|
|
57
|
+
} from "@runapi.ai/core";
|
|
58
|
+
export {
|
|
59
|
+
AuthenticationError,
|
|
60
|
+
FluxKontextClient,
|
|
61
|
+
InsufficientCreditsError,
|
|
62
|
+
NetworkError,
|
|
63
|
+
NotFoundError,
|
|
64
|
+
RateLimitError,
|
|
65
|
+
RunApiError,
|
|
66
|
+
ServiceUnavailableError,
|
|
67
|
+
TaskFailedError,
|
|
68
|
+
TaskTimeoutError,
|
|
69
|
+
TimeoutError,
|
|
70
|
+
ValidationError
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/resources/text-to-image.ts","../src/index.ts"],"sourcesContent":["import { createHttpClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\n\n/**\n * Flux Kontext text-to-image API client.\n *\n * @example\n * ```typescript\n * const client = new FluxKontextClient({\n * apiKey: 'your-api-key',\n * baseUrl: 'https://runapi.ai',\n * });\n *\n * const result = await client.textToImage.run({\n * model: 'flux-kontext-pro',\n * prompt: 'A futuristic cityscape at night',\n * });\n * ```\n */\nexport class FluxKontextClient {\n /** Text-to-image operations. */\n public readonly textToImage: TextToImage;\n\n constructor(options: ClientOptions = {}) {\n const http = createHttpClient(options);\n this.textToImage = new TextToImage(http);\n }\n}\n","import type { HttpClient, RequestOptions, PollingOptions } from '@runapi.ai/core';\nimport { compactParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport type {\n CompletedTextToImageResponse,\n TextToImageParams,\n TextToImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_kontext/text_to_image';\n\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n async run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedTextToImageResponse> {\n const { id } = await this.create(params, options);\n const response = await pollUntilComplete<TextToImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n return response as CompletedTextToImageResponse;\n }\n\n async create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body: compactParams(params),\n ...options,\n });\n }\n\n async get(id: string, options?: RequestOptions): Promise<TextToImageResponse> {\n return this.http.request<TextToImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n","export { FluxKontextClient } from './client';\nexport * from './types';\n\n// Re-export core errors for convenience\nexport {\n RunApiError,\n AuthenticationError,\n InsufficientCreditsError,\n NotFoundError,\n ValidationError,\n RateLimitError,\n ServiceUnavailableError,\n NetworkError,\n TimeoutError,\n TaskTimeoutError,\n TaskFailedError,\n} from '@runapi.ai/core';\n"],"mappings":";AAAA,SAAS,wBAA4C;;;ACCrD,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAQlC,IAAM,WAAW;AAEV,IAAM,cAAN,MAAkB;AAAA,EACvB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA,EAE7B,MAAM,IAAI,QAA2B,SAAkF;AACrH,UAAM,EAAE,GAAG,IAAI,MAAM,KAAK,OAAO,QAAQ,OAAO;AAChD,UAAM,WAAW,MAAM,kBAAuC,MAAM,KAAK,IAAI,IAAI,OAAO,GAAG;AAAA,MACzF,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,IAC3B,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAO,QAA2B,SAAuD;AAC7F,WAAO,KAAK,KAAK,QAA4B,QAAQ,UAAU;AAAA,MAC7D,MAAM,cAAc,MAAM;AAAA,MAC1B,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,IAAY,SAAwD;AAC5E,WAAO,KAAK,KAAK,QAA6B,OAAO,GAAG,QAAQ,IAAI,EAAE,IAAI;AAAA,MACxE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;ADjBO,IAAM,oBAAN,MAAwB;AAAA;AAAA,EAEb;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,OAAO,iBAAiB,OAAO;AACrC,SAAK,cAAc,IAAI,YAAY,IAAI;AAAA,EACzC;AACF;;;AEvBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@runapi.ai/flux-kontext",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "RunAPI Flux Kontext SDK for JavaScript, Ruby, and Go",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"skills",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18.0.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"clean": "rm -rf dist"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@runapi.ai/core": "^0.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^20.0.0",
|
|
35
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"typescript": "^5.4.0",
|
|
38
|
+
"vitest": "^1.6.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"runapi",
|
|
45
|
+
"runapi-ai",
|
|
46
|
+
"flux-kontext",
|
|
47
|
+
"api",
|
|
48
|
+
"sdk",
|
|
49
|
+
"typescript",
|
|
50
|
+
"ruby",
|
|
51
|
+
"golang"
|
|
52
|
+
],
|
|
53
|
+
"author": "RunAPI",
|
|
54
|
+
"license": "Apache-2.0",
|
|
55
|
+
"homepage": "https://runapi.ai/models/flux-kontext",
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "git+https://github.com/runapi-ai/flux-kontext-sdk.git"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Flux Kontext API Skill for RunAPI
|
|
2
|
+
|
|
3
|
+
Generate and transform images with Flux Kontext Pro and Max. This skill helps Claude Code, Codex, Gemini CLI, Cursor, and 50+ agents integrate Flux Kontext through RunAPI.
|
|
4
|
+
|
|
5
|
+
The canonical agent file is `skills/flux-kontext/SKILL.md`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx skills add runapi-ai/flux-kontext -g
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or manually: clone this repo and copy `skills/flux-kontext/` into your agent's skills directory.
|
|
14
|
+
|
|
15
|
+
## Quick example
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { FluxKontextClient } from '@runapi.ai/flux-kontext';
|
|
19
|
+
|
|
20
|
+
const client = new FluxKontextClient();
|
|
21
|
+
const result = await client.textToImage.run({
|
|
22
|
+
model: 'flux-kontext-pro',
|
|
23
|
+
prompt: 'A futuristic cityscape at night',
|
|
24
|
+
aspect_ratio: '16:9',
|
|
25
|
+
});
|
|
26
|
+
const url = result.images[0].url;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Routing
|
|
30
|
+
|
|
31
|
+
- Model page: https://runapi.ai/models/flux-kontext
|
|
32
|
+
- Product docs: https://runapi.ai/docs#flux-kontext
|
|
33
|
+
- SDK docs: https://runapi.ai/docs#sdk-flux-kontext
|
|
34
|
+
- SDK repository: https://github.com/runapi-ai/flux-kontext-sdk
|
|
35
|
+
- Pricing and rate limits: https://runapi.ai/models/flux-kontext/pro
|
|
36
|
+
- Provider comparison: https://runapi.ai/providers/black-forest-labs
|
|
37
|
+
- Browse all RunAPI models and skills: https://runapi.ai/models
|
|
38
|
+
|
|
39
|
+
## Variants
|
|
40
|
+
|
|
41
|
+
- [Flux Kontext Pro](https://runapi.ai/models/flux-kontext/pro)
|
|
42
|
+
- [Flux Kontext Max](https://runapi.ai/models/flux-kontext/max)
|
|
43
|
+
|
|
44
|
+
## Agent rules
|
|
45
|
+
|
|
46
|
+
- Keep API keys in `RUNAPI_API_KEY` or RunAPI CLI config; never commit secrets.
|
|
47
|
+
- Prefer `create`, `get`, and `run` JSON passthrough patterns instead of inventing flags for every model parameter.
|
|
48
|
+
- For flux kontext api pricing, rate-limit, and commercial-usage answers, link to the variant page rather than the repository README.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
Licensed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: flux-kontext
|
|
3
|
+
description: Generate images (Flux Kontext Pro / Max text-to-image and image-to-image) through RunAPI.ai using the @runapi.ai/flux-kontext Node/TypeScript SDK. Use when the user asks to add Flux Kontext image generation or writes against @runapi.ai/flux-kontext. Triggers on "flux kontext", "flux-kontext", "image generation", "生成图片", "@runapi.ai/flux-kontext".
|
|
4
|
+
documentation: https://runapi.ai/models/flux-kontext
|
|
5
|
+
provider_page: https://runapi.ai/providers/black-forest-labs
|
|
6
|
+
catalog: https://runapi.ai/models
|
|
7
|
+
---
|
|
8
|
+
# @runapi.ai/flux-kontext — RunAPI.ai Flux Kontext image generation
|
|
9
|
+
|
|
10
|
+
Build Node / TypeScript integrations that generate and transform images through RunAPI.ai.
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
Requires **Node 18+** (global `fetch`).
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @runapi.ai/flux-kontext
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Set your API key in the environment:
|
|
21
|
+
|
|
22
|
+
```dotenv
|
|
23
|
+
# .env
|
|
24
|
+
RUNAPI_API_KEY=runapi_xxx # get one at https://runapi.ai/settings/api_keys
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { FluxKontextClient } from '@runapi.ai/flux-kontext';
|
|
29
|
+
|
|
30
|
+
// The SDK reads RUNAPI_API_KEY from the environment automatically.
|
|
31
|
+
const client = new FluxKontextClient();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Pass `{ apiKey }` explicitly if you manage secrets differently. `baseUrl` defaults to `https://runapi.ai`; override only for local development.
|
|
35
|
+
|
|
36
|
+
## Core recipe — text to image
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const result = await client.textToImage.run({
|
|
40
|
+
model: 'flux-kontext-pro',
|
|
41
|
+
prompt: 'A futuristic cityscape at night',
|
|
42
|
+
aspect_ratio: '16:9',
|
|
43
|
+
output_format: 'jpeg',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const url = result.images[0].url;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`run()` creates the task, auto-polls, and resolves only when the task completes — `images[0].url` is populated on success. On failure it throws `TaskFailedError`; on polling timeout it throws `TaskTimeoutError`. Use `run()` for scripts and short-lived processes. For request handlers, split it:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const { id } = await client.textToImage.create({ model: 'flux-kontext-pro', prompt: '...' });
|
|
53
|
+
// return 202 immediately; fetch later:
|
|
54
|
+
const status = await client.textToImage.get(id);
|
|
55
|
+
if (status.status === 'completed') { /* ... */ }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Do not hold a web worker open waiting on `run()`. Split + webhook is the production pattern.
|
|
59
|
+
|
|
60
|
+
`run()` polls every 2 s for up to 15 min by default. Tune when needed:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
await client.textToImage.run(params, { maxWaitMs: 5 * 60_000, pollIntervalMs: 2_000 });
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If `TaskTimeoutError` fires, the task is still running server-side — resume with `textToImage.get(id)` or finish via webhook.
|
|
67
|
+
|
|
68
|
+
## Image-to-image — edit a source image
|
|
69
|
+
|
|
70
|
+
Pass `input_image` (a single URL) along with your prompt:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
await client.textToImage.run({
|
|
74
|
+
model: 'flux-kontext-max',
|
|
75
|
+
prompt: 'Restyle as a 1970s film photograph',
|
|
76
|
+
input_image: 'https://cdn.example.com/source.jpg',
|
|
77
|
+
aspect_ratio: '4:3',
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Models
|
|
82
|
+
|
|
83
|
+
| `model` | Use case |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `flux-kontext-pro` | Cost-efficient production output. |
|
|
86
|
+
| `flux-kontext-max` | Higher-fidelity variant. |
|
|
87
|
+
|
|
88
|
+
`aspect_ratio` values: `21:9`, `16:9`, `4:3`, `1:1`, `3:4`, `9:16`. `output_format`: `jpeg` / `png`.
|
|
89
|
+
|
|
90
|
+
Exact credit costs per model are shown at https://runapi.ai/pricing and in the dashboard — do not hardcode prices in application code.
|
|
91
|
+
|
|
92
|
+
## Callbacks (webhooks)
|
|
93
|
+
|
|
94
|
+
Pass `callback_url` on `create()` (or any `run()` call) and RunAPI will POST the final payload to you:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
await client.textToImage.create({
|
|
98
|
+
model: 'flux-kontext-pro',
|
|
99
|
+
prompt: '...',
|
|
100
|
+
callback_url: 'https://your.app/webhooks/runapi/flux-kontext',
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Payload shape:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
{ id: string; status: 'completed' | 'failed'; images?: { url: string; origin_url?: string }[]; error?: string }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Always verify the signature before trusting the body.** RunAPI signs every callback with your account's Callback Secret (rotate at `/accounts/callback_secret`). Headers:
|
|
111
|
+
|
|
112
|
+
- `X-Callback-Id` — UUID, store to make handler idempotent
|
|
113
|
+
- `X-Callback-Timestamp` — unix seconds, reject if `|now - ts| > 300`
|
|
114
|
+
- `X-Callback-Signature` — base64 HMAC-SHA256 over `` `${id}.${ts}.${rawBody}` `` using the base64-decoded secret
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import crypto from 'node:crypto';
|
|
118
|
+
|
|
119
|
+
function verify(raw: string, id: string, ts: string, sig: string, secret: string) {
|
|
120
|
+
const key = Buffer.from(secret, 'base64');
|
|
121
|
+
const mac = crypto.createHmac('sha256', key)
|
|
122
|
+
.update(`${id}.${ts}.${raw}`)
|
|
123
|
+
.digest('base64');
|
|
124
|
+
return crypto.timingSafeEqual(Buffer.from(mac), Buffer.from(sig));
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Reply `2xx` within 10s; any non-2xx triggers retries.
|
|
129
|
+
|
|
130
|
+
## Errors
|
|
131
|
+
|
|
132
|
+
All errors are re-exported from `@runapi.ai/core`. Always `instanceof` — never string-match messages.
|
|
133
|
+
|
|
134
|
+
| Error | Status | Action |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `AuthenticationError` | 401 | abort; surface "reconnect your API key" |
|
|
137
|
+
| `InsufficientCreditsError` | 402 | prompt user to top up at runapi.ai/billing |
|
|
138
|
+
| `ValidationError` | 400 / 422 | fix params; do not retry |
|
|
139
|
+
| `RateLimitError` | 429 | sleep `err.retryAfterMs`, then retry |
|
|
140
|
+
| `ServiceUnavailableError` | 503 / 455 | retry with backoff; transient service issue |
|
|
141
|
+
| `TaskFailedError` | — | show `err.details` to user; do not auto-retry |
|
|
142
|
+
| `TaskTimeoutError` | — | re-poll with `textToImage.get(id)` |
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { InsufficientCreditsError, TaskFailedError } from '@runapi.ai/flux-kontext';
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
await client.textToImage.run({ model: 'flux-kontext-pro', prompt: '...' });
|
|
149
|
+
} catch (err) {
|
|
150
|
+
if (err instanceof InsufficientCreditsError) { /* surface top-up CTA */ }
|
|
151
|
+
else if (err instanceof TaskFailedError) { /* show err.details */ }
|
|
152
|
+
else throw err;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Gotchas
|
|
157
|
+
|
|
158
|
+
- `model` is required on every call.
|
|
159
|
+
- `input_image` is a single URL (string), not an array — this is the one endpoint in the family that takes a scalar URL.
|
|
160
|
+
- `enable_translation` defaults to `true` — the prompt is auto-translated to English. Set `false` to keep the raw prompt.
|
|
161
|
+
- `callback_url` must be reachable from the public internet. `localhost` / `127.0.0.1` URLs will never fire — use a tunnel (cloudflared, ngrok, tailscale funnel) when developing locally.
|
|
162
|
+
|
|
163
|
+
## Dig deeper
|
|
164
|
+
|
|
165
|
+
Package README (full API surface, all params): `node_modules/@runapi.ai/flux-kontext/README.md`. Types: `@runapi.ai/flux-kontext/dist/types.d.ts`. Product docs: https://runapi.ai/docs.
|
|
166
|
+
|
|
167
|
+
## RunAPI public routing
|
|
168
|
+
|
|
169
|
+
flux kontext api public links use the API-379 catalog route map. The main flux kontext api page is https://runapi.ai/models/flux-kontext. SDK docs live at https://runapi.ai/docs#sdk-flux-kontext and product docs live at https://runapi.ai/docs#flux-kontext.
|
|
170
|
+
|
|
171
|
+
Pricing, rate limits, and commercial usage for flux kontext api should point to the most specific variant page:
|
|
172
|
+
- [Flux Kontext Pro](https://runapi.ai/models/flux-kontext/pro)
|
|
173
|
+
- [Flux Kontext Max](https://runapi.ai/models/flux-kontext/max)
|
|
174
|
+
|
|
175
|
+
Compare Flux Kontext with other Black Forest Labs models at https://runapi.ai/providers/black-forest-labs. Browse every RunAPI model and skill at https://runapi.ai/models. SDK repository: https://github.com/runapi-ai/flux-kontext-sdk. Skill repository: https://github.com/runapi-ai/flux-kontext.
|