Fireworks AI
Use Fireworks AI's OpenAI-compatible inference with Anvia.
Fireworks AI exposes an OpenAI-compatible chat completions surface at https://api.fireworks.ai/inference/v1. In Anvia, configure OpenAIClient with that baseUrl, then pass Fireworks model ids to completionModel(...). Fireworks also exposes a fine-tuning API and an Anthropic-SDK-compatible endpoint.
Create the Client
import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
const client = new OpenAIClient({
baseUrl: "https://api.fireworks.ai/inference/v1",
apiKey: process.env.FIREWORKS_API_KEY,
});
const model = client.completionModel("accounts/fireworks/models/llama-v3p1-8b-instruct");
const agent = new AgentBuilder("support", model)
.instructions("Answer support questions clearly.")
.build();
const response = await agent.prompt("Hello!").send();
console.log(response.output);baseUrl makes Anvia use the OpenAI-compatible chat completion adapter. Fireworks model ids are namespaced as accounts/fireworks/models/<model-name> and are not interchangeable with the upstream Hugging Face ids.
Get the Model List
Fireworks exposes a /v1/models endpoint that returns the model ids available to your key. Because the client was created with baseUrl, listModels() calls Fireworks's /models endpoint.
const models = await client.listModels();
console.table(
models.data.map((model) => ({
id: model.id,
name: model.name,
contextLength: model.contextLength,
})),
);Use the id field directly with completionModel(...).
Notes
- Fireworks API keys are passed as bearer tokens in the
Authorizationheader. max_tokensis adjusted to fit the model's context window by default. Ifpromptplusmax_tokensexceeds the context length, Fireworks automatically reducesmax_tokensand returns a successful response. Setcontext_length_exceeded_behavior: "error"to opt into the OpenAI-style error instead.- Fireworks returns
usagestats on streaming responses too. Theusagefield is present on the final chunk (the one withfinish_reasonset). The OpenAI SDK's TypeScript type does not declare the field, so cast the chunk to access it. - Fine-tuning uses the OpenAI-compatible
messagesshape with optionalweight,reasoning_content, and image content fields. OpenAI SFT datasets work without conversion. - Fireworks also exposes an Anthropic-SDK-compatible endpoint for Claude and other Anthropic-format models. Use
AnthropicClientwith thatbaseUrlfor Claude routes.
For current Fireworks API details, see the Fireworks OpenAI compatibility docs and the Fireworks model catalog.
