@ai-sdk/fireworks 0.0.0-156c9f7b-20250115085202 → 0.0.0-4115c213-20260122152721

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": "@ai-sdk/fireworks",
3
- "version": "0.0.0-156c9f7b-20250115085202",
3
+ "version": "0.0.0-4115c213-20260122152721",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -8,8 +8,18 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
11
- "CHANGELOG.md"
11
+ "docs/**/*",
12
+ "src",
13
+ "!src/**/*.test.ts",
14
+ "!src/**/*.test-d.ts",
15
+ "!src/**/__snapshots__",
16
+ "!src/**/__fixtures__",
17
+ "CHANGELOG.md",
18
+ "README.md"
12
19
  ],
20
+ "directories": {
21
+ "doc": "./docs"
22
+ },
13
23
  "exports": {
14
24
  "./package.json": "./package.json",
15
25
  ".": {
@@ -19,19 +29,20 @@
19
29
  }
20
30
  },
21
31
  "dependencies": {
22
- "@ai-sdk/openai-compatible": "0.0.16",
23
- "@ai-sdk/provider": "1.0.4",
24
- "@ai-sdk/provider-utils": "2.0.7"
32
+ "@ai-sdk/openai-compatible": "0.0.0-4115c213-20260122152721",
33
+ "@ai-sdk/provider": "0.0.0-4115c213-20260122152721",
34
+ "@ai-sdk/provider-utils": "0.0.0-4115c213-20260122152721"
25
35
  },
26
36
  "devDependencies": {
27
- "@types/node": "^18",
37
+ "@types/node": "20.17.24",
28
38
  "tsup": "^8",
29
- "typescript": "5.6.3",
30
- "zod": "3.23.8",
39
+ "typescript": "5.8.3",
40
+ "zod": "3.25.76",
41
+ "@ai-sdk/test-server": "0.0.0-4115c213-20260122152721",
31
42
  "@vercel/ai-tsconfig": "0.0.0"
32
43
  },
33
44
  "peerDependencies": {
34
- "zod": "^3.0.0"
45
+ "zod": "^3.25.76 || ^4.1.8"
35
46
  },
