@runapi.ai/flux-2 0.2.6 → 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.
- package/README.md +5 -5
- package/dist/index.js +124 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -4
- package/skills/flux-2/README.md +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Flux API JavaScript SDK for RunAPI
|
|
1
|
+
# Flux 2 API JavaScript SDK for RunAPI
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The Flux 2 JavaScript 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 JavaScript.
|
|
4
4
|
|
|
5
|
-
This
|
|
5
|
+
This README is the JavaScript 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
|
|
|
@@ -27,7 +27,7 @@ const status = await client.textToImage.get(task.id);
|
|
|
27
27
|
const remix = await client.remixImage.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://
|
|
30
|
+
source_image_urls: ['https://cdn.runapi.ai/public/samples/image.jpg'],
|
|
31
31
|
aspect_ratio: 'auto',
|
|
32
32
|
});
|
|
33
33
|
```
|
|
@@ -38,7 +38,7 @@ RunAPI-generated file URLs are temporary. Download and store generated images, v
|
|
|
38
38
|
|
|
39
39
|
## Language notes
|
|
40
40
|
|
|
41
|
-
Use the TypeScript types in `src/types.ts` and the resource classes under `src/resources` when building image applications. The available resources
|
|
41
|
+
Use the TypeScript types in `src/types.ts` and the resource classes under `src/resources` when building image applications. The available resources are `textToImage` and `remixImage`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
|
|
42
42
|
|
|
43
43
|
## Links
|
|
44
44
|
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,124 @@ var import_core3 = require("@runapi.ai/core");
|
|
|
41
41
|
// src/resources/text-to-image.ts
|
|
42
42
|
var import_core = require("@runapi.ai/core");
|
|
43
43
|
var import_internal = require("@runapi.ai/core/internal");
|
|
44
|
+
|
|
45
|
+
// src/contract_gen.ts
|
|
46
|
+
var contract = {
|
|
47
|
+
"remix-image": {
|
|
48
|
+
"models": [
|
|
49
|
+
"flux-2-flex-remix-image",
|
|
50
|
+
"flux-2-pro-remix-image"
|
|
51
|
+
],
|
|
52
|
+
"fields_by_model": {
|
|
53
|
+
"flux-2-flex-remix-image": {
|
|
54
|
+
"aspect_ratio": {
|
|
55
|
+
"enum": [
|
|
56
|
+
"1:1",
|
|
57
|
+
"4:3",
|
|
58
|
+
"3:4",
|
|
59
|
+
"16:9",
|
|
60
|
+
"9:16",
|
|
61
|
+
"3:2",
|
|
62
|
+
"2:3",
|
|
63
|
+
"auto"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"output_resolution": {
|
|
67
|
+
"enum": [
|
|
68
|
+
"1k",
|
|
69
|
+
"2k"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"prompt": {
|
|
73
|
+
"required": true
|
|
74
|
+
},
|
|
75
|
+
"source_image_urls": {
|
|
76
|
+
"required": true
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"flux-2-pro-remix-image": {
|
|
80
|
+
"aspect_ratio": {
|
|
81
|
+
"enum": [
|
|
82
|
+
"1:1",
|
|
83
|
+
"4:3",
|
|
84
|
+
"3:4",
|
|
85
|
+
"16:9",
|
|
86
|
+
"9:16",
|
|
87
|
+
"3:2",
|
|
88
|
+
"2:3",
|
|
89
|
+
"auto"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"output_resolution": {
|
|
93
|
+
"enum": [
|
|
94
|
+
"1k",
|
|
95
|
+
"2k"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
"prompt": {
|
|
99
|
+
"required": true
|
|
100
|
+
},
|
|
101
|
+
"source_image_urls": {
|
|
102
|
+
"required": true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"text-to-image": {
|
|
108
|
+
"models": [
|
|
109
|
+
"flux-2-flex-text-to-image",
|
|
110
|
+
"flux-2-pro-text-to-image"
|
|
111
|
+
],
|
|
112
|
+
"fields_by_model": {
|
|
113
|
+
"flux-2-flex-text-to-image": {
|
|
114
|
+
"aspect_ratio": {
|
|
115
|
+
"enum": [
|
|
116
|
+
"1:1",
|
|
117
|
+
"4:3",
|
|
118
|
+
"3:4",
|
|
119
|
+
"16:9",
|
|
120
|
+
"9:16",
|
|
121
|
+
"3:2",
|
|
122
|
+
"2:3"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"output_resolution": {
|
|
126
|
+
"enum": [
|
|
127
|
+
"1k",
|
|
128
|
+
"2k"
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
"prompt": {
|
|
132
|
+
"required": true
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
"flux-2-pro-text-to-image": {
|
|
136
|
+
"aspect_ratio": {
|
|
137
|
+
"enum": [
|
|
138
|
+
"1:1",
|
|
139
|
+
"4:3",
|
|
140
|
+
"3:4",
|
|
141
|
+
"16:9",
|
|
142
|
+
"9:16",
|
|
143
|
+
"3:2",
|
|
144
|
+
"2:3"
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
"output_resolution": {
|
|
148
|
+
"enum": [
|
|
149
|
+
"1k",
|
|
150
|
+
"2k"
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
"prompt": {
|
|
154
|
+
"required": true
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/resources/text-to-image.ts
|
|
44
162
|
var ENDPOINT = "/api/v1/flux_2/text_to_image";
|
|
45
163
|
var TextToImage = class {
|
|
46
164
|
constructor(http) {
|
|
@@ -68,8 +186,10 @@ var TextToImage = class {
|
|
|
68
186
|
* @returns The task creation result with id.
|
|
69
187
|
*/
|
|
70
188
|
async create(params, options) {
|
|
189
|
+
const body = (0, import_core.compactParams)(params);
|
|
190
|
+
(0, import_core.validateParams)(contract["text-to-image"], body);
|
|
71
191
|
return this.http.request("POST", ENDPOINT, {
|
|
72
|
-
body
|
|
192
|
+
body,
|
|
73
193
|
...options
|
|
74
194
|
});
|
|
75
195
|
}
|
|
@@ -116,8 +236,10 @@ var RemixImage = class {
|
|
|
116
236
|
* @returns The task creation result with id.
|
|
117
237
|
*/
|
|
118
238
|
async create(params, options) {
|
|
239
|
+
const body = (0, import_core2.compactParams)(params);
|
|
240
|
+
(0, import_core2.validateParams)(contract["remix-image"], body);
|
|
119
241
|
return this.http.request("POST", ENDPOINT2, {
|
|
120
|
-
body
|
|
242
|
+
body,
|
|
121
243
|
...options
|
|
122
244
|
});
|
|
123
245
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/resources/text-to-image.ts","../src/resources/remix-image.ts"],"sourcesContent":["export { Flux2Client } 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 { BaseClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\nimport { RemixImage } from './resources/remix-image';\n\n/**\n * Flux 2 text-to-image and remix API client.\n *\n * Pro and flex tiers for both text-to-image generation and\n * text-guided image remixing from source images.\n *\n * @example\n * ```typescript\n * const client = new Flux2Client({\n * apiKey: 'your-api-key',\n * baseUrl: 'https://runapi.ai',\n * });\n *\n * const result = await client.textToImage.run({\n * model: 'flux-2-pro-text-to-image',\n * prompt: 'A futuristic cityscape at night',\n * });\n * ```\n */\nexport class Flux2Client extends BaseClient {\n /** Text-to-image generation. */\n public readonly textToImage: TextToImage;\n /** Transform source images with text-guided prompts. */\n public readonly remixImage: RemixImage;\n\n constructor(options: ClientOptions = {}) {\n super(options);\n this.textToImage = new TextToImage(this.http);\n this.remixImage = new RemixImage(this.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_2/text_to_image';\n\n/** Flux 2 text-to-image generation resource. */\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate an image and wait until complete.\n * @param params Text-to-image parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed text-to-image result.\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 /**\n * Create a text-to-image task; returns immediately with a task id.\n * @param params Text-to-image parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\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 /**\n * Fetch the current status of a text-to-image task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current text-to-image status.\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","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 CompletedRemixImageResponse,\n RemixImageParams,\n RemixImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_2/remix_image';\n\n/** Flux 2 image remix: transform source images with text-guided prompts. */\nexport class RemixImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Remix an image and wait until complete.\n * @param params Image remix parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed remix result with images.\n */\n async run(params: RemixImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedRemixImageResponse> {\n const { id } = await this.create(params, options);\n const response = await pollUntilComplete<RemixImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n return response as CompletedRemixImageResponse;\n }\n\n /**\n * Create an image remix task; returns immediately with a task id.\n * @param params Image remix parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: RemixImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body: compactParams(params),\n ...options,\n });\n }\n\n /**\n * Fetch the current status of an image remix task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current remix status.\n */\n async get(id: string, options?: RequestOptions): Promise<RemixImageResponse> {\n return this.http.request<RemixImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,IAC3B,CAAC;AACD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,OAAO,QAA0B,SAAuD;AAC5F,WAAO,KAAK,KAAK,QAA4B,QAAQA,WAAU;AAAA,MAC7D,UAAM,4BAAc,MAAM;AAAA,MAC1B,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,IAAY,SAAuD;AAC3E,WAAO,KAAK,KAAK,QAA4B,OAAO,GAAGA,SAAQ,IAAI,EAAE,IAAI;AAAA,MACvE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;AFhCO,IAAM,cAAN,cAA0B,wBAAW;AAAA;AAAA,EAE1B;AAAA;AAAA,EAEA;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,OAAO;AACb,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAC5C,SAAK,aAAa,IAAI,WAAW,KAAK,IAAI;AAAA,EAC5C;AACF;;;AD9BA,IAAAC,eAYO;","names":["import_core","import_core","import_internal","ENDPOINT","import_core"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/resources/text-to-image.ts","../src/contract_gen.ts","../src/resources/remix-image.ts"],"sourcesContent":["export { Flux2Client } 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 { BaseClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\nimport { RemixImage } from './resources/remix-image';\n\n/**\n * Flux 2 text-to-image and remix API client.\n *\n * Pro and flex tiers for both text-to-image generation and\n * text-guided image remixing from source images.\n *\n * @example\n * ```typescript\n * const client = new Flux2Client({\n * apiKey: 'your-api-key',\n * baseUrl: 'https://runapi.ai',\n * });\n *\n * const result = await client.textToImage.run({\n * model: 'flux-2-pro-text-to-image',\n * prompt: 'A futuristic cityscape at night',\n * });\n * ```\n */\nexport class Flux2Client extends BaseClient {\n /** Text-to-image generation. */\n public readonly textToImage: TextToImage;\n /** Transform source images with text-guided prompts. */\n public readonly remixImage: RemixImage;\n\n constructor(options: ClientOptions = {}) {\n super(options);\n this.textToImage = new TextToImage(this.http);\n this.remixImage = new RemixImage(this.http);\n }\n}\n","import type { HttpClient, RequestOptions, PollingOptions, ActionSchema } from '@runapi.ai/core';\nimport { compactParams, validateParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport { contract } from '../contract_gen';\nimport type {\n CompletedTextToImageResponse,\n TextToImageParams,\n TextToImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_2/text_to_image';\n\n/** Flux 2 text-to-image generation resource. */\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate an image and wait until complete.\n * @param params Text-to-image parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed text-to-image result.\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 /**\n * Create a text-to-image task; returns immediately with a task id.\n * @param params Text-to-image parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n const body = compactParams(params);\n validateParams(contract['text-to-image'] as ActionSchema, body as Record<string, unknown>);\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body,\n ...options,\n });\n }\n\n /**\n * Fetch the current status of a text-to-image task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current text-to-image status.\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 const contract = {\n \"remix-image\": {\n \"models\": [\n \"flux-2-flex-remix-image\",\n \"flux-2-pro-remix-image\"\n ],\n \"fields_by_model\": {\n \"flux-2-flex-remix-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\",\n \"auto\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n },\n \"source_image_urls\": {\n \"required\": true\n }\n },\n \"flux-2-pro-remix-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\",\n \"auto\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n },\n \"source_image_urls\": {\n \"required\": true\n }\n }\n }\n },\n \"text-to-image\": {\n \"models\": [\n \"flux-2-flex-text-to-image\",\n \"flux-2-pro-text-to-image\"\n ],\n \"fields_by_model\": {\n \"flux-2-flex-text-to-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n }\n },\n \"flux-2-pro-text-to-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n }\n }\n }\n }\n} as const;\n","import type { HttpClient, RequestOptions, PollingOptions, ActionSchema } from '@runapi.ai/core';\nimport { compactParams, validateParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport { contract } from '../contract_gen';\nimport type {\n CompletedRemixImageResponse,\n RemixImageParams,\n RemixImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_2/remix_image';\n\n/** Flux 2 image remix: transform source images with text-guided prompts. */\nexport class RemixImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Remix an image and wait until complete.\n * @param params Image remix parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed remix result with images.\n */\n async run(params: RemixImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedRemixImageResponse> {\n const { id } = await this.create(params, options);\n const response = await pollUntilComplete<RemixImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n return response as CompletedRemixImageResponse;\n }\n\n /**\n * Create an image remix task; returns immediately with a task id.\n * @param params Image remix parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: RemixImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n const body = compactParams(params);\n validateParams(contract['remix-image'] as ActionSchema, body as Record<string, unknown>);\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body,\n ...options,\n });\n }\n\n /**\n * Fetch the current status of an image remix task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current remix status.\n */\n async get(id: string, options?: RequestOptions): Promise<RemixImageResponse> {\n return this.http.request<RemixImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;A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package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,126 @@
|
|
|
2
2
|
import { BaseClient } from "@runapi.ai/core";
|
|
3
3
|
|
|
4
4
|
// src/resources/text-to-image.ts
|
|
5
|
-
import { compactParams } from "@runapi.ai/core";
|
|
5
|
+
import { compactParams, validateParams } from "@runapi.ai/core";
|
|
6
6
|
import { pollUntilComplete } from "@runapi.ai/core/internal";
|
|
7
|
+
|
|
8
|
+
// src/contract_gen.ts
|
|
9
|
+
var contract = {
|
|
10
|
+
"remix-image": {
|
|
11
|
+
"models": [
|
|
12
|
+
"flux-2-flex-remix-image",
|
|
13
|
+
"flux-2-pro-remix-image"
|
|
14
|
+
],
|
|
15
|
+
"fields_by_model": {
|
|
16
|
+
"flux-2-flex-remix-image": {
|
|
17
|
+
"aspect_ratio": {
|
|
18
|
+
"enum": [
|
|
19
|
+
"1:1",
|
|
20
|
+
"4:3",
|
|
21
|
+
"3:4",
|
|
22
|
+
"16:9",
|
|
23
|
+
"9:16",
|
|
24
|
+
"3:2",
|
|
25
|
+
"2:3",
|
|
26
|
+
"auto"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"output_resolution": {
|
|
30
|
+
"enum": [
|
|
31
|
+
"1k",
|
|
32
|
+
"2k"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"prompt": {
|
|
36
|
+
"required": true
|
|
37
|
+
},
|
|
38
|
+
"source_image_urls": {
|
|
39
|
+
"required": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"flux-2-pro-remix-image": {
|
|
43
|
+
"aspect_ratio": {
|
|
44
|
+
"enum": [
|
|
45
|
+
"1:1",
|
|
46
|
+
"4:3",
|
|
47
|
+
"3:4",
|
|
48
|
+
"16:9",
|
|
49
|
+
"9:16",
|
|
50
|
+
"3:2",
|
|
51
|
+
"2:3",
|
|
52
|
+
"auto"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"output_resolution": {
|
|
56
|
+
"enum": [
|
|
57
|
+
"1k",
|
|
58
|
+
"2k"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"prompt": {
|
|
62
|
+
"required": true
|
|
63
|
+
},
|
|
64
|
+
"source_image_urls": {
|
|
65
|
+
"required": true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"text-to-image": {
|
|
71
|
+
"models": [
|
|
72
|
+
"flux-2-flex-text-to-image",
|
|
73
|
+
"flux-2-pro-text-to-image"
|
|
74
|
+
],
|
|
75
|
+
"fields_by_model": {
|
|
76
|
+
"flux-2-flex-text-to-image": {
|
|
77
|
+
"aspect_ratio": {
|
|
78
|
+
"enum": [
|
|
79
|
+
"1:1",
|
|
80
|
+
"4:3",
|
|
81
|
+
"3:4",
|
|
82
|
+
"16:9",
|
|
83
|
+
"9:16",
|
|
84
|
+
"3:2",
|
|
85
|
+
"2:3"
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"output_resolution": {
|
|
89
|
+
"enum": [
|
|
90
|
+
"1k",
|
|
91
|
+
"2k"
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
"prompt": {
|
|
95
|
+
"required": true
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"flux-2-pro-text-to-image": {
|
|
99
|
+
"aspect_ratio": {
|
|
100
|
+
"enum": [
|
|
101
|
+
"1:1",
|
|
102
|
+
"4:3",
|
|
103
|
+
"3:4",
|
|
104
|
+
"16:9",
|
|
105
|
+
"9:16",
|
|
106
|
+
"3:2",
|
|
107
|
+
"2:3"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"output_resolution": {
|
|
111
|
+
"enum": [
|
|
112
|
+
"1k",
|
|
113
|
+
"2k"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
"prompt": {
|
|
117
|
+
"required": true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/resources/text-to-image.ts
|
|
7
125
|
var ENDPOINT = "/api/v1/flux_2/text_to_image";
|
|
8
126
|
var TextToImage = class {
|
|
9
127
|
constructor(http) {
|
|
@@ -31,8 +149,10 @@ var TextToImage = class {
|
|
|
31
149
|
* @returns The task creation result with id.
|
|
32
150
|
*/
|
|
33
151
|
async create(params, options) {
|
|
152
|
+
const body = compactParams(params);
|
|
153
|
+
validateParams(contract["text-to-image"], body);
|
|
34
154
|
return this.http.request("POST", ENDPOINT, {
|
|
35
|
-
body
|
|
155
|
+
body,
|
|
36
156
|
...options
|
|
37
157
|
});
|
|
38
158
|
}
|
|
@@ -50,7 +170,7 @@ var TextToImage = class {
|
|
|
50
170
|
};
|
|
51
171
|
|
|
52
172
|
// src/resources/remix-image.ts
|
|
53
|
-
import { compactParams as compactParams2 } from "@runapi.ai/core";
|
|
173
|
+
import { compactParams as compactParams2, validateParams as validateParams2 } from "@runapi.ai/core";
|
|
54
174
|
import { pollUntilComplete as pollUntilComplete2 } from "@runapi.ai/core/internal";
|
|
55
175
|
var ENDPOINT2 = "/api/v1/flux_2/remix_image";
|
|
56
176
|
var RemixImage = class {
|
|
@@ -79,8 +199,10 @@ var RemixImage = class {
|
|
|
79
199
|
* @returns The task creation result with id.
|
|
80
200
|
*/
|
|
81
201
|
async create(params, options) {
|
|
202
|
+
const body = compactParams2(params);
|
|
203
|
+
validateParams2(contract["remix-image"], body);
|
|
82
204
|
return this.http.request("POST", ENDPOINT2, {
|
|
83
|
-
body
|
|
205
|
+
body,
|
|
84
206
|
...options
|
|
85
207
|
});
|
|
86
208
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/resources/text-to-image.ts","../src/resources/remix-image.ts","../src/index.ts"],"sourcesContent":["import { BaseClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\nimport { RemixImage } from './resources/remix-image';\n\n/**\n * Flux 2 text-to-image and remix API client.\n *\n * Pro and flex tiers for both text-to-image generation and\n * text-guided image remixing from source images.\n *\n * @example\n * ```typescript\n * const client = new Flux2Client({\n * apiKey: 'your-api-key',\n * baseUrl: 'https://runapi.ai',\n * });\n *\n * const result = await client.textToImage.run({\n * model: 'flux-2-pro-text-to-image',\n * prompt: 'A futuristic cityscape at night',\n * });\n * ```\n */\nexport class Flux2Client extends BaseClient {\n /** Text-to-image generation. */\n public readonly textToImage: TextToImage;\n /** Transform source images with text-guided prompts. */\n public readonly remixImage: RemixImage;\n\n constructor(options: ClientOptions = {}) {\n super(options);\n this.textToImage = new TextToImage(this.http);\n this.remixImage = new RemixImage(this.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_2/text_to_image';\n\n/** Flux 2 text-to-image generation resource. */\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate an image and wait until complete.\n * @param params Text-to-image parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed text-to-image result.\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 /**\n * Create a text-to-image task; returns immediately with a task id.\n * @param params Text-to-image parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\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 /**\n * Fetch the current status of a text-to-image task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current text-to-image status.\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","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 CompletedRemixImageResponse,\n RemixImageParams,\n RemixImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_2/remix_image';\n\n/** Flux 2 image remix: transform source images with text-guided prompts. */\nexport class RemixImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Remix an image and wait until complete.\n * @param params Image remix parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed remix result with images.\n */\n async run(params: RemixImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedRemixImageResponse> {\n const { id } = await this.create(params, options);\n const response = await pollUntilComplete<RemixImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n return response as CompletedRemixImageResponse;\n }\n\n /**\n * Create an image remix task; returns immediately with a task id.\n * @param params Image remix parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: RemixImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body: compactParams(params),\n ...options,\n });\n }\n\n /**\n * Fetch the current status of an image remix task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current remix status.\n */\n async get(id: string, options?: RequestOptions): Promise<RemixImageResponse> {\n return this.http.request<RemixImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n","export { Flux2Client } 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,kBAAsC;;;ACC/C,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAQlC,IAAM,WAAW;AAGV,IAAM,cAAN,MAAkB;AAAA,EACvB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,IAAY,SAAwD;AAC5E,WAAO,KAAK,KAAK,QAA6B,OAAO,GAAG,QAAQ,IAAI,EAAE,IAAI;AAAA,MACxE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;ACtDA,SAAS,iBAAAA,sBAAqB;AAC9B,SAAS,qBAAAC,0BAAyB;AAQlC,IAAMC,YAAW;AAGV,IAAM,aAAN,MAAiB;AAAA,EACtB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,MAAM,IAAI,QAA0B,SAAiF;AACnH,UAAM,EAAE,GAAG,IAAI,MAAM,KAAK,OAAO,QAAQ,OAAO;AAChD,UAAM,WAAW,MAAMD,mBAAsC,MAAM,KAAK,IAAI,IAAI,OAAO,GAAG;AAAA,MACxF,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,IAC3B,CAAC;AACD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,OAAO,QAA0B,SAAuD;AAC5F,WAAO,KAAK,KAAK,QAA4B,QAAQC,WAAU;AAAA,MAC7D,MAAMF,eAAc,MAAM;AAAA,MAC1B,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,IAAY,SAAuD;AAC3E,WAAO,KAAK,KAAK,QAA4B,OAAO,GAAGE,SAAQ,IAAI,EAAE,IAAI;AAAA,MACvE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;AFhCO,IAAM,cAAN,cAA0B,WAAW;AAAA;AAAA,EAE1B;AAAA;AAAA,EAEA;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,OAAO;AACb,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAC5C,SAAK,aAAa,IAAI,WAAW,KAAK,IAAI;AAAA,EAC5C;AACF;;;AG9BA;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":["compactParams","pollUntilComplete","ENDPOINT"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/resources/text-to-image.ts","../src/contract_gen.ts","../src/resources/remix-image.ts","../src/index.ts"],"sourcesContent":["import { BaseClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\nimport { RemixImage } from './resources/remix-image';\n\n/**\n * Flux 2 text-to-image and remix API client.\n *\n * Pro and flex tiers for both text-to-image generation and\n * text-guided image remixing from source images.\n *\n * @example\n * ```typescript\n * const client = new Flux2Client({\n * apiKey: 'your-api-key',\n * baseUrl: 'https://runapi.ai',\n * });\n *\n * const result = await client.textToImage.run({\n * model: 'flux-2-pro-text-to-image',\n * prompt: 'A futuristic cityscape at night',\n * });\n * ```\n */\nexport class Flux2Client extends BaseClient {\n /** Text-to-image generation. */\n public readonly textToImage: TextToImage;\n /** Transform source images with text-guided prompts. */\n public readonly remixImage: RemixImage;\n\n constructor(options: ClientOptions = {}) {\n super(options);\n this.textToImage = new TextToImage(this.http);\n this.remixImage = new RemixImage(this.http);\n }\n}\n","import type { HttpClient, RequestOptions, PollingOptions, ActionSchema } from '@runapi.ai/core';\nimport { compactParams, validateParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport { contract } from '../contract_gen';\nimport type {\n CompletedTextToImageResponse,\n TextToImageParams,\n TextToImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_2/text_to_image';\n\n/** Flux 2 text-to-image generation resource. */\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate an image and wait until complete.\n * @param params Text-to-image parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed text-to-image result.\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 /**\n * Create a text-to-image task; returns immediately with a task id.\n * @param params Text-to-image parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n const body = compactParams(params);\n validateParams(contract['text-to-image'] as ActionSchema, body as Record<string, unknown>);\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body,\n ...options,\n });\n }\n\n /**\n * Fetch the current status of a text-to-image task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current text-to-image status.\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 const contract = {\n \"remix-image\": {\n \"models\": [\n \"flux-2-flex-remix-image\",\n \"flux-2-pro-remix-image\"\n ],\n \"fields_by_model\": {\n \"flux-2-flex-remix-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\",\n \"auto\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n },\n \"source_image_urls\": {\n \"required\": true\n }\n },\n \"flux-2-pro-remix-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\",\n \"auto\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n },\n \"source_image_urls\": {\n \"required\": true\n }\n }\n }\n },\n \"text-to-image\": {\n \"models\": [\n \"flux-2-flex-text-to-image\",\n \"flux-2-pro-text-to-image\"\n ],\n \"fields_by_model\": {\n \"flux-2-flex-text-to-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n }\n },\n \"flux-2-pro-text-to-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"4:3\",\n \"3:4\",\n \"16:9\",\n \"9:16\",\n \"3:2\",\n \"2:3\"\n ]\n },\n \"output_resolution\": {\n \"enum\": [\n \"1k\",\n \"2k\"\n ]\n },\n \"prompt\": {\n \"required\": true\n }\n }\n }\n }\n} as const;\n","import type { HttpClient, RequestOptions, PollingOptions, ActionSchema } from '@runapi.ai/core';\nimport { compactParams, validateParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport { contract } from '../contract_gen';\nimport type {\n CompletedRemixImageResponse,\n RemixImageParams,\n RemixImageResponse,\n TaskCreateResponse,\n} from '../types';\n\nconst ENDPOINT = '/api/v1/flux_2/remix_image';\n\n/** Flux 2 image remix: transform source images with text-guided prompts. */\nexport class RemixImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Remix an image and wait until complete.\n * @param params Image remix parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed remix result with images.\n */\n async run(params: RemixImageParams, options?: RequestOptions & PollingOptions): Promise<CompletedRemixImageResponse> {\n const { id } = await this.create(params, options);\n const response = await pollUntilComplete<RemixImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n return response as CompletedRemixImageResponse;\n }\n\n /**\n * Create an image remix task; returns immediately with a task id.\n * @param params Image remix parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: RemixImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n const body = compactParams(params);\n validateParams(contract['remix-image'] as ActionSchema, body as Record<string, unknown>);\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body,\n ...options,\n });\n }\n\n /**\n * Fetch the current status of an image remix task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current remix status.\n */\n async get(id: string, options?: RequestOptions): Promise<RemixImageResponse> {\n return this.http.request<RemixImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n","export { Flux2Client } 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,kBAAsC;;;ACC/C,SAAS,eAAe,sBAAsB;AAC9C,SAAS,yBAAyB;;;ACF3B,IAAM,WAAW;AAAA,EACtB,eAAe;AAAA,IACb,UAAU;AAAA,MACR;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB,2BAA2B;AAAA,QACzB,gBAAgB;AAAA,UACd,QAAQ;AAAA,YACN;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,qBAAqB;AAAA,UACnB,QAAQ;AAAA,YACN;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,UAAU;AAAA,UACR,YAAY;AAAA,QACd;AAAA,QACA,qBAAqB;AAAA,UACnB,YAAY;AAAA,QACd;AAAA,MACF;AAAA,MACA,0BAA0B;AAAA,QACxB,gBAAgB;AAAA,UACd,QAAQ;AAAA,YACN;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,qBAAqB;AAAA,UACnB,QAAQ;AAAA,YACN;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,UAAU;AAAA,UACR,YAAY;AAAA,QACd;AAAA,QACA,qBAAqB;AAAA,UACnB,YAAY;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,UAAU;AAAA,MACR;AAAA,MACA;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB,6BAA6B;AAAA,QAC3B,gBAAg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G;AACvC,UAAM,OAAO;AACb,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAC5C,SAAK,aAAa,IAAI,WAAW,KAAK,IAAI;AAAA,EAC5C;AACF;;;AI9BA;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":["compactParams","validateParams","pollUntilComplete","ENDPOINT","pollUntilComplete","compactParams","validateParams"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runapi.ai/flux-2",
|
|
3
|
-
"
|
|
4
|
-
|
|
3
|
+
"runapi": {
|
|
4
|
+
"slug": "flux-2"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.2.7",
|
|
7
|
+
"description": "RunAPI Flux 2 SDK for text-to-image and remix-image workflows in JavaScript, Python, Ruby, Go, and Java",
|
|
5
8
|
"main": "./dist/index.js",
|
|
6
9
|
"module": "./dist/index.mjs",
|
|
7
10
|
"types": "./dist/index.d.ts",
|
|
@@ -28,7 +31,7 @@
|
|
|
28
31
|
"clean": "rm -rf dist"
|
|
29
32
|
},
|
|
30
33
|
"dependencies": {
|
|
31
|
-
"@runapi.ai/core": "^0.2.
|
|
34
|
+
"@runapi.ai/core": "^0.2.7"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
37
|
"@types/node": "^20.0.0",
|
|
@@ -47,8 +50,16 @@
|
|
|
47
50
|
"api",
|
|
48
51
|
"sdk",
|
|
49
52
|
"typescript",
|
|
53
|
+
"python",
|
|
50
54
|
"ruby",
|
|
51
|
-
"golang"
|
|
55
|
+
"golang",
|
|
56
|
+
"java",
|
|
57
|
+
"maven",
|
|
58
|
+
"gradle",
|
|
59
|
+
"image-generation",
|
|
60
|
+
"text-to-image",
|
|
61
|
+
"image-api",
|
|
62
|
+
"flux-api"
|
|
52
63
|
],
|
|
53
64
|
"author": "RunAPI",
|
|
54
65
|
"license": "Apache-2.0",
|
|
@@ -56,5 +67,8 @@
|
|
|
56
67
|
"repository": {
|
|
57
68
|
"type": "git",
|
|
58
69
|
"url": "git+https://github.com/runapi-ai/flux-2-sdk.git"
|
|
70
|
+
},
|
|
71
|
+
"bugs": {
|
|
72
|
+
"url": "https://github.com/runapi-ai/flux-2-sdk/issues"
|
|
59
73
|
}
|
|
60
74
|
}
|
package/skills/flux-2/README.md
CHANGED
|
@@ -59,7 +59,7 @@ const result = await client.textToImage.run({
|
|
|
59
59
|
const remix = await client.remixImage.run({
|
|
60
60
|
model: 'flux-2-pro-remix-image',
|
|
61
61
|
prompt: 'Make this product shot feel like a warm editorial photo',
|
|
62
|
-
source_image_urls: ['https://
|
|
62
|
+
source_image_urls: ['https://cdn.runapi.ai/public/samples/image.jpg'],
|
|
63
63
|
aspect_ratio: 'auto',
|
|
64
64
|
});
|
|
65
65
|
```
|
|
@@ -87,7 +87,7 @@ const remix = await client.remixImage.run({
|
|
|
87
87
|
- 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.
|
|
88
88
|
- Keep API keys in `RUNAPI_API_KEY` or RunAPI CLI config; never commit secrets.
|
|
89
89
|
- Prefer `create`, `get`, and `run` JSON passthrough patterns instead of inventing flags for every model parameter.
|
|
90
|
-
- For
|
|
90
|
+
- For pricing, rate-limit, and commercial-usage answers, link to the variant page rather than the repository README.
|
|
91
91
|
|
|
92
92
|
## License
|
|
93
93
|
|