本页还没有译文
本页 78 段还没译成简体中文,下面显示的是英文原文。Fireworks
还没翻译译自英文(ai-sdk.dev)本页 78 段都还没译
Fireworks is a platform for running and testing LLMs through their API.
Start with AI Gateway for models in its catalog (recommended), or use @ai-sdk/fireworks to connect directly to Fireworks.
import { generateText } from 'ai';
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
console.log(text);Using AI Gateway
The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install ai:
pnpm add ainpm install aiyarn add aibun add aiSet an AI Gateway API key in your environment:
export AI_GATEWAY_API_KEY=your_api_key_hereVercel deployments can also use OIDC authentication. See the AI Gateway provider documentation for configuration and the model catalog for available models.
The example sets providerOptions.gateway.order to ['fireworks']. This sends the request to Fireworks first, then falls back to other available providers of the same model if Fireworks is unavailable or the request fails. order sets a preference; it does not restrict fallback to Fireworks. See provider ordering.
The dropdown lists models served by Fireworks through Gateway with a corresponding direct-provider example. Provider availability depends on the model and your team's Provider Allowlist.
Using @ai-sdk/fireworks
For direct access to Fireworks, install ai and @ai-sdk/fireworks:
pnpm add ai @ai-sdk/fireworksnpm install ai @ai-sdk/fireworksyarn add ai @ai-sdk/fireworksbun add ai @ai-sdk/fireworksSet your Fireworks API credential in the FIREWORKS_API_KEY environment variable:
export FIREWORKS_API_KEY=your_api_key_hereAI Gateway does not expose every API in @ai-sdk/fireworks. Use the direct provider for provider-specific APIs or custom connection settings.
Note
The following sections document the direct @ai-sdk/fireworks provider,
including its model factories and settings. Gateway model and feature
availability can differ.
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
For models that support reasoning effort, use the top-level reasoning parameter.
Fireworks maps 'minimal' to 'low' and 'xhigh' or 'max' to 'high', returning
a compatibility warning whenever it coerces the effort. Streaming calls include
the warning in the stream-start event. Explicit
providerOptions.fireworks.reasoningEffort takes precedence over the top-level
setting.
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 | ✗ | ✓ | ✓ | ✗ |
Note
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 |
Note
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,
},
});Note
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.
Note
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',
});Note
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 |