@ai-sdk/fireworks 3.0.82 → 3.0.84
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 +27 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/docs/26-fireworks.mdx +3 -5
- package/package.json +3 -3
- package/src/fireworks-provider.ts +36 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @ai-sdk/fireworks
|
|
2
2
|
|
|
3
|
+
## 3.0.84
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 61a315e: fix: map the top-level `reasoning` option consistently across providers
|
|
8
|
+
|
|
9
|
+
Providers now resolve reasoning the same way:
|
|
10
|
+
|
|
11
|
+
1. A provider-specific reasoning setting in `providerOptions` is sent unchanged. OpenAI no longer drops `providerOptions.openai.reasoningEffort` values that are not in its list for the model, and Fireworks no longer rewrites `providerOptions.fireworks.reasoningEffort`. Fireworks also sends top-level `reasoning` values directly instead of rounding them to `'high'` at most, except for model families known to reject `'none'` (GPT-OSS, GLM-5.3, Muse Spark) or `'minimal'` (Nemotron, Inkling).
|
|
12
|
+
2. Otherwise, `reasoning` maps to the closest level the model supports, rounding down, and rounds up only when there is no lower level. For example, `'xhigh'` now maps to `'high'` instead of `'max'` on Anthropic and Bedrock models without `xhigh` effort, and `'medium'` maps to `'low'` instead of `'high'` on DeepSeek, Kimi K3, and Mistral GLM-5.3 models.
|
|
13
|
+
3. `'none'` on a model that cannot disable reasoning maps to the model's lowest level with a compatibility warning, instead of being dropped or sending a request the API rejects. This affects GPT-6 models without `'none'`, xAI grok-4.5 and later, Groq GPT-OSS, Kimi K3, Perplexity, QuiverAI, Bedrock OpenAI `gpt-oss` models, and Gemini 2.5 Pro (minimum thinking budget). Gemini 3 and Anthropic and Bedrock `between_tools` mappings now emit the compatibility warning too.
|
|
14
|
+
|
|
15
|
+
`mapReasoningToProviderEffort` now accepts any `reasoning` value, returns an optional `providerOptionsEffort` unchanged, and rounds levels that are missing from the effort map to the closest supported level. `mapReasoningToProviderBudget` maps `'none'` to the minimum reasoning budget, always returns a budget, and uses the default percentage for levels missing from `budgetPercentages`. `OpenAICompatibleChatConfig` adds an optional `mapReasoning` function for mapping the top-level `reasoning` option.
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [61a315e]
|
|
18
|
+
- @ai-sdk/provider-utils@5.0.71
|
|
19
|
+
- @ai-sdk/openai-compatible@3.0.81
|
|
20
|
+
|
|
21
|
+
## 3.0.83
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [57086ff]
|
|
26
|
+
- Updated dependencies [95348b3]
|
|
27
|
+
- @ai-sdk/provider-utils@5.0.70
|
|
28
|
+
- @ai-sdk/openai-compatible@3.0.80
|
|
29
|
+
|
|
3
30
|
## 3.0.82
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/fireworks-chat-options.ts","../src/fireworks-embedding-options.ts","../src/fireworks-image-options.ts","../src/fireworks-image-model.ts","../src/fireworks-image-model-options.ts","../src/fireworks-completion-options.ts","../src/fireworks-provider.ts","../src/version.ts"],"mappings":";;;;KAIY;cAsBC,+BAA6B,EAAA;;;;;;;;;;;;;;;;;GAoBxC,EAAA,KAAA;KAEU,gCAAgC,EAAE,aACrC;;;KC9CG;cAIC,gCAA8B,EAAA,cAAA,EAAA,KAAA;KAE/B,iCAAiC,EAAE,aACtC;;;KCTG;;;UC8FF;EACR;EACA;EACA,gBAAgB;EAChB,QAAQ;;;;;EAKR;;;;;EAKA;EACA;IACE,oBAAoB;;;qBAIX,+BAA+B;WAgD/B,SAAS;UACV;WAhDD;WACA;MAEL;MAqBA;MAIA;UAII,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B,SAAS;IACT,QAAQ;MACT;EAKU,YAAA,SAAS,uBACV,QAAQ;EAGZ,aACJ,QACA,GACA,MACA,aACA,MACA,iBACA,SACA,aACA,OACA,QACC,WAAW,iCAAiC,QAC7C,QAAQ,WAAW;;;;;UA2GP;;;;UAkEA;;;;cCzVH,mEAAgC;;;;;;;;;;;;KAmDjC,6BAA6B,mBAChC;;;KC1DG;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/fireworks-chat-options.ts","../src/fireworks-embedding-options.ts","../src/fireworks-image-options.ts","../src/fireworks-image-model.ts","../src/fireworks-image-model-options.ts","../src/fireworks-completion-options.ts","../src/fireworks-provider.ts","../src/version.ts"],"mappings":";;;;KAIY;cAsBC,+BAA6B,EAAA;;;;;;;;;;;;;;;;;GAoBxC,EAAA,KAAA;KAEU,gCAAgC,EAAE,aACrC;;;KC9CG;cAIC,gCAA8B,EAAA,cAAA,EAAA,KAAA;KAE/B,iCAAiC,EAAE,aACtC;;;KCTG;;;UC8FF;EACR;EACA;EACA,gBAAgB;EAChB,QAAQ;;;;;EAKR;;;;;EAKA;EACA;IACE,oBAAoB;;;qBAIX,+BAA+B;WAgD/B,SAAS;UACV;WAhDD;WACA;MAEL;MAqBA;MAIA;UAII,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B,SAAS;IACT,QAAQ;MACT;EAKU,YAAA,SAAS,uBACV,QAAQ;EAGZ,aACJ,QACA,GACA,MACA,aACA,MACA,iBACA,SACA,aACA,OACA,QACC,WAAW,iCAAiC,QAC7C,QAAQ,WAAW;;;;;UA2GP;;;;UAkEA;;;;cCzVH,mEAAgC;;;;;;;;;;;;KAmDjC,6BAA6B,mBAChC;;;KC1DG;;;KC0BA,qBAAqB,EAAE,aAAa;cAE1C,sBAAoB,EAAA;;;;;;;;GAWxB,EAAA,KAAA;UAQe;;;;;EAKf;;;;EAIA;;;;EAIA,UAAU;;;;;EAKV,QAAQ;;UAGO,0BAA0B;;;;GAIxC,SAAS,uBAAuB;;;;EAKjC,UAAU,SAAS,uBAAuB;;;;EAK1C,gBAAgB,SAAS,6BAA6B;;;;EAKtD,cAAc,SAAS,uBAAuB;;;;EAK9C,eAAe,SAAS,4BAA4B;;;;EAKpD,mBAAmB,SAAS,4BAA4B;;;;EAKxD,MAAM,SAAS,wBAAwB;;;;EAKvC,WAAW,SAAS,wBAAwB;;wBAK9B,gBACd,UAAS,4BACR;qBAiHU,WAAS;;;qBClOT"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertImageModelFileToDataUri, createBinaryResponseHandler, createJsonResponseHandler, createStatusCodeErrorResponseHandler, delay, getFromApi, lazySchema, loadApiKey, parseProviderOptions, postJsonToApi, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
1
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertImageModelFileToDataUri, createBinaryResponseHandler, createJsonResponseHandler, createStatusCodeErrorResponseHandler, delay, getFromApi, lazySchema, loadApiKey, mapReasoningToProviderEffort, parseProviderOptions, postJsonToApi, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
3
|
import { OpenAICompatibleChatLanguageModel, OpenAICompatibleCompletionLanguageModel, OpenAICompatibleEmbeddingModel } from "@ai-sdk/openai-compatible";
|
|
4
4
|
//#region src/fireworks-image-api.ts
|
|
@@ -286,7 +286,7 @@ var FireworksImageModel = class FireworksImageModel {
|
|
|
286
286
|
};
|
|
287
287
|
//#endregion
|
|
288
288
|
//#region src/version.ts
|
|
289
|
-
const VERSION = "3.0.
|
|
289
|
+
const VERSION = "3.0.84";
|
|
290
290
|
//#endregion
|
|
291
291
|
//#region src/fireworks-provider.ts
|
|
292
292
|
const fireworksErrorStructure = {
|
|
@@ -322,21 +322,19 @@ function createFireworks(options = {}) {
|
|
|
322
322
|
includeUsage: true,
|
|
323
323
|
errorStructure: fireworksErrorStructure,
|
|
324
324
|
supportsStructuredOutputs: true,
|
|
325
|
-
|
|
325
|
+
mapReasoning: ({ reasoning, warnings }) => mapReasoningToProviderEffort({
|
|
326
|
+
reasoning,
|
|
327
|
+
effortMap: getFireworksReasoningEffortMap(modelId),
|
|
328
|
+
warnings
|
|
329
|
+
}),
|
|
330
|
+
transformRequestBody: (args) => {
|
|
326
331
|
const thinking = args.thinking;
|
|
327
332
|
const reasoningHistory = args.reasoningHistory;
|
|
328
333
|
const promptCacheKey = args.promptCacheKey;
|
|
329
334
|
const serviceTier = args.serviceTier;
|
|
330
|
-
const { thinking: _, reasoningHistory: __, promptCacheKey: ___, serviceTier: ____,
|
|
331
|
-
const mappedReasoningEffort = reasoning_effort === "minimal" ? "low" : reasoning_effort === "xhigh" || reasoning_effort === "max" ? "high" : reasoning_effort;
|
|
332
|
-
if (mappedReasoningEffort !== reasoning_effort) warnings?.push({
|
|
333
|
-
type: "compatibility",
|
|
334
|
-
feature: "reasoning",
|
|
335
|
-
details: `reasoning "${reasoning_effort}" is not directly supported by this model. mapped to effort "${mappedReasoningEffort}".`
|
|
336
|
-
});
|
|
335
|
+
const { thinking: _, reasoningHistory: __, promptCacheKey: ___, serviceTier: ____, ...rest } = args;
|
|
337
336
|
return {
|
|
338
337
|
...rest,
|
|
339
|
-
...reasoning_effort != null && { reasoning_effort: mappedReasoningEffort },
|
|
340
338
|
...promptCacheKey !== void 0 && { prompt_cache_key: promptCacheKey },
|
|
341
339
|
...serviceTier !== void 0 && { service_tier: serviceTier },
|
|
342
340
|
...thinking && { thinking: {
|
|
@@ -373,6 +371,24 @@ function createFireworks(options = {}) {
|
|
|
373
371
|
return provider;
|
|
374
372
|
}
|
|
375
373
|
const fireworks = createFireworks();
|
|
374
|
+
const modelsWithoutNoneReasoningEffort = /^(?:gpt-oss|glm-5p3|muse-spark)/;
|
|
375
|
+
const modelsWithoutMinimalReasoningEffort = /^(?:nemotron|inkling)/;
|
|
376
|
+
/**
|
|
377
|
+
* Fireworks accepts every reasoning effort for most models, so reasoning
|
|
378
|
+
* values are sent directly, except to model families known to reject them.
|
|
379
|
+
*/
|
|
380
|
+
function getFireworksReasoningEffortMap(modelId) {
|
|
381
|
+
const modelName = modelId.slice(modelId.lastIndexOf("/") + 1);
|
|
382
|
+
return {
|
|
383
|
+
...!modelsWithoutNoneReasoningEffort.test(modelName) && { none: "none" },
|
|
384
|
+
...!modelsWithoutMinimalReasoningEffort.test(modelName) && { minimal: "minimal" },
|
|
385
|
+
low: "low",
|
|
386
|
+
medium: "medium",
|
|
387
|
+
high: "high",
|
|
388
|
+
xhigh: "xhigh",
|
|
389
|
+
max: "max"
|
|
390
|
+
};
|
|
391
|
+
}
|
|
376
392
|
//#endregion
|
|
377
393
|
export { FireworksImageModel, VERSION, createFireworks, fireworks };
|
|
378
394
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/fireworks-image-api.ts","../src/fireworks-image-model-options.ts","../src/fireworks-image-model.ts","../src/version.ts","../src/fireworks-provider.ts"],"sourcesContent":["import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\n// Schema for async submit response\nexport const asyncSubmitResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n request_id: z.string(),\n }),\n ),\n);\n\n// Schema for async poll response\nexport const asyncPollResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n status: z.string(),\n result: z\n .object({\n sample: z.string().optional(),\n })\n .nullable(),\n }),\n ),\n);\n","import {\n lazySchema,\n zodSchema,\n type InferSchema,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport const fireworksImageModelOptionsSchema = lazySchema(() =>\n zodSchema(\n z.looseObject({\n /**\n * Classifier-free guidance scale for the image diffusion process.\n */\n guidance_scale: z.number().optional(),\n\n /**\n * Number of denoising steps for the image generation process.\n */\n num_inference_steps: z.number().int().optional(),\n\n /**\n * Desired output image format.\n */\n output_format: z.enum(['jpeg', 'png']).optional(),\n\n /**\n * URL to receive webhook notifications for async Kontext requests.\n */\n webhook_url: z.string().optional(),\n\n /**\n * Secret for webhook signature verification.\n */\n webhook_secret: z.string().optional(),\n\n /**\n * Whether Fireworks should automatically modify the prompt for more creative generation.\n */\n prompt_upsampling: z.boolean().optional(),\n\n /**\n * Moderation tolerance level for inputs and outputs.\n */\n safety_tolerance: z.number().int().min(0).max(6).optional(),\n\n /**\n * Guidance scale for legacy image_generation models.\n */\n cfg_scale: z.number().optional(),\n\n /**\n * Number of generation steps for legacy image_generation models.\n */\n steps: z.number().int().optional(),\n }),\n ),\n);\n\nexport type FireworksImageModelOptions = InferSchema<\n typeof fireworksImageModelOptionsSchema\n>;\n","import type { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n convertImageModelFileToDataUri,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n parseProviderOptions,\n postJsonToApi,\n serializeModelOptions,\n WORKFLOW_SERIALIZE,\n WORKFLOW_DESERIALIZE,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n asyncPollResponseSchema,\n asyncSubmitResponseSchema,\n} from './fireworks-image-api';\nimport { fireworksImageModelOptionsSchema } from './fireworks-image-model-options';\nimport type { FireworksImageModelId } from './fireworks-image-options';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_POLL_TIMEOUT_MILLIS = 120000; // 2 minutes for image generation\n\ninterface FireworksImageModelBackendConfig {\n urlFormat: 'workflows' | 'workflows_async' | 'image_generation';\n supportsSize?: boolean;\n supportsEditing?: boolean;\n}\n\nconst modelToBackendConfig: Partial<\n Record<FireworksImageModelId, FireworksImageModelBackendConfig>\n> = {\n 'accounts/fireworks/models/flux-1-dev-fp8': {\n urlFormat: 'workflows',\n },\n 'accounts/fireworks/models/flux-1-schnell-fp8': {\n urlFormat: 'workflows',\n },\n 'accounts/fireworks/models/flux-kontext-pro': {\n urlFormat: 'workflows_async',\n supportsEditing: true,\n },\n 'accounts/fireworks/models/flux-kontext-max': {\n urlFormat: 'workflows_async',\n supportsEditing: true,\n },\n 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/japanese-stable-diffusion-xl': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/playground-v2-1024px-aesthetic': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/SSD-1B': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n};\n\nfunction getUrlForModel(\n baseUrl: string,\n modelId: FireworksImageModelId,\n): string {\n const config = modelToBackendConfig[modelId];\n\n switch (config?.urlFormat) {\n case 'image_generation':\n return `${baseUrl}/image_generation/${modelId}`;\n case 'workflows_async':\n return `${baseUrl}/workflows/${modelId}`;\n case 'workflows':\n default:\n return `${baseUrl}/workflows/${modelId}/text_to_image`;\n }\n}\n\nfunction getPollUrlForModel(\n baseUrl: string,\n modelId: FireworksImageModelId,\n): string {\n return `${baseUrl}/workflows/${modelId}/get_result`;\n}\n\ninterface FireworksImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: () => Record<string, string>;\n fetch?: FetchFunction;\n /**\n * Poll interval in milliseconds between status checks for async models.\n * Defaults to 500ms.\n */\n pollIntervalMillis?: number;\n /**\n * Overall timeout in milliseconds for polling before giving up.\n * Defaults to 120000ms (2 minutes).\n */\n pollTimeoutMillis?: number;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class FireworksImageModel implements ImageModelV4 {\n readonly specificationVersion = 'v4';\n readonly maxImagesPerCall = 1;\n\n get supportsFileInputs(): boolean | undefined {\n if (\n this.modelId === 'accounts/fireworks/models/flux-kontext-pro' ||\n this.modelId === 'accounts/fireworks/models/flux-kontext-max'\n ) {\n return true;\n }\n\n return [\n 'accounts/fireworks/models/flux-1-dev-fp8',\n 'accounts/fireworks/models/flux-1-schnell-fp8',\n 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic',\n 'accounts/fireworks/models/japanese-stable-diffusion-xl',\n 'accounts/fireworks/models/playground-v2-1024px-aesthetic',\n 'accounts/fireworks/models/SSD-1B',\n 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0',\n ].includes(this.modelId)\n ? false\n : undefined;\n }\n\n get supportsMaskInputs(): boolean | undefined {\n return this.supportsFileInputs == null ? undefined : false;\n }\n\n get provider(): string {\n return this.config.provider;\n }\n\n static [WORKFLOW_SERIALIZE](model: FireworksImageModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: FireworksImageModelId;\n config: FireworksImageModelConfig;\n }) {\n return new FireworksImageModel(options.modelId, options.config);\n }\n\n constructor(\n readonly modelId: FireworksImageModelId,\n private config: FireworksImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV4['doGenerate']>>\n > {\n const warnings: Array<SharedV4Warning> = [];\n\n const backendConfig = modelToBackendConfig[this.modelId];\n if (!backendConfig?.supportsSize && size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Use supportsSize as a proxy for whether the model does not support\n // aspectRatio. This invariant holds for the current set of models.\n if (backendConfig?.supportsSize && aspectRatio != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'aspectRatio',\n details: 'This model does not support the `aspectRatio` option.',\n });\n }\n\n // Handle files for image editing\n const hasInputImage = files != null && files.length > 0;\n let inputImage: string | undefined;\n\n if (hasInputImage) {\n inputImage = convertImageModelFileToDataUri(files[0]);\n\n if (files.length > 1) {\n warnings.push({\n type: 'other',\n message:\n 'Fireworks only supports a single input image. Additional images are ignored.',\n });\n }\n }\n\n // Warn about mask - Fireworks Kontext models don't support explicit masks\n if (mask != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'mask',\n details:\n 'Fireworks Kontext models do not support explicit masks. Use the prompt to describe the areas to edit.',\n });\n }\n\n const splitSize = size?.split('x');\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const combinedHeaders = combineHeaders(this.config.headers?.(), headers);\n const fireworksOptions =\n (await parseProviderOptions({\n provider: 'fireworks',\n providerOptions,\n schema: fireworksImageModelOptionsSchema,\n })) ?? {};\n\n const body = {\n prompt,\n aspect_ratio: aspectRatio,\n seed,\n samples: n,\n ...(inputImage && { input_image: inputImage }),\n ...(splitSize && { width: splitSize[0], height: splitSize[1] }),\n ...fireworksOptions,\n };\n\n // Handle async models that require polling (e.g., flux-kontext-*)\n if (backendConfig?.urlFormat === 'workflows_async') {\n return this.doGenerateAsync({\n body,\n headers: combinedHeaders,\n abortSignal,\n warnings,\n currentDate,\n });\n }\n\n // Handle sync models that return binary directly\n const { value: response, responseHeaders } = await postJsonToApi({\n url: getUrlForModel(this.config.baseURL, this.modelId),\n headers: combinedHeaders,\n body,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n images: [response],\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n\n /**\n * Handles async image generation for models like flux-kontext-* that return\n * a request_id and require polling for results.\n */\n private async doGenerateAsync({\n body,\n headers,\n abortSignal,\n warnings,\n currentDate,\n }: {\n body: Record<string, unknown>;\n headers: Record<string, string | undefined>;\n abortSignal: AbortSignal | undefined;\n warnings: Array<SharedV4Warning>;\n currentDate: Date;\n }): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>> {\n // Submit the generation request\n const { value: submitResponse } = await postJsonToApi({\n url: getUrlForModel(this.config.baseURL, this.modelId),\n headers,\n body,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n asyncSubmitResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n const requestId = submitResponse.request_id;\n\n // Poll for the result\n const imageUrl = await this.pollForImageUrl({\n requestId,\n headers,\n abortSignal,\n });\n\n // Download the image from the URL. The URL comes from the provider\n // response and typically points at a CDN, so only send credentials when it\n // stays on the provider's own origin (never leak the API key to a CDN or an\n // attacker-named host).\n const { value: imageBytes, responseHeaders } = await getFromApi({\n url: imageUrl,\n // imageUrl comes from the provider response body.\n validateUrl: true,\n credentialedOrigin: this.config.baseURL,\n trustedOrigin: this.config.baseURL,\n headers,\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n\n return {\n images: [imageBytes],\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n\n /**\n * Polls the get_result endpoint until the image is ready.\n */\n private async pollForImageUrl({\n requestId,\n headers,\n abortSignal,\n }: {\n requestId: string;\n headers: Record<string, string | undefined>;\n abortSignal: AbortSignal | undefined;\n }): Promise<string> {\n const pollIntervalMillis =\n this.config.pollIntervalMillis ?? DEFAULT_POLL_INTERVAL_MILLIS;\n const pollTimeoutMillis =\n this.config.pollTimeoutMillis ?? DEFAULT_POLL_TIMEOUT_MILLIS;\n\n const pollUrl = getPollUrlForModel(this.config.baseURL, this.modelId);\n\n const timeoutController = new AbortController();\n let didTimeout = false;\n const timeoutId = setTimeout(() => {\n didTimeout = true;\n timeoutController.abort();\n }, pollTimeoutMillis);\n const pollingAbortSignal =\n abortSignal == null\n ? timeoutController.signal\n : AbortSignal.any([abortSignal, timeoutController.signal]);\n\n try {\n while (true) {\n const { value: pollResponse } = await postJsonToApi({\n url: pollUrl,\n headers,\n body: { id: requestId },\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n asyncPollResponseSchema,\n ),\n abortSignal: pollingAbortSignal,\n fetch: this.config.fetch,\n });\n\n const status = pollResponse.status;\n\n if (status === 'Ready') {\n const imageUrl = pollResponse.result?.sample;\n if (typeof imageUrl === 'string') {\n return imageUrl;\n }\n throw new Error(\n 'Fireworks poll response is Ready but missing result.sample',\n );\n }\n\n if (status === 'Error' || status === 'Failed') {\n throw new Error(\n `Fireworks image generation failed with status: ${status}`,\n );\n }\n\n // Wait before next poll attempt\n await delay(pollIntervalMillis, {\n abortSignal: pollingAbortSignal,\n });\n }\n } catch (error) {\n if (didTimeout) {\n throw new Error(\n `Fireworks image generation timed out after ${pollTimeoutMillis}ms`,\n );\n }\n throw error;\n } finally {\n clearTimeout(timeoutId);\n }\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import {\n OpenAICompatibleChatLanguageModel,\n OpenAICompatibleCompletionLanguageModel,\n OpenAICompatibleEmbeddingModel,\n type ProviderErrorStructure,\n} from '@ai-sdk/openai-compatible';\nimport type {\n EmbeddingModelV4,\n ImageModelV4,\n LanguageModelV4,\n ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport type { FireworksChatModelId } from './fireworks-chat-options';\nimport type { FireworksCompletionModelId } from './fireworks-completion-options';\nimport type { FireworksEmbeddingModelId } from './fireworks-embedding-options';\nimport { FireworksImageModel } from './fireworks-image-model';\nimport type { FireworksImageModelId } from './fireworks-image-options';\nimport { VERSION } from './version';\n\nexport type FireworksErrorData = z.infer<typeof fireworksErrorSchema>;\n\nconst fireworksErrorSchema = z.object({\n error: z.union([\n z.string(),\n z.object({\n message: z.string(),\n object: z.string().nullish(),\n type: z.string().nullish(),\n param: z.any().nullish(),\n code: z.union([z.string(), z.number()]).nullish(),\n }),\n ]),\n});\n\nconst fireworksErrorStructure: ProviderErrorStructure<FireworksErrorData> = {\n errorSchema: fireworksErrorSchema,\n errorToMessage: data =>\n typeof data.error === 'string' ? data.error : data.error.message,\n};\n\nexport interface FireworksProviderSettings {\n /**\n * Fireworks API key. Default value is taken from the `FIREWORKS_API_KEY`\n * environment variable.\n */\n apiKey?: string;\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface FireworksProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n chatModel(modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a completion model for text generation.\n */\n completionModel(modelId: FireworksCompletionModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n languageModel(modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a text embedding model for text generation.\n */\n embeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;\n\n /**\n * Creates a model for image generation.\n */\n image(modelId: FireworksImageModelId): ImageModelV4;\n\n /**\n * Creates a model for image generation.\n */\n imageModel(modelId: FireworksImageModelId): ImageModelV4;\n}\n\nconst defaultBaseURL = 'https://api.fireworks.ai/inference/v1';\n\nexport function createFireworks(\n options: FireworksProviderSettings = {},\n): FireworksProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'FIREWORKS_API_KEY',\n description: 'Fireworks API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk-fireworks/${VERSION}`,\n );\n\n interface CommonModelConfig {\n provider: string;\n url: ({ path }: { path: string }) => string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n }\n\n const getCommonModelConfig = (modelType: string): CommonModelConfig => ({\n provider: `fireworks.${modelType}`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createChatModel = (modelId: FireworksChatModelId) => {\n return new OpenAICompatibleChatLanguageModel(modelId, {\n ...getCommonModelConfig('chat'),\n includeUsage: true,\n errorStructure: fireworksErrorStructure,\n supportsStructuredOutputs: true,\n transformRequestBody: (args, warnings) => {\n const thinking = args.thinking as\n | { type?: string; budgetTokens?: number }\n | undefined;\n const reasoningHistory = args.reasoningHistory as string | undefined;\n const promptCacheKey = args.promptCacheKey as string | undefined;\n const serviceTier = args.serviceTier as string | undefined;\n\n const {\n thinking: _,\n reasoningHistory: __,\n promptCacheKey: ___,\n serviceTier: ____,\n reasoning_effort,\n ...rest\n } = args;\n\n // Fireworks supports low, medium, and high reasoning levels.\n const mappedReasoningEffort =\n reasoning_effort === 'minimal'\n ? 'low'\n : reasoning_effort === 'xhigh' || reasoning_effort === 'max'\n ? 'high'\n : reasoning_effort;\n\n if (mappedReasoningEffort !== reasoning_effort) {\n warnings?.push({\n type: 'compatibility',\n feature: 'reasoning',\n details: `reasoning \"${reasoning_effort}\" is not directly supported by this model. mapped to effort \"${mappedReasoningEffort}\".`,\n });\n }\n\n return {\n ...rest,\n ...(reasoning_effort != null && {\n reasoning_effort: mappedReasoningEffort,\n }),\n ...(promptCacheKey !== undefined && {\n prompt_cache_key: promptCacheKey,\n }),\n ...(serviceTier !== undefined && {\n service_tier: serviceTier,\n }),\n ...(thinking && {\n thinking: {\n type: thinking.type,\n ...(thinking.budgetTokens !== undefined && {\n budget_tokens: thinking.budgetTokens,\n }),\n },\n }),\n ...(reasoningHistory && {\n reasoning_history: reasoningHistory,\n }),\n };\n },\n });\n };\n\n const createCompletionModel = (modelId: FireworksCompletionModelId) =>\n new OpenAICompatibleCompletionLanguageModel(modelId, {\n ...getCommonModelConfig('completion'),\n includeUsage: true,\n errorStructure: fireworksErrorStructure,\n });\n\n const createEmbeddingModel = (modelId: FireworksEmbeddingModelId) =>\n new OpenAICompatibleEmbeddingModel(modelId, {\n ...getCommonModelConfig('embedding'),\n errorStructure: fireworksErrorStructure,\n });\n\n const createImageModel = (modelId: FireworksImageModelId) =>\n new FireworksImageModel(modelId, {\n ...getCommonModelConfig('image'),\n baseURL: baseURL ?? defaultBaseURL,\n });\n\n const provider = (modelId: FireworksChatModelId) => createChatModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.completionModel = createCompletionModel;\n provider.chatModel = createChatModel;\n provider.languageModel = createChatModel;\n provider.embeddingModel = createEmbeddingModel;\n provider.textEmbeddingModel = createEmbeddingModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n return provider;\n}\n\nexport const fireworks = createFireworks();\n"],"mappings":";;;;AAIA,MAAa,4BAA4B,iBACvC,UACE,EAAE,OAAO,EACP,YAAY,EAAE,OAAO,EACvB,CAAC,CACH,CACF;AAGA,MAAa,0BAA0B,iBACrC,UACE,EAAE,OAAO;CACP,IAAI,EAAE,OAAO;CACb,QAAQ,EAAE,OAAO;CACjB,QAAQ,EACL,OAAO,EACN,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS,EAC9B,CAAC,CAAC,CACD,SAAS;AACd,CAAC,CACH,CACF;;;AClBA,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AAY,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/fireworks-image-api.ts","../src/fireworks-image-model-options.ts","../src/fireworks-image-model.ts","../src/version.ts","../src/fireworks-provider.ts"],"sourcesContent":["import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\n// Schema for async submit response\nexport const asyncSubmitResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n request_id: z.string(),\n }),\n ),\n);\n\n// Schema for async poll response\nexport const asyncPollResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n status: z.string(),\n result: z\n .object({\n sample: z.string().optional(),\n })\n .nullable(),\n }),\n ),\n);\n","import {\n lazySchema,\n zodSchema,\n type InferSchema,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport const fireworksImageModelOptionsSchema = lazySchema(() =>\n zodSchema(\n z.looseObject({\n /**\n * Classifier-free guidance scale for the image diffusion process.\n */\n guidance_scale: z.number().optional(),\n\n /**\n * Number of denoising steps for the image generation process.\n */\n num_inference_steps: z.number().int().optional(),\n\n /**\n * Desired output image format.\n */\n output_format: z.enum(['jpeg', 'png']).optional(),\n\n /**\n * URL to receive webhook notifications for async Kontext requests.\n */\n webhook_url: z.string().optional(),\n\n /**\n * Secret for webhook signature verification.\n */\n webhook_secret: z.string().optional(),\n\n /**\n * Whether Fireworks should automatically modify the prompt for more creative generation.\n */\n prompt_upsampling: z.boolean().optional(),\n\n /**\n * Moderation tolerance level for inputs and outputs.\n */\n safety_tolerance: z.number().int().min(0).max(6).optional(),\n\n /**\n * Guidance scale for legacy image_generation models.\n */\n cfg_scale: z.number().optional(),\n\n /**\n * Number of generation steps for legacy image_generation models.\n */\n steps: z.number().int().optional(),\n }),\n ),\n);\n\nexport type FireworksImageModelOptions = InferSchema<\n typeof fireworksImageModelOptionsSchema\n>;\n","import type { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n convertImageModelFileToDataUri,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n parseProviderOptions,\n postJsonToApi,\n serializeModelOptions,\n WORKFLOW_SERIALIZE,\n WORKFLOW_DESERIALIZE,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n asyncPollResponseSchema,\n asyncSubmitResponseSchema,\n} from './fireworks-image-api';\nimport { fireworksImageModelOptionsSchema } from './fireworks-image-model-options';\nimport type { FireworksImageModelId } from './fireworks-image-options';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_POLL_TIMEOUT_MILLIS = 120000; // 2 minutes for image generation\n\ninterface FireworksImageModelBackendConfig {\n urlFormat: 'workflows' | 'workflows_async' | 'image_generation';\n supportsSize?: boolean;\n supportsEditing?: boolean;\n}\n\nconst modelToBackendConfig: Partial<\n Record<FireworksImageModelId, FireworksImageModelBackendConfig>\n> = {\n 'accounts/fireworks/models/flux-1-dev-fp8': {\n urlFormat: 'workflows',\n },\n 'accounts/fireworks/models/flux-1-schnell-fp8': {\n urlFormat: 'workflows',\n },\n 'accounts/fireworks/models/flux-kontext-pro': {\n urlFormat: 'workflows_async',\n supportsEditing: true,\n },\n 'accounts/fireworks/models/flux-kontext-max': {\n urlFormat: 'workflows_async',\n supportsEditing: true,\n },\n 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/japanese-stable-diffusion-xl': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/playground-v2-1024px-aesthetic': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n 'accounts/fireworks/models/SSD-1B': {\n urlFormat: 'image_generation',\n supportsSize: true,\n },\n};\n\nfunction getUrlForModel(\n baseUrl: string,\n modelId: FireworksImageModelId,\n): string {\n const config = modelToBackendConfig[modelId];\n\n switch (config?.urlFormat) {\n case 'image_generation':\n return `${baseUrl}/image_generation/${modelId}`;\n case 'workflows_async':\n return `${baseUrl}/workflows/${modelId}`;\n case 'workflows':\n default:\n return `${baseUrl}/workflows/${modelId}/text_to_image`;\n }\n}\n\nfunction getPollUrlForModel(\n baseUrl: string,\n modelId: FireworksImageModelId,\n): string {\n return `${baseUrl}/workflows/${modelId}/get_result`;\n}\n\ninterface FireworksImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: () => Record<string, string>;\n fetch?: FetchFunction;\n /**\n * Poll interval in milliseconds between status checks for async models.\n * Defaults to 500ms.\n */\n pollIntervalMillis?: number;\n /**\n * Overall timeout in milliseconds for polling before giving up.\n * Defaults to 120000ms (2 minutes).\n */\n pollTimeoutMillis?: number;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class FireworksImageModel implements ImageModelV4 {\n readonly specificationVersion = 'v4';\n readonly maxImagesPerCall = 1;\n\n get supportsFileInputs(): boolean | undefined {\n if (\n this.modelId === 'accounts/fireworks/models/flux-kontext-pro' ||\n this.modelId === 'accounts/fireworks/models/flux-kontext-max'\n ) {\n return true;\n }\n\n return [\n 'accounts/fireworks/models/flux-1-dev-fp8',\n 'accounts/fireworks/models/flux-1-schnell-fp8',\n 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic',\n 'accounts/fireworks/models/japanese-stable-diffusion-xl',\n 'accounts/fireworks/models/playground-v2-1024px-aesthetic',\n 'accounts/fireworks/models/SSD-1B',\n 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0',\n ].includes(this.modelId)\n ? false\n : undefined;\n }\n\n get supportsMaskInputs(): boolean | undefined {\n return this.supportsFileInputs == null ? undefined : false;\n }\n\n get provider(): string {\n return this.config.provider;\n }\n\n static [WORKFLOW_SERIALIZE](model: FireworksImageModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: FireworksImageModelId;\n config: FireworksImageModelConfig;\n }) {\n return new FireworksImageModel(options.modelId, options.config);\n }\n\n constructor(\n readonly modelId: FireworksImageModelId,\n private config: FireworksImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV4['doGenerate']>>\n > {\n const warnings: Array<SharedV4Warning> = [];\n\n const backendConfig = modelToBackendConfig[this.modelId];\n if (!backendConfig?.supportsSize && size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Use supportsSize as a proxy for whether the model does not support\n // aspectRatio. This invariant holds for the current set of models.\n if (backendConfig?.supportsSize && aspectRatio != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'aspectRatio',\n details: 'This model does not support the `aspectRatio` option.',\n });\n }\n\n // Handle files for image editing\n const hasInputImage = files != null && files.length > 0;\n let inputImage: string | undefined;\n\n if (hasInputImage) {\n inputImage = convertImageModelFileToDataUri(files[0]);\n\n if (files.length > 1) {\n warnings.push({\n type: 'other',\n message:\n 'Fireworks only supports a single input image. Additional images are ignored.',\n });\n }\n }\n\n // Warn about mask - Fireworks Kontext models don't support explicit masks\n if (mask != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'mask',\n details:\n 'Fireworks Kontext models do not support explicit masks. Use the prompt to describe the areas to edit.',\n });\n }\n\n const splitSize = size?.split('x');\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const combinedHeaders = combineHeaders(this.config.headers?.(), headers);\n const fireworksOptions =\n (await parseProviderOptions({\n provider: 'fireworks',\n providerOptions,\n schema: fireworksImageModelOptionsSchema,\n })) ?? {};\n\n const body = {\n prompt,\n aspect_ratio: aspectRatio,\n seed,\n samples: n,\n ...(inputImage && { input_image: inputImage }),\n ...(splitSize && { width: splitSize[0], height: splitSize[1] }),\n ...fireworksOptions,\n };\n\n // Handle async models that require polling (e.g., flux-kontext-*)\n if (backendConfig?.urlFormat === 'workflows_async') {\n return this.doGenerateAsync({\n body,\n headers: combinedHeaders,\n abortSignal,\n warnings,\n currentDate,\n });\n }\n\n // Handle sync models that return binary directly\n const { value: response, responseHeaders } = await postJsonToApi({\n url: getUrlForModel(this.config.baseURL, this.modelId),\n headers: combinedHeaders,\n body,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n images: [response],\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n\n /**\n * Handles async image generation for models like flux-kontext-* that return\n * a request_id and require polling for results.\n */\n private async doGenerateAsync({\n body,\n headers,\n abortSignal,\n warnings,\n currentDate,\n }: {\n body: Record<string, unknown>;\n headers: Record<string, string | undefined>;\n abortSignal: AbortSignal | undefined;\n warnings: Array<SharedV4Warning>;\n currentDate: Date;\n }): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>> {\n // Submit the generation request\n const { value: submitResponse } = await postJsonToApi({\n url: getUrlForModel(this.config.baseURL, this.modelId),\n headers,\n body,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n asyncSubmitResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n const requestId = submitResponse.request_id;\n\n // Poll for the result\n const imageUrl = await this.pollForImageUrl({\n requestId,\n headers,\n abortSignal,\n });\n\n // Download the image from the URL. The URL comes from the provider\n // response and typically points at a CDN, so only send credentials when it\n // stays on the provider's own origin (never leak the API key to a CDN or an\n // attacker-named host).\n const { value: imageBytes, responseHeaders } = await getFromApi({\n url: imageUrl,\n // imageUrl comes from the provider response body.\n validateUrl: true,\n credentialedOrigin: this.config.baseURL,\n trustedOrigin: this.config.baseURL,\n headers,\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n\n return {\n images: [imageBytes],\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n\n /**\n * Polls the get_result endpoint until the image is ready.\n */\n private async pollForImageUrl({\n requestId,\n headers,\n abortSignal,\n }: {\n requestId: string;\n headers: Record<string, string | undefined>;\n abortSignal: AbortSignal | undefined;\n }): Promise<string> {\n const pollIntervalMillis =\n this.config.pollIntervalMillis ?? DEFAULT_POLL_INTERVAL_MILLIS;\n const pollTimeoutMillis =\n this.config.pollTimeoutMillis ?? DEFAULT_POLL_TIMEOUT_MILLIS;\n\n const pollUrl = getPollUrlForModel(this.config.baseURL, this.modelId);\n\n const timeoutController = new AbortController();\n let didTimeout = false;\n const timeoutId = setTimeout(() => {\n didTimeout = true;\n timeoutController.abort();\n }, pollTimeoutMillis);\n const pollingAbortSignal =\n abortSignal == null\n ? timeoutController.signal\n : AbortSignal.any([abortSignal, timeoutController.signal]);\n\n try {\n while (true) {\n const { value: pollResponse } = await postJsonToApi({\n url: pollUrl,\n headers,\n body: { id: requestId },\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n asyncPollResponseSchema,\n ),\n abortSignal: pollingAbortSignal,\n fetch: this.config.fetch,\n });\n\n const status = pollResponse.status;\n\n if (status === 'Ready') {\n const imageUrl = pollResponse.result?.sample;\n if (typeof imageUrl === 'string') {\n return imageUrl;\n }\n throw new Error(\n 'Fireworks poll response is Ready but missing result.sample',\n );\n }\n\n if (status === 'Error' || status === 'Failed') {\n throw new Error(\n `Fireworks image generation failed with status: ${status}`,\n );\n }\n\n // Wait before next poll attempt\n await delay(pollIntervalMillis, {\n abortSignal: pollingAbortSignal,\n });\n }\n } catch (error) {\n if (didTimeout) {\n throw new Error(\n `Fireworks image generation timed out after ${pollTimeoutMillis}ms`,\n );\n }\n throw error;\n } finally {\n clearTimeout(timeoutId);\n }\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import {\n OpenAICompatibleChatLanguageModel,\n OpenAICompatibleCompletionLanguageModel,\n OpenAICompatibleEmbeddingModel,\n type ProviderErrorStructure,\n} from '@ai-sdk/openai-compatible';\nimport type {\n EmbeddingModelV4,\n ImageModelV4,\n LanguageModelV4,\n ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n mapReasoningToProviderEffort,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport type { FireworksChatModelId } from './fireworks-chat-options';\nimport type { FireworksCompletionModelId } from './fireworks-completion-options';\nimport type { FireworksEmbeddingModelId } from './fireworks-embedding-options';\nimport { FireworksImageModel } from './fireworks-image-model';\nimport type { FireworksImageModelId } from './fireworks-image-options';\nimport { VERSION } from './version';\n\nexport type FireworksErrorData = z.infer<typeof fireworksErrorSchema>;\n\nconst fireworksErrorSchema = z.object({\n error: z.union([\n z.string(),\n z.object({\n message: z.string(),\n object: z.string().nullish(),\n type: z.string().nullish(),\n param: z.any().nullish(),\n code: z.union([z.string(), z.number()]).nullish(),\n }),\n ]),\n});\n\nconst fireworksErrorStructure: ProviderErrorStructure<FireworksErrorData> = {\n errorSchema: fireworksErrorSchema,\n errorToMessage: data =>\n typeof data.error === 'string' ? data.error : data.error.message,\n};\n\nexport interface FireworksProviderSettings {\n /**\n * Fireworks API key. Default value is taken from the `FIREWORKS_API_KEY`\n * environment variable.\n */\n apiKey?: string;\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface FireworksProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n chatModel(modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a completion model for text generation.\n */\n completionModel(modelId: FireworksCompletionModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n languageModel(modelId: FireworksChatModelId): LanguageModelV4;\n\n /**\n * Creates a text embedding model for text generation.\n */\n embeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;\n\n /**\n * Creates a model for image generation.\n */\n image(modelId: FireworksImageModelId): ImageModelV4;\n\n /**\n * Creates a model for image generation.\n */\n imageModel(modelId: FireworksImageModelId): ImageModelV4;\n}\n\nconst defaultBaseURL = 'https://api.fireworks.ai/inference/v1';\n\nexport function createFireworks(\n options: FireworksProviderSettings = {},\n): FireworksProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'FIREWORKS_API_KEY',\n description: 'Fireworks API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk-fireworks/${VERSION}`,\n );\n\n interface CommonModelConfig {\n provider: string;\n url: ({ path }: { path: string }) => string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n }\n\n const getCommonModelConfig = (modelType: string): CommonModelConfig => ({\n provider: `fireworks.${modelType}`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createChatModel = (modelId: FireworksChatModelId) => {\n return new OpenAICompatibleChatLanguageModel(modelId, {\n ...getCommonModelConfig('chat'),\n includeUsage: true,\n errorStructure: fireworksErrorStructure,\n supportsStructuredOutputs: true,\n mapReasoning: ({ reasoning, warnings }) =>\n mapReasoningToProviderEffort({\n reasoning,\n effortMap: getFireworksReasoningEffortMap(modelId),\n warnings,\n }),\n transformRequestBody: args => {\n const thinking = args.thinking as\n | { type?: string; budgetTokens?: number }\n | undefined;\n const reasoningHistory = args.reasoningHistory as string | undefined;\n const promptCacheKey = args.promptCacheKey as string | undefined;\n const serviceTier = args.serviceTier as string | undefined;\n\n const {\n thinking: _,\n reasoningHistory: __,\n promptCacheKey: ___,\n serviceTier: ____,\n ...rest\n } = args;\n\n return {\n ...rest,\n ...(promptCacheKey !== undefined && {\n prompt_cache_key: promptCacheKey,\n }),\n ...(serviceTier !== undefined && {\n service_tier: serviceTier,\n }),\n ...(thinking && {\n thinking: {\n type: thinking.type,\n ...(thinking.budgetTokens !== undefined && {\n budget_tokens: thinking.budgetTokens,\n }),\n },\n }),\n ...(reasoningHistory && {\n reasoning_history: reasoningHistory,\n }),\n };\n },\n });\n };\n\n const createCompletionModel = (modelId: FireworksCompletionModelId) =>\n new OpenAICompatibleCompletionLanguageModel(modelId, {\n ...getCommonModelConfig('completion'),\n includeUsage: true,\n errorStructure: fireworksErrorStructure,\n });\n\n const createEmbeddingModel = (modelId: FireworksEmbeddingModelId) =>\n new OpenAICompatibleEmbeddingModel(modelId, {\n ...getCommonModelConfig('embedding'),\n errorStructure: fireworksErrorStructure,\n });\n\n const createImageModel = (modelId: FireworksImageModelId) =>\n new FireworksImageModel(modelId, {\n ...getCommonModelConfig('image'),\n baseURL: baseURL ?? defaultBaseURL,\n });\n\n const provider = (modelId: FireworksChatModelId) => createChatModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.completionModel = createCompletionModel;\n provider.chatModel = createChatModel;\n provider.languageModel = createChatModel;\n provider.embeddingModel = createEmbeddingModel;\n provider.textEmbeddingModel = createEmbeddingModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n return provider;\n}\n\nexport const fireworks = createFireworks();\n\n// Model families that always reason and reject reasoning effort 'none'.\nconst modelsWithoutNoneReasoningEffort = /^(?:gpt-oss|glm-5p3|muse-spark)/;\n\n// Model families that reject reasoning effort 'minimal'.\nconst modelsWithoutMinimalReasoningEffort = /^(?:nemotron|inkling)/;\n\n/**\n * Fireworks accepts every reasoning effort for most models, so reasoning\n * values are sent directly, except to model families known to reject them.\n */\nfunction getFireworksReasoningEffortMap(modelId: string) {\n const modelName = modelId.slice(modelId.lastIndexOf('/') + 1);\n\n return {\n ...(!modelsWithoutNoneReasoningEffort.test(modelName) && {\n none: 'none' as const,\n }),\n ...(!modelsWithoutMinimalReasoningEffort.test(modelName) && {\n minimal: 'minimal' as const,\n }),\n low: 'low' as const,\n medium: 'medium' as const,\n high: 'high' as const,\n xhigh: 'xhigh' as const,\n max: 'max' as const,\n };\n}\n"],"mappings":";;;;AAIA,MAAa,4BAA4B,iBACvC,UACE,EAAE,OAAO,EACP,YAAY,EAAE,OAAO,EACvB,CAAC,CACH,CACF;AAGA,MAAa,0BAA0B,iBACrC,UACE,EAAE,OAAO;CACP,IAAI,EAAE,OAAO;CACb,QAAQ,EAAE,OAAO;CACjB,QAAQ,EACL,OAAO,EACN,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS,EAC9B,CAAC,CAAC,CACD,SAAS;AACd,CAAC,CACH,CACF;;;AClBA,MAAa,mCAAmC,iBAC9C,UACE,EAAE,YAAY;;;;CAIZ,gBAAgB,EAAE,OAAO,CAAC,CAAC,SAAS;;;;CAKpC,qBAAqB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;;;;CAK/C,eAAe,EAAE,KAAK,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,SAAS;;;;CAKhD,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;;;;CAKjC,gBAAgB,EAAE,OAAO,CAAC,CAAC,SAAS;;;;CAKpC,mBAAmB,EAAE,QAAQ,CAAC,CAAC,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MAAM,SAAS;MACf,GAAI,SAAS,iBAAiB,KAAA,KAAa,EACzC,eAAe,SAAS,aAC1B;KACF,EACF;KACA,GAAI,oBAAoB,EACtB,mBAAmB,iBACrB;IACF;GACF;EACF,CAAC;CACH;CAEA,MAAM,yBAAyB,YAC7B,IAAI,wCAAwC,SAAS;EACnD,GAAG,qBAAqB,YAAY;EACpC,cAAc;EACd,gBAAgB;CAClB,CAAC;CAEH,MAAM,wBAAwB,YAC5B,IAAI,+BAA+B,SAAS;EAC1C,GAAG,qBAAqB,WAAW;EACnC,gBAAgB;CAClB,CAAC;CAEH,MAAM,oBAAoB,YACxB,IAAI,oBAAoB,SAAS;EAC/B,GAAG,qBAAqB,OAAO;EAC/B,SAAS,WAAW;CACtB,CAAC;CAEH,MAAM,YAAY,YAAkC,gBAAgB,OAAO;CAE3E,SAAS,uBAAuB;CAChC,SAAS,kBAAkB;CAC3B,SAAS,YAAY;CACrB,SAAS,gBAAgB;CACzB,SAAS,iBAAiB;CAC1B,SAAS,qBAAqB;CAC9B,SAAS,QAAQ;CACjB,SAAS,aAAa;CACtB,OAAO;AACT;AAEA,MAAa,YAAY,gBAAgB;AAGzC,MAAM,mCAAmC;AAGzC,MAAM,sCAAsC;;;;;AAM5C,SAAS,+BAA+B,SAAiB;CACvD,MAAM,YAAY,QAAQ,MAAM,QAAQ,YAAY,GAAG,IAAI,CAAC;CAE5D,OAAO;EACL,GAAI,CAAC,iCAAiC,KAAK,SAAS,KAAK,EACvD,MAAM,OACR;EACA,GAAI,CAAC,oCAAoC,KAAK,SAAS,KAAK,EAC1D,SAAS,UACX;EACA,KAAK;EACL,QAAQ;EACR,MAAM;EACN,OAAO;EACP,KAAK;CACP;AACF"}
|
package/docs/26-fireworks.mdx
CHANGED
|
@@ -111,11 +111,9 @@ const model = fireworks('accounts/fireworks/models/firefunction-v1');
|
|
|
111
111
|
### Reasoning Models
|
|
112
112
|
|
|
113
113
|
For models that support reasoning effort, use the top-level `reasoning` parameter.
|
|
114
|
-
Fireworks
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
`providerOptions.fireworks.reasoningEffort` takes precedence over the top-level
|
|
118
|
-
setting.
|
|
114
|
+
Most Fireworks models accept every reasoning effort from `'none'` to `'max'`.
|
|
115
|
+
GPT-OSS, GLM-5.3 and Muse Spark models cannot disable reasoning, and Nemotron
|
|
116
|
+
and Inkling models do not support `'minimal'`.
|
|
119
117
|
|
|
120
118
|
Fireworks exposes the thinking of `deepseek-r1` in the generated text using the `<think>` tag.
|
|
121
119
|
You can use the `extractReasoningMiddleware` to extract this reasoning and expose it as a `reasoning` property on the result:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/fireworks",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.84",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/openai-compatible": "3.0.
|
|
32
|
+
"@ai-sdk/openai-compatible": "3.0.81",
|
|
33
33
|
"@ai-sdk/provider": "4.0.34",
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.71"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@ai-sdk/test-server": "2.0.4",
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
} from '@ai-sdk/provider';
|
|
13
13
|
import {
|
|
14
14
|
loadApiKey,
|
|
15
|
+
mapReasoningToProviderEffort,
|
|
15
16
|
withoutTrailingSlash,
|
|
16
17
|
withUserAgentSuffix,
|
|
17
18
|
type FetchFunction,
|
|
@@ -147,7 +148,13 @@ export function createFireworks(
|
|
|
147
148
|
includeUsage: true,
|
|
148
149
|
errorStructure: fireworksErrorStructure,
|
|
149
150
|
supportsStructuredOutputs: true,
|
|
150
|
-
|
|
151
|
+
mapReasoning: ({ reasoning, warnings }) =>
|
|
152
|
+
mapReasoningToProviderEffort({
|
|
153
|
+
reasoning,
|
|
154
|
+
effortMap: getFireworksReasoningEffortMap(modelId),
|
|
155
|
+
warnings,
|
|
156
|
+
}),
|
|
157
|
+
transformRequestBody: args => {
|
|
151
158
|
const thinking = args.thinking as
|
|
152
159
|
| { type?: string; budgetTokens?: number }
|
|
153
160
|
| undefined;
|
|
@@ -160,31 +167,11 @@ export function createFireworks(
|
|
|
160
167
|
reasoningHistory: __,
|
|
161
168
|
promptCacheKey: ___,
|
|
162
169
|
serviceTier: ____,
|
|
163
|
-
reasoning_effort,
|
|
164
170
|
...rest
|
|
165
171
|
} = args;
|
|
166
172
|
|
|
167
|
-
// Fireworks supports low, medium, and high reasoning levels.
|
|
168
|
-
const mappedReasoningEffort =
|
|
169
|
-
reasoning_effort === 'minimal'
|
|
170
|
-
? 'low'
|
|
171
|
-
: reasoning_effort === 'xhigh' || reasoning_effort === 'max'
|
|
172
|
-
? 'high'
|
|
173
|
-
: reasoning_effort;
|
|
174
|
-
|
|
175
|
-
if (mappedReasoningEffort !== reasoning_effort) {
|
|
176
|
-
warnings?.push({
|
|
177
|
-
type: 'compatibility',
|
|
178
|
-
feature: 'reasoning',
|
|
179
|
-
details: `reasoning "${reasoning_effort}" is not directly supported by this model. mapped to effort "${mappedReasoningEffort}".`,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
173
|
return {
|
|
184
174
|
...rest,
|
|
185
|
-
...(reasoning_effort != null && {
|
|
186
|
-
reasoning_effort: mappedReasoningEffort,
|
|
187
|
-
}),
|
|
188
175
|
...(promptCacheKey !== undefined && {
|
|
189
176
|
prompt_cache_key: promptCacheKey,
|
|
190
177
|
}),
|
|
@@ -240,3 +227,31 @@ export function createFireworks(
|
|
|
240
227
|
}
|
|
241
228
|
|
|
242
229
|
export const fireworks = createFireworks();
|
|
230
|
+
|
|
231
|
+
// Model families that always reason and reject reasoning effort 'none'.
|
|
232
|
+
const modelsWithoutNoneReasoningEffort = /^(?:gpt-oss|glm-5p3|muse-spark)/;
|
|
233
|
+
|
|
234
|
+
// Model families that reject reasoning effort 'minimal'.
|
|
235
|
+
const modelsWithoutMinimalReasoningEffort = /^(?:nemotron|inkling)/;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Fireworks accepts every reasoning effort for most models, so reasoning
|
|
239
|
+
* values are sent directly, except to model families known to reject them.
|
|
240
|
+
*/
|
|
241
|
+
function getFireworksReasoningEffortMap(modelId: string) {
|
|
242
|
+
const modelName = modelId.slice(modelId.lastIndexOf('/') + 1);
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
...(!modelsWithoutNoneReasoningEffort.test(modelName) && {
|
|
246
|
+
none: 'none' as const,
|
|
247
|
+
}),
|
|
248
|
+
...(!modelsWithoutMinimalReasoningEffort.test(modelName) && {
|
|
249
|
+
minimal: 'minimal' as const,
|
|
250
|
+
}),
|
|
251
|
+
low: 'low' as const,
|
|
252
|
+
medium: 'medium' as const,
|
|
253
|
+
high: 'high' as const,
|
|
254
|
+
xhigh: 'xhigh' as const,
|
|
255
|
+
max: 'max' as const,
|
|
256
|
+
};
|
|
257
|
+
}
|