/install runapi-flux-kontext
@runapi.ai/flux-kontext — RunAPI.ai Flux Kontext image generation
Build Node / TypeScript integrations that generate and transform images through RunAPI.ai.
Setup
Requires Node 18+ (global fetch).
npm install @runapi.ai/flux-kontext
Set your API key in the environment:
# .env
RUNAPI_API_KEY=runapi_xxx # get one at https://runapi.ai/api_keys
import { FluxKontextClient } from '@runapi.ai/flux-kontext';
// The SDK reads RUNAPI_API_KEY from the environment automatically.
const client = new FluxKontextClient();
Pass { apiKey } explicitly if you manage secrets differently. baseUrl defaults to https://runapi.ai; override only for local development.
Core recipe — text to image
const result = await client.textToImage.run({
model: 'flux-kontext-pro',
prompt: 'A futuristic cityscape at night',
aspect_ratio: '16:9',
output_format: 'jpeg',
});
const url = result.images[0].url;
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:
const { id } = await client.textToImage.create({ model: 'flux-kontext-pro', prompt: '...' });
// return 202 immediately; fetch later:
const status = await client.textToImage.get(id);
if (status.status === 'completed') { /* ... */ }
Do not hold a web worker open waiting on run(). Split + webhook is the production pattern.
run() polls every 2 s for up to 15 min by default. Tune when needed:
await client.textToImage.run(params, { maxWaitMs: 5 * 60_000, pollIntervalMs: 2_000 });
If TaskTimeoutError fires, the task is still running server-side — resume with textToImage.get(id) or finish via webhook.
Image-to-image — edit a source image
Pass input_image (a single URL) along with your prompt:
await client.textToImage.run({
model: 'flux-kontext-max',
prompt: 'Restyle as a 1970s film photograph',
input_image: 'https://cdn.example.com/source.jpg',
aspect_ratio: '4:3',
});
Models
model |
Use case |
|---|---|
flux-kontext-pro |
Cost-efficient production output. |
flux-kontext-max |
Higher-fidelity variant. |
aspect_ratio values: 21:9, 16:9, 4:3, 1:1, 3:4, 9:16. output_format: jpeg / png.
Exact credit costs per model are shown at https://runapi.ai/pricing and in the dashboard — do not hardcode prices in application code.
Callbacks (webhooks)
Pass callback_url on create() (or any run() call) and RunAPI will POST the final payload to you:
await client.textToImage.create({
model: 'flux-kontext-pro',
prompt: '...',
callback_url: 'https://your.app/webhooks/runapi/flux-kontext',
});
Payload shape:
{ id: string; status: 'completed' | 'failed'; images?: { url: string; origin_url?: string }[]; error?: string }
Always verify the signature before trusting the body. RunAPI signs every callback with your account's Callback Secret (rotate at /accounts/callback_secret). Headers:
X-Callback-Id— UUID, store to make handler idempotentX-Callback-Timestamp— unix seconds, reject if|now - ts| > 300X-Callback-Signature— base64 HMAC-SHA256 over`${id}.${ts}.${rawBody}`using the base64-decoded secret
import crypto from 'node:crypto';
function verify(raw: string, id: string, ts: string, sig: string, secret: string) {
const key = Buffer.from(secret, 'base64');
const mac = crypto.createHmac('sha256', key)
.update(`${id}.${ts}.${raw}`)
.digest('base64');
return crypto.timingSafeEqual(Buffer.from(mac), Buffer.from(sig));
}
Reply 2xx within 10s; any non-2xx triggers retries.
Errors
All errors are re-exported from @runapi.ai/core. Always instanceof — never string-match messages.
| Error | Status | Action |
|---|---|---|
AuthenticationError |
401 | abort; surface "reconnect your API key" |
InsufficientCreditsError |
402 | prompt user to top up at runapi.ai/billing |
ValidationError |
400 / 422 | fix params; do not retry |
RateLimitError |
429 | sleep err.retryAfterMs, then retry |
ServiceUnavailableError |
503 / 455 | retry with backoff; transient service issue |
TaskFailedError |
— | show err.details to user; do not auto-retry |
TaskTimeoutError |
— | re-poll with textToImage.get(id) |
import { InsufficientCreditsError, TaskFailedError } from '@runapi.ai/flux-kontext';
try {
await client.textToImage.run({ model: 'flux-kontext-pro', prompt: '...' });
} catch (err) {
if (err instanceof InsufficientCreditsError) { /* surface top-up CTA */ }
else if (err instanceof TaskFailedError) { /* show err.details */ }
else throw err;
}
Gotchas
modelis required on every call.input_imageis a single URL (string), not an array — this is the one endpoint in the family that takes a scalar URL.enable_translationdefaults totrue— the prompt is auto-translated to English. Setfalseto keep the raw prompt.callback_urlmust be reachable from the public internet.localhost/127.0.0.1URLs will never fire — use a tunnel (cloudflared, ngrok, tailscale funnel) when developing locally.
Dig deeper
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.
RunAPI public routing
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.
Pricing, rate limits, and commercial usage for flux kontext api should point to the most specific variant page:
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.
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install runapi-flux-kontext - 安装完成后,直接呼叫该 Skill 的名称或使用
/runapi-flux-kontext触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
Flux Kontext 是什么?
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 t... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 33 次。
如何安装 Flux Kontext?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install runapi-flux-kontext」即可一键安装,无需额外配置。
Flux Kontext 是免费的吗?
是的,Flux Kontext 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Flux Kontext 支持哪些平台?
Flux Kontext 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Flux Kontext?
由 RunAPI(@runapi-ai)开发并维护,当前版本 v0.2.3。