Compatible Gateways

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 Authorization header.
  • max_tokens is adjusted to fit the model's context window by default. If prompt plus max_tokens exceeds the context length, Fireworks automatically reduces max_tokens and returns a successful response. Set context_length_exceeded_behavior: "error" to opt into the OpenAI-style error instead.
  • Fireworks returns usage stats on streaming responses too. The usage field is present on the final chunk (the one with finish_reason set). The OpenAI SDK's TypeScript type does not declare the field, so cast the chunk to access it.
  • Fine-tuning uses the OpenAI-compatible messages shape with optional weight, 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 AnthropicClient with that baseUrl for Claude routes.

For current Fireworks API details, see the Fireworks OpenAI compatibility docs and the Fireworks model catalog.