Use the completions API for raw text generation with custom prompt templates
The completions API provides raw text generation without automatic message formatting. Use this when you need full control over prompt formatting or when working with base models.
Custom prompt templates with specific formatting requirements
Base models (non-instruct/non-chat variants)
Fine-grained control over token-level formatting
Legacy applications that depend on raw completion format
For most use cases, use chat completions instead. Chat completions handles message formatting automatically and works better with instruct-tuned models.
from fireworks import Fireworksclient = Fireworks()response = client.completions.create( model="accounts/fireworks/models/deepseek-v3p1", prompt="Once upon a time")print(response.choices[0].text)
Copy
Ask AI
import osfrom openai import OpenAIclient = OpenAI( api_key=os.environ.get("FIREWORKS_API_KEY"), base_url="https://api.fireworks.ai/inference/v1")response = client.completions.create( model="accounts/fireworks/models/deepseek-v3p1", prompt="Once upon a time")print(response.choices[0].text)
Copy
Ask AI
import OpenAI from "openai";const client = new OpenAI({ apiKey: process.env.FIREWORKS_API_KEY, baseURL: "https://api.fireworks.ai/inference/v1",});const response = await client.completions.create({ model: "accounts/fireworks/models/deepseek-v3p1", prompt: "Once upon a time",});console.log(response.choices[0].text);
Most models automatically prepend the beginning-of-sequence (BOS) token (e.g., <s>) to your prompt. Verify this with the raw_output parameter if needed.
The completions API is useful when you need to implement custom prompt formats:
Copy
Ask AI
# Custom few-shot prompt templateprompt = """Task: Classify the sentiment of the following text.Text: I love this product!Sentiment: PositiveText: This is terrible.Sentiment: NegativeText: The weather is nice today.Sentiment:"""response = client.completions.create( model="accounts/fireworks/models/deepseek-v3p1", prompt=prompt, max_tokens=10, temperature=0)print(response.choices[0].text) # Output: " Positive"