Skip to main content
New to Fireworks? Start with the Serverless Quickstart for a step-by-step guide to making your first API call.
Fireworks provides fast, cost-effective access to leading open-source text models through OpenAI-compatible APIs. Query models via serverless inference or dedicated deployments using the chat completions API (recommended), completions API, or responses API. Browse 100+ available models →

Chat Completions API

Most models automatically format your messages with the correct template. To verify the exact prompt used, enable the echo parameter.
For Priority tier (service_tier: "priority") and Fast, see Serverless Serving Paths.

Alternative query methods

Fireworks also supports Completions API and Responses API.

Querying dedicated deployments

For consistent performance, guaranteed capacity, or higher throughput, you can query on-demand deployments instead of serverless models. Deployments use the same APIs with a deployment-specific identifier:
For example:

Common patterns

Multi-turn conversations

Maintain conversation history by including all previous messages:
The model uses the full conversation history to provide contextually relevant responses.

System prompts

Override the default system prompt by setting the first message with role: "system":
To completely omit the system prompt, set the first message’s content to an empty string.

Streaming responses

Stream tokens as they’re generated for real time, interactive UX. Covered in detail in the Serverless Quickstart.
Aborting streams: Close the connection to stop generation and avoid billing for ungenerated tokens:

Async requests

Use async clients to make multiple concurrent requests for better throughput:

Usage & performance tracking

Every response includes token usage information and performance metrics for debugging and observability. For aggregate metrics over time, see the usage dashboard.
The analytics and usage dashboard measures server-acknowledged requests, not every client-observed outcome.The dashboard counts requests that successfully reached the Fireworks API. It does not capture connection timeouts before the request lands on the server, client-side retries before a successful attempt, or failures on the network path between your application and the API.If your application reports failures but the dashboard looks healthy, check client timeout configuration and network connectivity. For dedicated deployments, Prometheus-style metrics reflect server-side behavior for that deployment.
Token usage (prompt, completion, total tokens) is included in the response body for all requests. Performance metrics (latency, time-to-first-token, etc.) are included in response headers for non-streaming requests. For streaming requests, use the perf_metrics_in_response parameter to include all metrics in the response body.
Usage information is automatically included in the final chunk for streaming responses (the chunk with finish_reason set). This is a Fireworks extension - OpenAI SDK doesn’t return usage for streaming by default.
For all available metrics and details, see the API reference documentation.
If you encounter errors during inference, see Inference Error Codes for common issues and resolutions.

Advanced capabilities

Extend text models with additional features for structured outputs, tool integration, and performance optimization:

Tool calling

Connect models to external tools and APIs with type-safe parameters

Structured outputs

Enforce JSON schemas for reliable data extraction

Responses API

Multi-step reasoning for complex problem-solving

Predicted outputs

Speed up edits by predicting unchanged sections

Prompt caching

Cache common prompts to reduce latency and cost

Batch inference

Process large volumes of requests asynchronously

Configuration & debugging

Control how the model generates text. Fireworks automatically uses recommended sampling parameters from each model’s HuggingFace generation_config.json when you don’t specify them explicitly, ensuring optimal performance out-of-the-box.We pull temperature, top_k, top_p, min_p, and typical_p from the model’s configuration when not explicitly provided.

Temperature

Adjust randomness (0 = deterministic, higher = more creative):

Max tokens

Control the maximum number of tokens in the generated completion:
Important notes:
  • Default value is 2048 tokens if not specified
  • Most models support up to their full context window (e.g., 128K for DeepSeek R1)
  • When the limit is reached, you’ll see "finish_reason": "length" in the response
Set max_tokens appropriately for your use case to avoid truncated responses. Check the model’s context window in the Model Library.

Top-p (nucleus sampling)

Consider only the most probable tokens summing to top_p probability mass:

Top-k

Consider only the k most probable tokens:

Min-p

Exclude tokens below a probability threshold:

Typical-p

Use typical sampling to select tokens with probability close to the entropy of the distribution:

Repetition penalties

Reduce repetitive text with frequency_penalty, presence_penalty, or repetition_penalty:

Sampling options header

The fireworks-sampling-options header contains the actual default sampling parameters used for the model, including values from the model’s HuggingFace generation_config.json:
See the API reference for detailed parameter descriptions.
Generate multiple completions in one request:
Inspect token probabilities for debugging or analysis:
Verify how your prompt was formatted:Echo: Return the prompt along with the generation:
Token IDs: Return prompt and completion token IDs:
Raw output: See prompt fragments and raw completion:
Experimental API - may change without notice.
Force generation to continue past the end-of-sequence token (useful for benchmarking):
Output quality may degrade when ignoring EOS. This API is experimental and should not be relied upon for production use cases.
Modify token probabilities to encourage or discourage specific tokens:
Control perplexity dynamically using the Mirostat algorithm:

Understanding tokens

Language models process text in chunks called tokens. In English, a token can be as short as one character or as long as one word. Different model families use different tokenizers, so the same text may translate to different token counts depending on the model. Why tokens matter:
  • Models have maximum context lengths measured in tokens
  • Pricing is based on token usage (prompt + completion)
  • Token count affects response time
For Llama models, use this tokenizer tool to estimate token counts. Actual usage is returned in the usage field of every API response.

OpenAI SDK migration

Fireworks provides an OpenAI-compatible API, making migration from OpenAI straightforward. For detailed information on setup, usage examples, and API compatibility notes, see the OpenAI compatibility guide.

Next steps

Vision models

Process images alongside text

Embeddings

Generate vector representations for search

On-demand deployments

Deploy models on dedicated GPUs

Fine-tuning

Customize models for your use case

Error codes

Troubleshoot common inference errors

API Reference

Complete API documentation