@ai-sdk/fireworks
Version:
The **[Fireworks provider](https://ai-sdk.dev/providers/ai-sdk-providers/fireworks)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model and image model support for the [Fireworks](https://fireworks.ai) platform.
160 lines (150 loc) • 7.58 kB
TypeScript
import { z } from 'zod/v4';
import * as _ai_sdk_provider from '@ai-sdk/provider';
import { ImageModelV4, ProviderV4, LanguageModelV4, EmbeddingModelV4 } from '@ai-sdk/provider';
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
type FireworksChatModelId = 'accounts/fireworks/models/deepseek-v3' | 'accounts/fireworks/models/llama-v3p3-70b-instruct' | 'accounts/fireworks/models/llama-v3p2-3b-instruct' | 'accounts/fireworks/models/llama-v3p1-405b-instruct' | 'accounts/fireworks/models/llama-v3p1-8b-instruct' | 'accounts/fireworks/models/mixtral-8x7b-instruct' | 'accounts/fireworks/models/mixtral-8x22b-instruct' | 'accounts/fireworks/models/mixtral-8x7b-instruct-hf' | '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' | (string & {});
declare const fireworksLanguageModelOptions: z.ZodObject<{
promptCacheKey: z.ZodOptional<z.ZodString>;
serviceTier: z.ZodOptional<z.ZodEnum<{
priority: "priority";
}>>;
thinking: z.ZodOptional<z.ZodObject<{
type: z.ZodOptional<z.ZodEnum<{
enabled: "enabled";
disabled: "disabled";
}>>;
budgetTokens: z.ZodOptional<z.ZodNumber>;
}, z.core.$strip>>;
reasoningHistory: z.ZodOptional<z.ZodEnum<{
disabled: "disabled";
interleaved: "interleaved";
preserved: "preserved";
}>>;
}, z.core.$strip>;
type FireworksLanguageModelOptions = z.infer<typeof fireworksLanguageModelOptions>;
type FireworksEmbeddingModelId = 'nomic-ai/nomic-embed-text-v1.5' | (string & {});
declare const fireworksEmbeddingModelOptions: z.ZodObject<{}, z.core.$strip>;
type FireworksEmbeddingModelOptions = z.infer<typeof fireworksEmbeddingModelOptions>;
type FireworksImageModelId = 'accounts/fireworks/models/flux-1-dev-fp8' | 'accounts/fireworks/models/flux-1-schnell-fp8' | 'accounts/fireworks/models/flux-kontext-pro' | 'accounts/fireworks/models/flux-kontext-max' | 'accounts/fireworks/models/playground-v2-5-1024px-aesthetic' | 'accounts/fireworks/models/japanese-stable-diffusion-xl' | 'accounts/fireworks/models/playground-v2-1024px-aesthetic' | 'accounts/fireworks/models/SSD-1B' | 'accounts/fireworks/models/stable-diffusion-xl-1024-v1-0' | (string & {});
interface FireworksImageModelConfig {
provider: string;
baseURL: string;
headers?: () => Record<string, string>;
fetch?: FetchFunction;
/**
* Poll interval in milliseconds between status checks for async models.
* Defaults to 500ms.
*/
pollIntervalMillis?: number;
/**
* Overall timeout in milliseconds for polling before giving up.
* Defaults to 120000ms (2 minutes).
*/
pollTimeoutMillis?: number;
_internal?: {
currentDate?: () => Date;
};
}
declare class FireworksImageModel implements ImageModelV4 {
readonly modelId: FireworksImageModelId;
private config;
readonly specificationVersion = "v4";
readonly maxImagesPerCall = 1;
get provider(): string;
static [WORKFLOW_SERIALIZE](model: FireworksImageModel): {
modelId: string;
config: _ai_sdk_provider.JSONObject;
};
static [WORKFLOW_DESERIALIZE](options: {
modelId: FireworksImageModelId;
config: FireworksImageModelConfig;
}): FireworksImageModel;
constructor(modelId: FireworksImageModelId, config: FireworksImageModelConfig);
doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal, files, mask, }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>>;
/**
* Handles async image generation for models like flux-kontext-* that return
* a request_id and require polling for results.
*/
private doGenerateAsync;
/**
* Polls the get_result endpoint until the image is ready.
*/
private pollForImageUrl;
}
declare const fireworksImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
[x: string]: unknown;
guidance_scale?: number | undefined;
num_inference_steps?: number | undefined;
output_format?: "jpeg" | "png" | undefined;
webhook_url?: string | undefined;
webhook_secret?: string | undefined;
prompt_upsampling?: boolean | undefined;
safety_tolerance?: number | undefined;
cfg_scale?: number | undefined;
steps?: number | undefined;
}>;
type FireworksImageModelOptions = InferSchema<typeof fireworksImageModelOptionsSchema>;
type FireworksCompletionModelId = 'accounts/fireworks/models/llama-v3-8b-instruct' | 'accounts/fireworks/models/llama-v2-34b-code' | (string & {});
type FireworksErrorData = z.infer<typeof fireworksErrorSchema>;
declare const fireworksErrorSchema: z.ZodObject<{
error: z.ZodString;
}, z.core.$strip>;
interface FireworksProviderSettings {
/**
* Fireworks API key. Default value is taken from the `FIREWORKS_API_KEY`
* environment variable.
*/
apiKey?: string;
/**
* Base URL for the API calls.
*/
baseURL?: string;
/**
* Custom headers to include in the requests.
*/
headers?: Record<string, string>;
/**
* Custom fetch implementation. You can use it as a middleware to intercept requests,
* or to provide a custom fetch implementation for e.g. testing.
*/
fetch?: FetchFunction;
}
interface FireworksProvider extends ProviderV4 {
/**
* Creates a model for text generation.
*/
(modelId: FireworksChatModelId): LanguageModelV4;
/**
* Creates a chat model for text generation.
*/
chatModel(modelId: FireworksChatModelId): LanguageModelV4;
/**
* Creates a completion model for text generation.
*/
completionModel(modelId: FireworksCompletionModelId): LanguageModelV4;
/**
* Creates a chat model for text generation.
*/
languageModel(modelId: FireworksChatModelId): LanguageModelV4;
/**
* Creates a text embedding model for text generation.
*/
embeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;
/**
* @deprecated Use `embeddingModel` instead.
*/
textEmbeddingModel(modelId: FireworksEmbeddingModelId): EmbeddingModelV4;
/**
* Creates a model for image generation.
*/
image(modelId: FireworksImageModelId): ImageModelV4;
/**
* Creates a model for image generation.
*/
imageModel(modelId: FireworksImageModelId): ImageModelV4;
}
declare function createFireworks(options?: FireworksProviderSettings): FireworksProvider;
declare const fireworks: FireworksProvider;
declare const VERSION: string;
export { type FireworksEmbeddingModelId, type FireworksEmbeddingModelOptions, type FireworksEmbeddingModelOptions as FireworksEmbeddingProviderOptions, type FireworksErrorData, FireworksImageModel, type FireworksImageModelId, type FireworksImageModelOptions, type FireworksLanguageModelOptions, type FireworksProvider, type FireworksLanguageModelOptions as FireworksProviderOptions, type FireworksProviderSettings, VERSION, createFireworks, fireworks };