@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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';
|
|
2
|
+
import type { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import {
|
|
4
|
+
loadApiKey,
|
|
5
|
+
withoutTrailingSlash,
|
|
6
|
+
withUserAgentSuffix,
|
|
7
|
+
} from '@ai-sdk/provider-utils';
|
|
8
|
+
import { BlackForestLabsImageModel } from './black-forest-labs-image-model';
|
|
9
|
+
import { BlackForestLabsImageModelId } from './black-forest-labs-image-settings';
|
|
10
|
+
import { VERSION } from './version';
|
|
11
|
+
|
|
12
|
+
export interface BlackForestLabsProviderSettings {
|
|
13
|
+
/**
|
|
14
|
+
Black Forest Labs API key. Default value is taken from the `BFL_API_KEY` environment variable.
|
|
15
|
+
*/
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
Base URL for the API calls. Defaults to `https://api.bfl.ai/v1`.
|
|
20
|
+
*/
|
|
21
|
+
baseURL?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
Custom headers to include in the requests.
|
|
25
|
+
*/
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
Custom fetch implementation. You can use it as a middleware to intercept
|
|
30
|
+
requests, or to provide a custom fetch implementation for e.g. testing.
|
|
31
|
+
*/
|
|
32
|
+
fetch?: FetchFunction;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
Poll interval in milliseconds between status checks. Defaults to 500ms.
|
|
36
|
+
*/
|
|
37
|
+
pollIntervalMillis?: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
Overall timeout in milliseconds for polling before giving up. Defaults to 60s.
|
|
41
|
+
*/
|
|
42
|
+
pollTimeoutMillis?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface BlackForestLabsProvider extends ProviderV3 {
|
|
46
|
+
/**
|
|
47
|
+
Creates a model for image generation.
|
|
48
|
+
*/
|
|
49
|
+
image(modelId: BlackForestLabsImageModelId): ImageModelV3;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
Creates a model for image generation.
|
|
53
|
+
*/
|
|
54
|
+
imageModel(modelId: BlackForestLabsImageModelId): ImageModelV3;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use `embeddingModel` instead.
|
|
58
|
+
*/
|
|
59
|
+
textEmbeddingModel(modelId: string): never;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const defaultBaseURL = 'https://api.bfl.ai/v1';
|
|
63
|
+
|
|
64
|
+
export function createBlackForestLabs(
|
|
65
|
+
options: BlackForestLabsProviderSettings = {},
|
|
66
|
+
): BlackForestLabsProvider {
|
|
67
|
+
const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);
|
|
68
|
+
const getHeaders = () =>
|
|
69
|
+
withUserAgentSuffix(
|
|
70
|
+
{
|
|
71
|
+
'x-key': loadApiKey({
|
|
72
|
+
apiKey: options.apiKey,
|
|
73
|
+
environmentVariableName: 'BFL_API_KEY',
|
|
74
|
+
description: 'Black Forest Labs',
|
|
75
|
+
}),
|
|
76
|
+
...options.headers,
|
|
77
|
+
},
|
|
78
|
+
`ai-sdk/black-forest-labs/${VERSION}`,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const createImageModel = (modelId: BlackForestLabsImageModelId) =>
|
|
82
|
+
new BlackForestLabsImageModel(modelId, {
|
|
83
|
+
provider: 'black-forest-labs.image',
|
|
84
|
+
baseURL: baseURL ?? defaultBaseURL,
|
|
85
|
+
headers: getHeaders,
|
|
86
|
+
fetch: options.fetch,
|
|
87
|
+
pollIntervalMillis: options.pollIntervalMillis,
|
|
88
|
+
pollTimeoutMillis: options.pollTimeoutMillis,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const embeddingModel = (modelId: string) => {
|
|
92
|
+
throw new NoSuchModelError({
|
|
93
|
+
modelId,
|
|
94
|
+
modelType: 'embeddingModel',
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
specificationVersion: 'v3',
|
|
100
|
+
imageModel: createImageModel,
|
|
101
|
+
image: createImageModel,
|
|
102
|
+
languageModel: (modelId: string) => {
|
|
103
|
+
throw new NoSuchModelError({
|
|
104
|
+
modelId,
|
|
105
|
+
modelType: 'languageModel',
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
embeddingModel,
|
|
109
|
+
textEmbeddingModel: embeddingModel,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const blackForestLabs = createBlackForestLabs();
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createBlackForestLabs,
|
|
3
|
+
blackForestLabs,
|
|
4
|
+
} from './black-forest-labs-provider';
|
|
5
|
+
export type {
|
|
6
|
+
BlackForestLabsProvider,
|
|
7
|
+
BlackForestLabsProviderSettings,
|
|
8
|
+
} from './black-forest-labs-provider';
|
|
9
|
+
export type {
|
|
10
|
+
BlackForestLabsImageModelId,
|
|
11
|
+
BlackForestLabsAspectRatio,
|
|
12
|
+
} from './black-forest-labs-image-settings';
|
|
13
|
+
export type { BlackForestLabsImageProviderOptions } from './black-forest-labs-image-model';
|
|
14
|
+
export { VERSION } from './version';
|