Fireworks Provider
Fireworks is a platform for running and testing LLMs through their API.
Setup
The Fireworks provider is available via the @ai-sdk/fireworks module. You can install it with
pnpm add @ai-sdk/fireworks
Provider Instance
You can import the default provider instance fireworks from @ai-sdk/fireworks:
import { fireworks } from '@ai-sdk/fireworks';If you need a customized setup, you can import createFireworks from @ai-sdk/fireworks
and create a provider instance with your settings:
import { createFireworks } from '@ai-sdk/fireworks';
const fireworks = createFireworks({ apiKey: process.env.FIREWORKS_API_KEY ?? '',});You can use the following optional settings to customize the Fireworks provider instance:
-
baseURL string
Use a different URL prefix for API calls, e.g. to use proxy servers. The default prefix is
https://api.fireworks.ai/inference/v1. -
apiKey string
API key that is being sent using the
Authorizationheader. It defaults to theFIREWORKS_API_KEYenvironment variable. -
headers Record<string,string>
Custom headers to include in the requests.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
Custom fetch implementation.
Language Models
You can create Fireworks models using a provider instance.
The first argument is the model id, e.g. accounts/fireworks/models/firefunction-v1:
const model = fireworks('accounts/fireworks/models/firefunction-v1');Reasoning Models
Fireworks exposes the thinking of deepseek-r1 in the generated text using the <think> tag.
You can use the extractReasoningMiddleware to extract this reasoning and expose it as a reasoning property on the result:
import { fireworks } from '@ai-sdk/fireworks';import { wrapLanguageModel, extractReasoningMiddleware } from 'ai';
const enhancedModel = wrapLanguageModel({ model: fireworks('accounts/fireworks/models/deepseek-r1'), middleware: extractReasoningMiddleware({ tagName: 'think' }),});You can then use that enhanced model in functions like generateText and streamText.
Example
You can use Fireworks language models to generate text with the generateText function:
import { fireworks } from '@ai-sdk/fireworks';import { generateText } from 'ai';
const { text } = await generateText({ model: fireworks('accounts/fireworks/models/firefunction-v1'), prompt: 'Write a vegetarian lasagna recipe for 4 people.',});Fireworks language models can also be used in the streamText function
(see AI SDK Core).
Provider Options
Fireworks chat models support additional provider options that are not part of
the standard call settings. You can pass them in the providerOptions argument:
import { fireworks, type FireworksLanguageModelOptions,} from '@ai-sdk/fireworks';import { generateText } from 'ai';
const { text, reasoningText } = await generateText({ model: fireworks('accounts/fireworks/models/kimi-k2p6'), providerOptions: { fireworks: { thinking: { type: 'enabled', budgetTokens: 4096 }, reasoningHistory: 'interleaved', } satisfies FireworksLanguageModelOptions, }, prompt: 'How many "r"s are in the word "strawberry"?',});The following optional provider options are available for Fireworks chat models:
-
promptCacheKey string
A stable, opaque key that improves prompt cache hit rates by routing requests with shared prompt prefixes to the same Fireworks replica. Reuse the same key for all steps and calls in one conversation, and use different keys for unrelated conversations.
-
serviceTier 'priority'
Uses the Fireworks Priority serving path for higher reliability during peak traffic. The provider sends it as Fireworks'
service_tierrequest field. -
thinking object
Configuration for thinking/reasoning models like Kimi K2.6.
-
type 'enabled' | 'disabled'
Whether to enable thinking mode.
-
budgetTokens number
Maximum number of tokens for thinking (minimum 1024).
-
-
reasoningHistory 'disabled' | 'interleaved' | 'preserved'
Controls how reasoning history is handled in multi-turn conversations:
'disabled': Remove reasoning from history'interleaved': Include reasoning between tool calls within a single turn'preserved': Keep all reasoning in history
Prompt Cache Affinity
Fireworks prompt caching
is automatic, but cached prefixes are local to a replica. Set
promptCacheKey to an opaque session or conversation identifier to improve
cache affinity. The provider sends it as Fireworks'
prompt_cache_key
request field.
The AI SDK reuses the same provider options for every model step in a
multi-step generateText or streamText call, so one key covers the complete
tool loop:
import { fireworks, type FireworksLanguageModelOptions,} from '@ai-sdk/fireworks';import { generateText, isStepCount, tool } from 'ai';import { z } from 'zod';
const sessionId = 'conversation-123';
const result = await generateText({ model: fireworks('accounts/fireworks/models/kimi-k2p6'), providerOptions: { fireworks: { promptCacheKey: sessionId, } satisfies FireworksLanguageModelOptions, }, tools: { weather: tool({ description: 'Get the weather for a city.', inputSchema: z.object({ city: z.string() }), execute: async ({ city }) => `It is sunny in ${city}.`, }), }, stopWhen: isStepCount(5), prompt: 'What is the weather in San Francisco?',});
console.log(result.usage.inputTokenDetails.cacheReadTokens);For a reusable ToolLoopAgent, use call options to supply a key for each
conversation. Pass the same key again for later agent calls that continue that
conversation:
import { fireworks, type FireworksLanguageModelOptions,} from '@ai-sdk/fireworks';import { ToolLoopAgent } from 'ai';import { z } from 'zod';import { weatherTool } from './weather-tool';
const agent = new ToolLoopAgent({ model: fireworks('accounts/fireworks/models/kimi-k2p6'), callOptionsSchema: z.object({ sessionId: z.string(), }), prepareCall: ({ options, ...settings }) => ({ ...settings, providerOptions: { fireworks: { promptCacheKey: options.sessionId, } satisfies FireworksLanguageModelOptions, }, }), tools: { weather: weatherTool },});
const result = await agent.generate({ prompt: 'What is the weather in San Francisco?', options: { sessionId: 'conversation-123', },});Use non-identifying values for cache keys rather than email addresses or other personal information.
Priority Service Tier
Fireworks Priority tier
prioritizes supported models above Standard traffic. Set serviceTier to
'priority' to send Fireworks' service_tier request field:
import { fireworks, type FireworksLanguageModelOptions,} from '@ai-sdk/fireworks';import { generateText } from 'ai';
const result = await generateText({ model: fireworks('accounts/fireworks/models/glm-5p2'), providerOptions: { fireworks: { serviceTier: 'priority', } satisfies FireworksLanguageModelOptions, }, prompt: 'Write a haiku about reliable inference.',});Completion Models
You can create models that call the Fireworks completions API using the .completionModel() factory method:
const model = fireworks.completionModel( 'accounts/fireworks/models/firefunction-v1',);Model Capabilities
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|---|---|---|---|---|
accounts/fireworks/models/firefunction-v1 | ||||
accounts/fireworks/models/deepseek-r1 | ||||
accounts/fireworks/models/deepseek-v3 | ||||
accounts/fireworks/models/llama-v3p1-405b-instruct | ||||
accounts/fireworks/models/llama-v3p1-8b-instruct | ||||
accounts/fireworks/models/llama-v3p2-3b-instruct | ||||
accounts/fireworks/models/llama-v3p3-70b-instruct | ||||
accounts/fireworks/models/mixtral-8x7b-instruct | ||||
accounts/fireworks/models/mixtral-8x7b-instruct-hf | ||||
accounts/fireworks/models/mixtral-8x22b-instruct | ||||
accounts/fireworks/models/qwen2p5-coder-32b-instruct | ||||
accounts/fireworks/models/qwen2p5-72b-instruct | ||||
accounts/fireworks/models/qwen-qwq-32b-preview | ||||
accounts/fireworks/models/qwen2-vl-72b-instruct | ||||
accounts/fireworks/models/llama-v3p2-11b-vision-instruct | ||||
accounts/fireworks/models/qwq-32b | ||||
accounts/fireworks/models/yi-large | ||||
accounts/fireworks/models/kimi-k2-instruct | ||||
accounts/fireworks/models/kimi-k2-thinking | ||||
accounts/fireworks/models/kimi-k2p6 | ||||
accounts/fireworks/models/minimax-m2 |
The table above lists popular models. Please see the Fireworks models page for a full list of available models.
Embedding Models
You can create models that call the Fireworks embeddings API using the .embeddingModel() factory method:
const model = fireworks.embeddingModel('nomic-ai/nomic-embed-text-v1.5');You can use Fireworks embedding models to generate embeddings with the embed function:
import { fireworks } from '@ai-sdk/fireworks';import { embed } from 'ai';
const { embedding } = await embed({ model: fireworks.embeddingModel('nomic-ai/nomic-embed-text-v1.5'), value: 'sunny day at the beach',});Model Capabilities
| Model | Dimensions | Max Tokens |
|---|---|---|
nomic-ai/nomic-embed-text-v1.5 | 768 | 8192 |
For more embedding models, see the Fireworks models page for a full list of available models.
Image Models
You can create Fireworks image models using the .image() factory method.
For more on image generation with the AI SDK see generateImage().
import { fireworks, type FireworksImageModelOptions } from '@ai-sdk/fireworks';import { generateImage } from 'ai';
const { image } = await generateImage({ model: fireworks.image('accounts/fireworks/models/flux-1-dev-fp8'), prompt: 'A futuristic cityscape at sunset', aspectRatio: '16:9', providerOptions: { fireworks: { guidance_scale: 4.5, num_inference_steps: 8, } satisfies FireworksImageModelOptions, },});Model support for size and aspectRatio parameters varies. See the Model
Capabilities section below for supported dimensions,
or check the model's documentation on Fireworks models
page for more details.
Provider Options
Fireworks image models support flexible provider options through the providerOptions.fireworks object. Use the FireworksImageModelOptions type to validate known Fireworks image options while still allowing model-specific options to pass through.
The following typed provider options are available:
-
guidance_scale number
Classifier-free guidance scale for the image diffusion process.
-
num_inference_steps number
Number of denoising steps for FLUX workflow image generation.
-
output_format 'jpeg' | 'png'
Desired output format for FLUX Kontext image generation and editing.
-
prompt_upsampling boolean
Whether Fireworks should automatically modify the prompt for more creative generation.
-
safety_tolerance number
Moderation tolerance level for inputs and outputs, from
0to6. Fireworks limits image-to-image requests to2. -
webhook_url string
URL to receive webhook notifications for async Kontext requests.
-
webhook_secret string
Secret for webhook signature verification.
-
cfg_scale number
Guidance scale for legacy
image_generationmodels. -
steps number
Number of generation steps for legacy
image_generationmodels.
Image Editing
Fireworks supports image editing through FLUX Kontext models (flux-kontext-pro and flux-kontext-max). Pass input images via prompt.images to transform or edit existing images.
Fireworks Kontext models do not support explicit masks. Editing is prompt-driven — describe what you want to change in the text prompt.
Basic Image Editing
Transform an existing image using text prompts:
const imageBuffer = readFileSync('./input-image.png');
const { images } = await generateImage({ model: fireworks.image('accounts/fireworks/models/flux-kontext-pro'), prompt: { text: 'Turn the cat into a golden retriever dog', images: [imageBuffer], }, providerOptions: { fireworks: { output_format: 'jpeg', safety_tolerance: 2, } satisfies FireworksImageModelOptions, },});Style Transfer
Apply artistic styles to an image:
const imageBuffer = readFileSync('./input-image.png');
const { images } = await generateImage({ model: fireworks.image('accounts/fireworks/models/flux-kontext-pro'), prompt: { text: 'Transform this into a watercolor painting style', images: [imageBuffer], }, aspectRatio: '1:1',});Input images can be provided as Buffer, ArrayBuffer, Uint8Array, or
base64-encoded strings. Fireworks only supports a single input image per
request.
Model Capabilities
For all models supporting aspect ratios, the following aspect ratios are supported:
1:1 (default), 2:3, 3:2, 4:5, 5:4, 16:9, 9:16, 9:21, 21:9
For all models supporting size, the following sizes are supported:
640 x 1536, 768 x 1344, 832 x 1216, 896 x 1152, 1024x1024 (default), 1152 x 896, 1216 x 832, 1344 x 768, 1536 x 640
| Model | Dimensions Specification | Image Editing |
|---|---|---|
accounts/fireworks/models/flux-kontext-pro | Aspect Ratio | |
accounts/fireworks/models/flux-kontext-max | Aspect Ratio | |
accounts/fireworks/models/flux-1-dev-fp8 | Aspect Ratio | |
accounts/fireworks/models/flux-1-schnell-fp8 | Aspect Ratio | |
accounts/fireworks/models/playground-v2-5-1024px-aesthetic | Size | |
accounts/fireworks/models/japanese-stable-diffusion-xl | Size | |
accounts/fireworks/models/playground-v2-1024px-aesthetic | Size | |
accounts/fireworks/models/SSD-1B | Size | |
accounts/fireworks/models/stable-diffusion-xl-1024-v1-0 | Size |
For more details, see the Fireworks models page.
Stability AI Models
Fireworks also presents several Stability AI models backed by Stability AI API keys and endpoint. The AI SDK Fireworks provider does not currently include support for these models:
| Model ID |
|---|
accounts/stability/models/sd3-turbo |
accounts/stability/models/sd3-medium |
accounts/stability/models/sd3 |