Chat Completions
Create chat completions using Blackfuel's available models
POST /v1/chat/completions
This endpoint implements the OpenAI Chat Completions API, so OpenAI client libraries work against it.
Request
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer token with your API key |
Content-Type | Yes | Must be application/json |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model identifier (e.g., deepseek-ai/DeepSeek-V4-Flash-0731) |
messages | array | Yes | Array of message objects |
stream | boolean | No | Enable streaming responses (default: false) |
stream_options | object | No | Accepted for OpenAI compatibility. See Token Usage |
max_tokens | integer | No | Maximum tokens to generate |
temperature | number | No | Sampling temperature (0.0 - 2.0, default: 1.0) |
top_p | number | No | Nucleus sampling (0.0 - 1.0, default: 1.0) |
top_k | integer | No | Top-k sampling (default: -1, disabled) |
stop | string/array | No | Stop sequences |
seed | integer | No | Random seed for reproducibility |
frequency_penalty | number | No | Reduce repetition (-2.0 - 2.0, default: 0) |
presence_penalty | number | No | Encourage new topics (-2.0 - 2.0, default: 0) |
logprobs | boolean | No | Return log probabilities |
top_logprobs | integer | No | Number of top logprobs to return (0-20) |
tools | array | No | Function definitions for tool calling |
tool_choice | string/object | No | Control tool calling behavior |
response_format | object | No | Constrain the reply to JSON or to a JSON schema. See Structured Output |
reasoning_effort | string | No | Reasoning depth for reasoning-capable models: none, minimal, low, medium, high, xhigh, max. Send only a level the model lists in its supported_efforts. See the Reasoning guide. |
Message Object
| Field | Type | Required | Description |
|---|---|---|---|
role | string | Yes | system, user, assistant, or tool |
content | string/array | Yes | Message content (text or multimodal) |
name | string | No | Name of the participant |
tool_calls | array | No | Tool calls made by assistant |
tool_call_id | string | No | ID of the tool call being responded to |
Code Examples
import os
import openai
client = openai.OpenAI(
base_url="https://api.blackfuel.ai/v1",
api_key=os.environ["BLACKFUEL_API_KEY"],
)
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."}
],
max_tokens=500,
temperature=0.7
)
print(response.choices[0].message.content)
print(f"Tokens used: {response.usage.total_tokens}")import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.blackfuel.ai/v1',
apiKey: process.env.BLACKFUEL_API_KEY
});
const response = await client.chat.completions.create({
model: 'deepseek-ai/DeepSeek-V4-Flash-0731',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain quantum computing in simple terms.' }
],
max_tokens: 500,
temperature: 0.7
});
console.log(response.choices[0].message.content);
console.log(`Tokens used: ${response.usage.total_tokens}`);curl -X POST https://api.blackfuel.ai/v1/chat/completions \
-H "Authorization: Bearer $BLACKFUEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-ai/DeepSeek-V4-Flash-0731",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."}
],
"max_tokens": 500,
"temperature": 0.7
}'Response
Success Response
200 OK{
"id": "chatcmpl-abc123def456",
"object": "chat.completion",
"created": 1703123456,
"model": "deepseek-ai/DeepSeek-V4-Flash-0731",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Quantum computing is a type of computing that uses quantum mechanics..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 142,
"total_tokens": 167
}
}Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the completion |
object | string | Always "chat.completion" |
created | integer | Unix timestamp |
model | string | Model used for completion |
choices | array | Array of completion choices |
usage | object | Token usage statistics |
Choice Object
| Field | Type | Description |
|---|---|---|
index | integer | Index of this choice |
message | object | The generated message |
finish_reason | string | Why generation stopped |
The generated message also carries reasoning: the model's thinking pass when it reasoned, or null when it did not. See Reasoning.
Finish Reasons
| Reason | Description |
|---|---|
stop | Natural stop or stop sequence reached |
length | Max tokens limit reached |
tool_calls | Model invoked a tool |
content_filter | Content was filtered |
Error Responses
To read an error response and decide whether to retry, follow Error Handling.
Tool Calling
Enable function calling by providing tool definitions:
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[
{"role": "user", "content": "What's the weather in Paris?"}
],
tools=[
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}
}
],
tool_choice="auto"
)
# Check if the model wants to call a tool
if response.choices[0].message.tool_calls:
tool_call = response.choices[0].message.tool_calls[0]
print(f"Function: {tool_call.function.name}")
print(f"Arguments: {tool_call.function.arguments}")Vision (Multimodal)
To send an image, pass a content array combining a text part and an image_url part. image_url.url takes a data: URI, or an HTTPS URL the service can fetch. Replace the URL below with your own image.
A model accepts image input when its input_modalities includes image in GET /v1/models; sending an image to any other model returns a 400. An image_url the service cannot fetch returns a 422.
response = client.chat.completions.create(
model="google/gemma-4-31B-it",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
],
max_tokens=300
)A non-streaming request that produces no response before the response timeout fails with a 524. Use streaming for any request that may run that long, and to receive tokens as they're generated.