@ai-sdk/black-forest-labs 0.0.0-70e0935a-20260114150030 → 0.0.0-98261322-20260122142521
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/CHANGELOG.md +31 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/12-black-forest-labs.mdx +200 -0
- package/package.json +10 -5
- package/src/black-forest-labs-image-model.test.ts +576 -0
- package/src/black-forest-labs-image-model.ts +473 -0
- package/src/black-forest-labs-image-settings.ts +9 -0
- package/src/black-forest-labs-provider.test.ts +139 -0
- package/src/black-forest-labs-provider.ts +113 -0
- package/src/index.ts +14 -0
- package/src/version.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
# @ai-sdk/black-forest-labs
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-98261322-20260122142521
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
- 080559b: chore: add docs to package dist
|
|
8
|
+
|
|
9
|
+
## 1.0.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8dc54db: chore: add src folders to package bundle
|
|
14
|
+
|
|
15
|
+
## 1.0.8
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [5c090e7]
|
|
20
|
+
- @ai-sdk/provider@3.0.4
|
|
21
|
+
- @ai-sdk/provider-utils@4.0.8
|
|
22
|
+
|
|
23
|
+
## 1.0.7
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [46f46e4]
|
|
28
|
+
- @ai-sdk/provider-utils@4.0.7
|
|
29
|
+
|
|
30
|
+
## 1.0.6
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [1b11dcb]
|
|
35
|
+
- @ai-sdk/provider-utils@4.0.6
|
|
36
|
+
- @ai-sdk/provider@3.0.3
|
|
10
37
|
|
|
11
38
|
## 1.0.5
|
|
12
39
|
|
package/dist/index.js
CHANGED
|
@@ -392,7 +392,7 @@ function bflErrorToMessage(error) {
|
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
// src/version.ts
|
|
395
|
-
var VERSION = true ? "0.0.0-
|
|
395
|
+
var VERSION = true ? "0.0.0-98261322-20260122142521" : "0.0.0-test";
|
|
396
396
|
|
|
397
397
|
// src/black-forest-labs-provider.ts
|
|
398
398
|
var defaultBaseURL = "https://api.bfl.ai/v1";
|
package/dist/index.mjs
CHANGED
|
@@ -381,7 +381,7 @@ function bflErrorToMessage(error) {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
// src/version.ts
|
|
384
|
-
var VERSION = true ? "0.0.0-
|
|
384
|
+
var VERSION = true ? "0.0.0-98261322-20260122142521" : "0.0.0-test";
|
|
385
385
|
|
|
386
386
|
// src/black-forest-labs-provider.ts
|
|
387
387
|
var defaultBaseURL = "https://api.bfl.ai/v1";
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Black Forest Labs
|
|
3
|
+
description: Learn how to use Black Forest Labs models with the AI SDK.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Black Forest Labs Provider
|
|
7
|
+
|
|
8
|
+
[Black Forest Labs](https://bfl.ai/) provides a generative image platform for developers with FLUX-based models. Their platform offers fast, high quality, and in-context image generation and editing with precise and coherent results.
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
The Black Forest Labs provider is available via the `@ai-sdk/black-forest-labs` module. You can install it with
|
|
13
|
+
|
|
14
|
+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
|
|
15
|
+
<Tab>
|
|
16
|
+
<Snippet text="pnpm add @ai-sdk/black-forest-labs" dark />
|
|
17
|
+
</Tab>
|
|
18
|
+
<Tab>
|
|
19
|
+
<Snippet text="npm install @ai-sdk/black-forest-labs" dark />
|
|
20
|
+
</Tab>
|
|
21
|
+
<Tab>
|
|
22
|
+
<Snippet text="yarn add @ai-sdk/black-forest-labs" dark />
|
|
23
|
+
</Tab>
|
|
24
|
+
|
|
25
|
+
<Tab>
|
|
26
|
+
<Snippet text="bun add @ai-sdk/black-forest-labs" dark />
|
|
27
|
+
</Tab>
|
|
28
|
+
</Tabs>
|
|
29
|
+
|
|
30
|
+
## Provider Instance
|
|
31
|
+
|
|
32
|
+
You can import the default provider instance `blackForestLabs` from `@ai-sdk/black-forest-labs`:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { blackForestLabs } from '@ai-sdk/black-forest-labs';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
If you need a customized setup, you can import `createBlackForestLabs` and create a provider instance with your settings:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createBlackForestLabs } from '@ai-sdk/black-forest-labs';
|
|
42
|
+
|
|
43
|
+
const blackForestLabs = createBlackForestLabs({
|
|
44
|
+
apiKey: 'your-api-key', // optional, defaults to BFL_API_KEY environment variable
|
|
45
|
+
baseURL: 'custom-url', // optional
|
|
46
|
+
headers: {
|
|
47
|
+
/* custom headers */
|
|
48
|
+
}, // optional
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
You can use the following optional settings to customize the Black Forest Labs provider instance:
|
|
53
|
+
|
|
54
|
+
- **baseURL** _string_
|
|
55
|
+
|
|
56
|
+
Use a different URL prefix for API calls, e.g. to use a regional endpoint.
|
|
57
|
+
The default prefix is `https://api.bfl.ai/v1`.
|
|
58
|
+
|
|
59
|
+
- **apiKey** _string_
|
|
60
|
+
|
|
61
|
+
API key that is being sent using the `x-key` header.
|
|
62
|
+
It defaults to the `BFL_API_KEY` environment variable.
|
|
63
|
+
|
|
64
|
+
- **headers** _Record<string,string>_
|
|
65
|
+
|
|
66
|
+
Custom headers to include in the requests.
|
|
67
|
+
|
|
68
|
+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
|
|
69
|
+
|
|
70
|
+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
71
|
+
You can use it as a middleware to intercept requests,
|
|
72
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
73
|
+
|
|
74
|
+
## Image Models
|
|
75
|
+
|
|
76
|
+
You can create Black Forest Labs image models using the `.image()` factory method.
|
|
77
|
+
For more on image generation with the AI SDK see [generateImage()](/docs/reference/ai-sdk-core/generate-image).
|
|
78
|
+
|
|
79
|
+
### Basic Usage
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { writeFileSync } from 'node:fs';
|
|
83
|
+
import { blackForestLabs } from '@ai-sdk/black-forest-labs';
|
|
84
|
+
import { generateImage } from 'ai';
|
|
85
|
+
|
|
86
|
+
const { image, providerMetadata } = await generateImage({
|
|
87
|
+
model: blackForestLabs.image('flux-pro-1.1'),
|
|
88
|
+
prompt: 'A serene mountain landscape at sunset',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const filename = `image-${Date.now()}.png`;
|
|
92
|
+
writeFileSync(filename, image.uint8Array);
|
|
93
|
+
console.log(`Image saved to ${filename}`);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Model Capabilities
|
|
97
|
+
|
|
98
|
+
Black Forest Labs offers many models optimized for different use cases. Here are a few popular examples. For a full list of models, see the [Black Forest Labs Models Page](https://bfl.ai/models).
|
|
99
|
+
|
|
100
|
+
| Model | Description |
|
|
101
|
+
| -------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| `flux-kontext-pro` | FLUX.1 Kontext [pro] handles both text and reference images as inputs, enabling targeted edits and complex transformations |
|
|
103
|
+
| `flux-kontext-max` | FLUX.1 Kontext [max] with improved prompt adherence and typography generation |
|
|
104
|
+
| `flux-pro-1.1-ultra` | Ultra-fast, ultra high-resolution image creation |
|
|
105
|
+
| `flux-pro-1.1` | Fast, high-quality image generation from text. |
|
|
106
|
+
|
|
107
|
+
Black Forest Labs models support aspect ratios from 3:7 (portrait) to 7:3 (landscape).
|
|
108
|
+
|
|
109
|
+
### Image Editing
|
|
110
|
+
|
|
111
|
+
Black Forest Labs Kontext models support powerful image editing capabilities using reference images. Pass input images via `prompt.images` to transform, combine, or edit existing images.
|
|
112
|
+
|
|
113
|
+
#### Single Image Editing
|
|
114
|
+
|
|
115
|
+
Transform an existing image using text prompts:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import {
|
|
119
|
+
blackForestLabs,
|
|
120
|
+
BlackForestLabsImageProviderOptions,
|
|
121
|
+
} from '@ai-sdk/black-forest-labs';
|
|
122
|
+
import { generateImage } from 'ai';
|
|
123
|
+
|
|
124
|
+
const { images } = await generateImage({
|
|
125
|
+
model: blackForestLabs.image('flux-kontext-pro'),
|
|
126
|
+
prompt: {
|
|
127
|
+
text: 'A baby elephant with a shirt that has the logo from the input image.',
|
|
128
|
+
images: [
|
|
129
|
+
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
providerOptions: {
|
|
133
|
+
blackForestLabs: {
|
|
134
|
+
width: 1024,
|
|
135
|
+
height: 768,
|
|
136
|
+
} satisfies BlackForestLabsImageProviderOptions,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Multi-Reference Editing
|
|
142
|
+
|
|
143
|
+
Combine multiple reference images for complex transformations. Black Forest Labs supports up to 10 input images:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { blackForestLabs } from '@ai-sdk/black-forest-labs';
|
|
147
|
+
import { generateImage } from 'ai';
|
|
148
|
+
|
|
149
|
+
const { images } = await generateImage({
|
|
150
|
+
model: blackForestLabs.image('flux-kontext-pro'),
|
|
151
|
+
prompt: {
|
|
152
|
+
text: 'Combine the style of image 1 with the subject of image 2',
|
|
153
|
+
images: [
|
|
154
|
+
'https://example.com/style-reference.jpg',
|
|
155
|
+
'https://example.com/subject-reference.jpg',
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
<Note>
|
|
162
|
+
Input images can be provided as URLs or base64-encoded strings. They support
|
|
163
|
+
up to 20MB or 20 megapixels per image.
|
|
164
|
+
</Note>
|
|
165
|
+
|
|
166
|
+
### Provider Options
|
|
167
|
+
|
|
168
|
+
Black Forest Labs image models support flexible provider options through the `providerOptions.blackForestLabs` object. The supported parameters depend on the used model ID:
|
|
169
|
+
|
|
170
|
+
- **width** _number_ - Output width in pixels (256–1920). When set, this overrides any width derived from `size`.
|
|
171
|
+
- **height** _number_ - Output height in pixels (256–1920). When set, this overrides any height derived from `size`.
|
|
172
|
+
- **outputFormat** _string_ - Desired format of the output image (`"jpeg"` or `"png"`).
|
|
173
|
+
- **steps** _number_ - Number of inference steps. Higher values may improve quality but increase generation time.
|
|
174
|
+
- **guidance** _number_ - Guidance scale for generation. Higher values follow the prompt more closely.
|
|
175
|
+
- **imagePrompt** _string_ - Base64-encoded image to use as additional visual context for generation.
|
|
176
|
+
- **imagePromptStrength** _number_ - Strength of the image prompt influence on generation (0.0 to 1.0).
|
|
177
|
+
- **promptUpsampling** _boolean_ - If true, performs upsampling on the prompt.
|
|
178
|
+
- **raw** _boolean_ - Enable raw mode for more natural, authentic aesthetics.
|
|
179
|
+
- **safetyTolerance** _number_ - Moderation level for inputs and outputs (0 = most strict, 6 = more permissive).
|
|
180
|
+
- **pollIntervalMillis** _number_ - Interval in milliseconds between polling attempts (default 500ms).
|
|
181
|
+
- **pollTimeoutMillis** _number_ - Overall timeout in milliseconds for polling before timing out (default 60s).
|
|
182
|
+
- **webhookUrl** _string_ - URL for asynchronous completion notification. Must be a valid HTTP/HTTPS URL.
|
|
183
|
+
- **webhookSecret** _string_ - Secret for webhook signature verification, sent in the `X-Webhook-Secret` header.
|
|
184
|
+
|
|
185
|
+
<Note>
|
|
186
|
+
To pass reference images for editing, use `prompt.images` instead of provider
|
|
187
|
+
options. This supports up to 10 images as URLs or base64-encoded strings.
|
|
188
|
+
</Note>
|
|
189
|
+
|
|
190
|
+
### Regional Endpoints
|
|
191
|
+
|
|
192
|
+
By default, requests are sent to `https://api.bfl.ai/v1`. You can select a [regional endpoint](https://docs.bfl.ai/api_integration/integration_guidelines#regional-endpoints) by setting `baseURL` when creating the provider instance:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { createBlackForestLabs } from '@ai-sdk/black-forest-labs';
|
|
196
|
+
|
|
197
|
+
const blackForestLabs = createBlackForestLabs({
|
|
198
|
+
baseURL: 'https://api.eu.bfl.ai/v1', // or https://api.us.bfl.ai/v1
|
|
199
|
+
});
|
|
200
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/black-forest-labs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-98261322-20260122142521",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,8 +8,13 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
11
|
+
"docs/**/*",
|
|
12
|
+
"src",
|
|
11
13
|
"CHANGELOG.md"
|
|
12
14
|
],
|
|
15
|
+
"directories": {
|
|
16
|
+
"doc": "./docs"
|
|
17
|
+
},
|
|
13
18
|
"exports": {
|
|
14
19
|
"./package.json": "./package.json",
|
|
15
20
|
".": {
|
|
@@ -19,15 +24,15 @@
|
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@ai-sdk/provider": "
|
|
23
|
-
"@ai-sdk/provider-utils": "
|
|
27
|
+
"@ai-sdk/provider": "3.0.4",
|
|
28
|
+
"@ai-sdk/provider-utils": "4.0.8"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"@types/node": "20.17.24",
|
|
27
32
|
"tsup": "^8",
|
|
28
33
|
"typescript": "5.8.3",
|
|
29
34
|
"zod": "3.25.76",
|
|
30
|
-
"@ai-sdk/test-server": "1.0.
|
|
35
|
+
"@ai-sdk/test-server": "1.0.2",
|
|
31
36
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
32
37
|
},
|
|
33
38
|
"peerDependencies": {
|
|
@@ -53,7 +58,7 @@
|
|
|
53
58
|
"scripts": {
|
|
54
59
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
55
60
|
"build:watch": "pnpm clean && tsup --watch",
|
|
56
|
-
"clean": "del-cli dist *.tsbuildinfo",
|
|
61
|
+
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
57
62
|
"lint": "eslint \"./**/*.ts*\"",
|
|
58
63
|
"type-check": "tsc --build",
|
|
59
64
|
"prettier-check": "prettier --check \"./**/*.ts*\"",
|