Fireworks Provider

Fireworks is a platform for running and testing LLMs. It offers an OpenAI compatible API that you can use with the AI SDK.

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
npm
yarn
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({
name: 'fireworks',
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({
name: 'fireworks',
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, and streamObject functions.