36
47
  "engines": {
37
48
  "node": ">=18"
@@ -39,7 +50,7 @@
39
50
  "publishConfig": {
40
51
  "access": "public"
41
52
  },
42
- "homepage": "https://sdk.vercel.ai/docs",
53
+ "homepage": "https://ai-sdk.dev/docs",
43
54
  "repository": {
44
55
  "type": "git",
45
56
  "url": "git+https://github.com/vercel/ai.git"
@@ -51,13 +62,15 @@
51
62
  "ai"
52
63
  ],
53
64
  "scripts": {
54
- "build": "tsup",
55
- "build:watch": "tsup --watch",
56
- "clean": "rm -rf dist",
65
+ "build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
66
+ "build:watch": "pnpm clean && tsup --watch",
67
+ "clean": "del-cli dist docs *.tsbuildinfo",
57
68
  "lint": "eslint \"./**/*.ts*\"",
58
- "type-check": "tsc --noEmit",
69
+ "type-check": "tsc --build",
59
70
  "prettier-check": "prettier --check \"./**/*.ts*\"",
60
71
  "test": "pnpm test:node && pnpm test:edge",
72
+ "test:update": "pnpm test:node -u",
73
+ "test:watch": "vitest --config vitest.node.config.js",
61
74
  "test:edge": "vitest --config vitest.edge.config.js --run",
62
75
  "test:node": "vitest --config vitest.node.config.js --run"
63
76
  }
@@ -0,0 +1,20 @@
1
+ // https://docs.fireworks.ai/docs/serverless-models#chat-models
2
+ // Below is just a subset of the available models.
3
+ export type FireworksChatModelId =
4
+ | 'accounts/fireworks/models/deepseek-v3'
5
+ | 'accounts/fireworks/models/llama-v3p3-70b-instruct'
6
+ | 'accounts/fireworks/models/llama-v3p2-3b-instruct'
7
+ | 'accounts/fireworks/models/llama-v3p1-405b-instruct'
8
+ | 'accounts/fireworks/models/llama-v3p1-8b-instruct'
9
+ | 'accounts/fireworks/models/mixtral-8x7b-instruct'
10
+ | 'accounts/fireworks/models/mixtral-8x22b-instruct'
11
+ | 'accounts/fireworks/models/mixtral-8x7b-instruct-hf'
12
+ | 'accounts/fireworks/models/qwen2p5-coder-32b-instruct'
13
+ | 'accounts/fireworks/models/qwen2p5-72b-instruct'
14
+ | 'accounts/fireworks/models/qwen-qwq-32b-preview'
15
+ | 'accounts/fireworks/models/qwen2-vl-72b-instruct'
16
+ | 'accounts/fireworks/models/llama-v3p2-11b-vision-instruct'
17
+ | 'accounts/fireworks/models/qwq-32b'
18
+ | 'accounts/fireworks/models/yi-large'
19
+ | 'accounts/fireworks/models/kimi-k2-instruct'
20
+ | (string & {});
@@ -0,0 +1,5 @@
1
+ // Below is just a subset of the available models.
2
+ export type FireworksCompletionModelId =
3
+ | 'accounts/fireworks/models/llama-v3-8b-instruct'
4
+ | 'accounts/fireworks/models/llama-v2-34b-code'
5
+ | (string & {});
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod/v4';
2
+
3
+ // Below is just a subset of the available models.
4
+ export type FireworksEmbeddingModelId =
5
+ | 'nomic-ai/nomic-embed-text-v1.5'
6
+ | (string & {});
7
+
8
+ export const fireworksEmbeddingProviderOptions = z.object({});
9
+
10
+ export type FireworksEmbeddingProviderOptions = z.infer<
11
+ typeof fireworksEmbeddingProviderOptions
12
+ >;
@@ -0,0 +1,196 @@
1
+ import { ImageModelV3, SharedV3Warning } from '@ai-sdk/provider';
2
+ import {
3
+ combineHeaders,
4
+ convertImageModelFileToDataUri,
5
+ createBinaryResponseHandler,
6
+ createStatusCodeErrorResponseHandler,
7
+ FetchFunction,
8
+ postJsonToApi,
9
+ } from '@ai-sdk/provider-utils';
10
+ import { FireworksImageModelId } from './fireworks-image-options';
11
+
12
+ interface FireworksImageModelBackendConfig {
13
+ urlFormat: 'workflows' | 'workflows_edit' | 'image_generation';
14
+ supportsSize?: boolean;
15
+ supportsEditing?: boolean;
16
+ }
17
+
18
+ const modelToBackendConfig: Partial<
19
+ Record<FireworksImageModelId, FireworksImageModelBackendConfig>
20
+ > = {
21
+ 'accounts/fireworks/models/flux-1-dev-fp8': {
22
+ urlFormat: 'workflows',
23
+ },
24
+ 'accounts/fireworks/models/flux-1-schnell-fp8': {
25
+ urlFormat: 'workflows',
26
+ },
27
+ 'accounts/fireworks/models/flux-kontext-pro': {
28
+ urlFormat: 'workflows_edit',
29
+ supportsEditing: true,
30
+ },
31
+ 'accounts/fireworks/models/flux-kontext-max': {
32
+ urlFormat: 'workflows_edit',
33
+ supportsEditing: true,
34
+ },
35
+ 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic': {
36
+ urlFormat: 'image_generation',
37
+ supportsSize: true,
38
+ },
39
+ 'accounts/fireworks/models/japanese-stable-diffusion-xl': {
40
+ urlFormat: 'image_generation',
41
+ supportsSize: true,
42
+ },
43
+ 'accounts/fireworks/models/playground-v2-1024px-aesthetic': {
44
+ urlFormat: 'image_generation',
45
+ supportsSize: true,
46
+ },
47
+ 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0': {
48
+ urlFormat: 'image_generation',
49
+ supportsSize: true,
50
+ },
51
+ 'accounts/fireworks/models/SSD-1B': {
52
+ urlFormat: 'image_generation',
53
+ supportsSize: true,
54
+ },
55
+ };
56
+
57
+ function getUrlForModel(
58
+ baseUrl: string,
59
+ modelId: FireworksImageModelId,
60
+ hasInputImage: boolean,
61
+ ): string {
62
+ const config = modelToBackendConfig[modelId];
63
+
64
+ switch (config?.urlFormat) {
65
+ case 'image_generation':
66
+ return `${baseUrl}/image_generation/${modelId}`;
67
+ case 'workflows_edit':
68
+ // Kontext models: use base URL for editing (no suffix)
69
+ return `${baseUrl}/workflows/${modelId}`;
70
+ case 'workflows':
71
+ default:
72
+ // Standard FLUX models: use text_to_image for generation,
73
+ // but if input_image provided, some models may support editing
74
+ if (hasInputImage && config?.supportsEditing) {
75
+ return `${baseUrl}/workflows/${modelId}`;
76
+ }
77
+ return `${baseUrl}/workflows/${modelId}/text_to_image`;
78
+ }
79
+ }
80
+
81
+ interface FireworksImageModelConfig {
82
+ provider: string;
83
+ baseURL: string;
84
+ headers: () => Record<string, string>;
85
+ fetch?: FetchFunction;
86
+ _internal?: {
87
+ currentDate?: () => Date;
88
+ };
89
+ }
90
+
91
+ export class FireworksImageModel implements ImageModelV3 {
92
+ readonly specificationVersion = 'v3';
93
+ readonly maxImagesPerCall = 1;
94
+
95
+ get provider(): string {
96
+ return this.config.provider;
97
+ }
98
+
99
+ constructor(
100
+ readonly modelId: FireworksImageModelId,
101
+ private config: FireworksImageModelConfig,
102
+ ) {}
103
+
104
+ async doGenerate({
105
+ prompt,
106
+ n,
107
+ size,
108
+ aspectRatio,
109
+ seed,
110
+ providerOptions,
111
+ headers,
112
+ abortSignal,
113
+ files,
114
+ mask,
115
+ }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<
116
+ Awaited<ReturnType<ImageModelV3['doGenerate']>>
117
+ > {
118
+ const warnings: Array<SharedV3Warning> = [];
119
+
120
+ const backendConfig = modelToBackendConfig[this.modelId];
121
+ if (!backendConfig?.supportsSize && size != null) {
122
+ warnings.push({
123
+ type: 'unsupported',
124
+ feature: 'size',
125
+ details:
126
+ 'This model does not support the `size` option. Use `aspectRatio` instead.',
127
+ });
128
+ }
129
+
130
+ // Use supportsSize as a proxy for whether the model does not support
131
+ // aspectRatio. This invariant holds for the current set of models.
132
+ if (backendConfig?.supportsSize && aspectRatio != null) {
133
+ warnings.push({
134
+ type: 'unsupported',
135
+ feature: 'aspectRatio',
136
+ details: 'This model does not support the `aspectRatio` option.',
137
+ });
138
+ }
139
+
140
+ // Handle files for image editing
141
+ const hasInputImage = files != null && files.length > 0;
142
+ let inputImage: string | undefined;
143
+
144
+ if (hasInputImage) {
145
+ inputImage = convertImageModelFileToDataUri(files[0]);
146
+
147
+ if (files.length > 1) {
148
+ warnings.push({
149
+ type: 'other',
150
+ message:
151
+ 'Fireworks only supports a single input image. Additional images are ignored.',
152
+ });
153
+ }
154
+ }
155
+
156
+ // Warn about mask - Fireworks Kontext models don't support explicit masks
157
+ if (mask != null) {
158
+ warnings.push({
159
+ type: 'unsupported',
160
+ feature: 'mask',
161
+ details:
162
+ 'Fireworks Kontext models do not support explicit masks. Use the prompt to describe the areas to edit.',
163
+ });
164
+ }
165
+
166
+ const splitSize = size?.split('x');
167
+ const currentDate = this.config._internal?.currentDate?.() ?? new Date();
168
+ const { value: response, responseHeaders } = await postJsonToApi({
169
+ url: getUrlForModel(this.config.baseURL, this.modelId, hasInputImage),
170
+ headers: combineHeaders(this.config.headers(), headers),
171
+ body: {
172
+ prompt,
173
+ aspect_ratio: aspectRatio,
174
+ seed,
175
+ samples: n,
176
+ ...(inputImage && { input_image: inputImage }),
177
+ ...(splitSize && { width: splitSize[0], height: splitSize[1] }),
178
+ ...(providerOptions.fireworks ?? {}),
179
+ },
180
+ failedResponseHandler: createStatusCodeErrorResponseHandler(),
181
+ successfulResponseHandler: createBinaryResponseHandler(),
182
+ abortSignal,
183
+ fetch: this.config.fetch,
184
+ });
185
+
186
+ return {
187
+ images: [response],
188
+ warnings,
189
+ response: {
190
+ timestamp: currentDate,
191
+ modelId: this.modelId,
192
+ headers: responseHeaders,
193
+ },
194
+ };
195
+ }
196
+ }
@@ -0,0 +1,12 @@
1
+ // https://fireworks.ai/models?type=image
2
+ export type FireworksImageModelId =
3
+ | 'accounts/fireworks/models/flux-1-dev-fp8'
4
+ | 'accounts/fireworks/models/flux-1-schnell-fp8'
5
+ | 'accounts/fireworks/models/flux-kontext-pro'
6
+ | 'accounts/fireworks/models/flux-kontext-max'
7
+ | 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic'
8
+ | 'accounts/fireworks/models/japanese-stable-diffusion-xl'
9
+ | 'accounts/fireworks/models/playground-v2-1024px-aesthetic'
10
+ | 'accounts/fireworks/models/SSD-1B'
11
+ | 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0'
12
+ | (string & {});
@@ -0,0 +1,172 @@
1
+ import {
2
+ OpenAICompatibleChatLanguageModel,
3
+ OpenAICompatibleCompletionLanguageModel,
4
+ OpenAICompatibleEmbeddingModel,
5
+ ProviderErrorStructure,
6
+ } from '@ai-sdk/openai-compatible';
7
+ import {
8
+ EmbeddingModelV3,
9
+ ImageModelV3,
10
+ LanguageModelV3,
11
+ ProviderV3,
12
+ } from '@ai-sdk/provider';
13
+ import {
14
+ FetchFunction,
15
+ loadApiKey,
16
+ withoutTrailingSlash,
17
+ withUserAgentSuffix,
18
+ } from '@ai-sdk/provider-utils';
19
+ import { z } from 'zod/v4';
20
+ import { FireworksChatModelId } from './fireworks-chat-options';
21
+ import { FireworksCompletionModelId } from './fireworks-completion-options';
22
+ import { FireworksEmbeddingModelId } from './fireworks-embedding-options';
23
+ import { FireworksImageModel } from './fireworks-image-model';
24
+ import { FireworksImageModelId } from './fireworks-image-options';
25
+ import { VERSION } from './version';
26
+
27
+ export type FireworksErrorData = z.infer<typeof fireworksErrorSchema>;
28
+
29
+ const fireworksErrorSchema = z.object({
30
+ error: z.string(),
31
+ });
32
+
33
+ const fireworksErrorStructure: ProviderErrorStructure<FireworksErrorData> = {
34
+ errorSchema: fireworksErrorSchema,
35
+ errorToMessage: data => data.error,
36
+ };
37
+
38
+ export interface FireworksProviderSettings {
39
+ /**
40
+ Fireworks API key. Default value is taken from the `FIREWORKS_API_KEY`
41
+ environment variable.
42
+ */
43
+ apiKey?: string;
44
+ /**
45
+ Base URL for the API calls.
46
+ */
47
+ baseURL?: string;
48
+ /**
49
+ Custom headers to include in the requests.
50
+ */
51
+ headers?: Record<string, string>;
52
+ /**
53
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
54
+ or to provide a custom fetch implementation for e.g. testing.
55
+ */
56
+ fetch?: FetchFunction;
57
+ }
58
+
59
+ export interface FireworksProvider extends ProviderV3 {
60
+ /**
61
+ Creates a model for text generation.
62
+ */
63
+ (modelId: FireworksChatModelId): LanguageModelV3;
64
+
65
+ /**
66
+ Creates a chat model for text generation.
67
+ */
68
+ chatModel(modelId: FireworksChatModelId): LanguageModelV3;
69
+
70
+ /**
71
+ Creates a completion model for text generation.
72
+ */
73
+ completionModel(modelId: FireworksCompletionModelId): LanguageModelV3;
74
+
75
+ /**
76
+ Creates a chat model for text generation.
77
+ */
78
+ languageModel(modelId: FireworksChatModelId): LanguageModelV3;
79
+
80
+ /**
81
+ Creates a text embedding model for text generation.
82
+ */
83
+ embeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV3;
84
+
85
+ /**
86
+ * @deprecated Use `embeddingModel` instead.
87
+ */
88
+ textEmbeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV3;
89
+
90
+ /**
91
+ Creates a model for image generation.
92
+ */
93
+ image(modelId: FireworksImageModelId): ImageModelV3;
94
+
95
+ /**
96
+ Creates a model for image generation.
97
+ */
98
+ imageModel(modelId: FireworksImageModelId): ImageModelV3;
99
+ }
100
+
101
+ const defaultBaseURL = 'https://api.fireworks.ai/inference/v1';
102
+
103
+ export function createFireworks(
104
+ options: FireworksProviderSettings = {},
105
+ ): FireworksProvider {
106
+ const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);
107
+ const getHeaders = () =>
108
+ withUserAgentSuffix(
109
+ {
110
+ Authorization: `Bearer ${loadApiKey({
111
+ apiKey: options.apiKey,
112
+ environmentVariableName: 'FIREWORKS_API_KEY',
113
+ description: 'Fireworks API key',
114
+ })}`,
115
+ ...options.headers,
116
+ },
117
+ `ai-sdk/fireworks/${VERSION}`,
118
+ );
119
+
120
+ interface CommonModelConfig {
121
+ provider: string;
122
+ url: ({ path }: { path: string }) => string;
123
+ headers: () => Record<string, string>;
124
+ fetch?: FetchFunction;
125
+ }
126
+
127
+ const getCommonModelConfig = (modelType: string): CommonModelConfig => ({
128
+ provider: `fireworks.${modelType}`,
129
+ url: ({ path }) => `${baseURL}${path}`,
130
+ headers: getHeaders,
131
+ fetch: options.fetch,
132
+ });
133
+
134
+ const createChatModel = (modelId: FireworksChatModelId) => {
135
+ return new OpenAICompatibleChatLanguageModel(modelId, {
136
+ ...getCommonModelConfig('chat'),
137
+ errorStructure: fireworksErrorStructure,
138
+ });
139
+ };
140
+
141
+ const createCompletionModel = (modelId: FireworksCompletionModelId) =>
142
+ new OpenAICompatibleCompletionLanguageModel(modelId, {
143
+ ...getCommonModelConfig('completion'),
144
+ errorStructure: fireworksErrorStructure,
145
+ });
146
+
147
+ const createEmbeddingModel = (modelId: FireworksEmbeddingModelId) =>
148
+ new OpenAICompatibleEmbeddingModel(modelId, {
149
+ ...getCommonModelConfig('embedding'),
150
+ errorStructure: fireworksErrorStructure,
151
+ });
152
+
153
+ const createImageModel = (modelId: FireworksImageModelId) =>
154
+ new FireworksImageModel(modelId, {
155
+ ...getCommonModelConfig('image'),
156
+ baseURL: baseURL ?? defaultBaseURL,
157
+ });
158
+
159
+ const provider = (modelId: FireworksChatModelId) => createChatModel(modelId);
160
+
161
+ provider.specificationVersion = 'v3' as const;
162
+ provider.completionModel = createCompletionModel;
163
+ provider.chatModel = createChatModel;
164
+ provider.languageModel = createChatModel;
165
+ provider.embeddingModel = createEmbeddingModel;
166
+ provider.textEmbeddingModel = createEmbeddingModel;
167
+ provider.image = createImageModel;
168
+ provider.imageModel = createImageModel;
169
+ return provider;
170
+ }
171
+
172
+ export const fireworks = createFireworks();
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ export type {
2
+ FireworksEmbeddingModelId,
3
+ FireworksEmbeddingProviderOptions,
4
+ } from './fireworks-embedding-options';
5
+ export { FireworksImageModel } from './fireworks-image-model';
6
+ export type { FireworksImageModelId } from './fireworks-image-options';
7
+ export { fireworks, createFireworks } from './fireworks-provider';
8
+ export type {
9
+ FireworksProvider,
10
+ FireworksProviderSettings,
11
+ FireworksErrorData,
12
+ } from './fireworks-provider';
13
+ export { VERSION } from './version';
package/src/version.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Version string of this package injected at build time.
2
+ declare const __PACKAGE_VERSION__: string | undefined;
3
+ export const VERSION: string =
4
+ typeof __PACKAGE_VERSION__ !== 'undefined'
5
+ ? __PACKAGE_VERSION__
6
+ : '0.0.0-test';