Fireworks Provider
Fireworks is supported via OpenAI API compatibility - the OpenAI provider is used in the examples below.
The Fireworks provider contains language model support for the Fireworks API.
It creates language model objects that can be used with the generateText
, streamText
, generateObject
, and streamObject
functions.
Setup
The Fireworks provider is available via the @ai-sdk/openai
module as it is compatible with the OpenAI API.
You can install it with
pnpm add @ai-sdk/openai
Provider Instance
To use Fireworks, you can create a custom provider instance with the createOpenAI
function from @ai-sdk/openai
:
import { createOpenAI } from '@ai-sdk/openai';
const fireworks = createOpenAI({ apiKey: process.env.FIREWORKS_API_KEY ?? '', baseURL: 'https://api.fireworks.ai/inference/v1',});
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');
Example
You can use Fireworks language models to generate text with the generateText
function:
import { createOpenAI } from '@ai-sdk/openai'import { generateText } from 'ai'
const fireworks = createOpenAI({ apiKey: process.env.FIREWORKS_API_KEY ?? '', baseURL: 'https://api.fireworks.ai/inference/v1'})
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
, generateObject
, streamObject
, and streamUI
functions
(see AI SDK Core and AI SDK RSC).