@runapi.ai/flux-kontext 0.2.1 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runapi.ai/flux-kontext",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "RunAPI Flux Kontext SDK for JavaScript, Ruby, and Go",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -28,7 +28,7 @@
28
28
  "clean": "rm -rf dist"
29
29
  },
30
30
  "dependencies": {
31
- "@runapi.ai/core": "^0.2.1"
31
+ "@runapi.ai/core": "^0.2.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^20.0.0",
@@ -1,4 +1,25 @@
1
- # Flux Kontext API Skill for RunAPI
1
+ <p align="center">
2
+ <a href="https://github.com/runapi-ai/flux-kontext">
3
+ <h3 align="center">Flux Kontext API Skill for RunAPI</h3>
4
+ </a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ Install this agent skill, inspect Flux Kontext fields, then run jobs through the RunAPI CLI.
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://runapi.ai/models/flux-kontext"><strong>Model Reference</strong></a> · <a href="https://github.com/runapi-ai/cli"><strong>CLI</strong></a> · <a href="https://github.com/runapi-ai/flux-kontext-sdk"><strong>SDK</strong></a>
13
+ </p>
14
+
15
+ <div align="center">
16
+
17
+ [![skills.sh](https://www.skills.sh/b/runapi-ai/flux-kontext)](https://www.skills.sh/runapi-ai/flux-kontext/flux-kontext)
18
+ [![ClawHub](https://img.shields.io/badge/ClawHub-runapi--flux--kontext-111827)](https://clawhub.ai/runapi-ai/runapi-flux-kontext)
19
+ [![License](https://img.shields.io/github/license/runapi-ai/flux-kontext)](https://github.com/runapi-ai/flux-kontext/blob/main/LICENSE)
20
+
21
+ </div>
22
+ <br/>
2
23
 
3
24
  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
25
 
@@ -10,7 +31,18 @@ The canonical agent file is `skills/flux-kontext/SKILL.md`.
10
31
  npx skills add runapi-ai/flux-kontext -g
11
32
  ```
12
33
 
13
- Or manually: clone this repo and copy `skills/flux-kontext/` into your agent's skills directory.
34
+ Or paste this prompt to your AI agent:
35
+
36
+ ```text
37
+ Install the flux-kontext skill for me:
38
+
39
+ 1. Clone https://github.com/runapi-ai/flux-kontext
40
+ 2. Copy the skills/flux-kontext/ directory into your
41
+ user-level skills directory (e.g. ~/.claude/skills/
42
+ for Claude Code, ~/.codex/skills/ for Codex).
43
+ 3. Verify that SKILL.md is present.
44
+ 4. Confirm the install path when done.
45
+ ```
14
46
 
15
47
  ## Quick example
16
48
 
@@ -1,175 +1,77 @@
1
1
  ---
2
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
3
+ description: Generate and edit images with Flux Kontext through RunAPI. Use when the user asks an agent to create, edit, or transform images with Flux Kontext. Default to the RunAPI CLI for one-off generation; use SDKs only when the user is integrating RunAPI into an app or backend.
4
+ documentation: https://runapi.ai/models/flux-kontext.md
5
+ provider_page: https://runapi.ai/providers/black-forest-labs.md
6
+ catalog: https://runapi.ai/models.md
7
+ metadata:
8
+ openclaw:
9
+ homepage: https://runapi.ai/models/flux-kontext
10
+ requires:
11
+ bins:
12
+ - runapi
13
+ install:
14
+ - kind: brew
15
+ formula: runapi-ai/tap/runapi
16
+ bins:
17
+ - runapi
18
+ envVars:
19
+ - name: RUNAPI_API_KEY
20
+ required: false
21
+ description: Optional RunAPI API key; agents should prefer environment auth or saved CLI config. Browser login is interactive fallback only.
7
22
  ---
8
- # @runapi.ai/flux-kontext — RunAPI.ai Flux Kontext image generation
9
23
 
10
- Build Node / TypeScript integrations that generate and transform images through RunAPI.ai.
24
+ # Flux Kontext on RunAPI
11
25
 
12
- ## Setup
26
+ Generate and edit images with Flux Kontext through RunAPI. The default path for one-off agent tasks is the `runapi` CLI; SDKs are for application integration.
13
27
 
14
- Requires **Node 18+** (global `fetch`).
28
+ ## Routing decision
15
29
 
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
30
+ - One-off generation, editing, or transformation for the user → use the **CLI path** with the `runapi` binary.
31
+ - Building an app, backend, worker, library, or production codebase → use the **SDK integration path**.
37
32
 
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
- });
33
+ ## CLI path
45
34
 
46
- const url = result.images[0].url;
47
- ```
35
+ The `runapi` binary is the runtime dependency. Run `runapi auth status` first. For agents and headless runs, prefer `RUNAPI_API_KEY` or import it into saved config with `printf '%s' "$RUNAPI_API_KEY" | runapi auth import-token --token -`. Use `runapi login` only when the user explicitly wants interactive browser auth.
48
36
 
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:
37
+ Inspect the available actions and request fields with CLI help:
50
38
 
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') { /* ... */ }
39
+ ```shell
40
+ runapi flux-kontext --help
41
+ runapi flux-kontext text-to-image --help
56
42
  ```
57
43
 
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:
44
+ Run a one-off task (synchronous polls until the task completes):
61
45
 
62
- ```ts
63
- await client.textToImage.run(params, { maxWaitMs: 5 * 60_000, pollIntervalMs: 2_000 });
46
+ ```shell
47
+ runapi flux-kontext text-to-image --input-file request.json
64
48
  ```
65
49
 
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
50
+ Submit asynchronously and poll separately:
69
51
 
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
- });
52
+ ```shell
53
+ runapi flux-kontext text-to-image --async --input-file request.json
54
+ runapi wait <task-id> --service flux-kontext --action text-to-image
79
55
  ```
80
56
 
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
- ```
57
+ Available actions: `text-to-image`.
155
58
 
156
- ## Gotchas
59
+ ## SDK integration path
157
60
 
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.
61
+ When integrating Flux Kontext into an app, backend, worker, or library — not for one-off tasks use a RunAPI SDK package:
162
62
 
163
- ## Dig deeper
63
+ - JavaScript / TypeScript: `@runapi.ai/flux-kontext`
64
+ - Ruby: `runapi-flux_kontext`
65
+ - Go: `github.com/runapi-ai/flux-kontext-sdk/go`
164
66
 
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.
67
+ ## References
166
68
 
167
- ## RunAPI public routing
69
+ - Model overview, pricing, and rate limits: https://runapi.ai/models/flux-kontext.md
70
+ - Provider comparison: https://runapi.ai/providers/black-forest-labs.md
71
+ - Full model catalog: https://runapi.ai/models.md
168
72
 
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.
73
+ ## Variants
170
74
 
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)
75
+ - [Flux Kontext Pro](https://runapi.ai/models/flux-kontext/pro.md)
76
+ - [Flux Kontext Max](https://runapi.ai/models/flux-kontext/max.md)
174
77
 
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.