Getting Started
Quickstart
Make your first request to the Blackfuel API
Prerequisites
- A Blackfuel account with an API key (get one here)
- A Python or Node.js runtime supported by the OpenAI SDK
Step 1: Install an OpenAI client library
Blackfuel serves the OpenAI Chat Completions API, so the official OpenAI SDK and any OpenAI-compatible client library work — point the base URL at Blackfuel.
pip install openainpm install openaiOther languages work too: Go, Rust, Ruby, PHP, Java.
Step 2: Configure the client
Set your API key as an environment variable, replacing bf_mykey_xxxxxx with your actual key from the API Keys page:
export BLACKFUEL_API_KEY="bf_mykey_xxxxxx"import os
import openai
client = openai.OpenAI(
base_url="https://api.blackfuel.ai/v1",
api_key=os.environ["BLACKFUEL_API_KEY"],
)import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.blackfuel.ai/v1',
apiKey: process.env.BLACKFUEL_API_KEY,
});Step 3: Make your first request
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
max_tokens=100
)
print(response.choices[0].message.content)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: 'What is the capital of France?' }
],
max_tokens: 100
});
console.log(response.choices[0].message.content);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": "What is the capital of France?"}
],
"max_tokens": 100
}'Step 4: Stream a response
For long responses, streaming delivers a better user experience:
stream = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=[
{"role": "user", "content": "Explain how LLMs work in simple terms."}
],
stream=True,
)
for chunk in stream:
# The stream ends with a usage chunk whose choices array is empty
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)const stream = await client.chat.completions.create({
model: 'deepseek-ai/DeepSeek-V4-Flash-0731',
messages: [
{ role: 'user', content: 'Explain how LLMs work in simple terms.' }
],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}Step 5: Explore available models
models = client.models.list()
for model in models.data:
print(f"{model.id}: {model.description}")const models = await client.models.list();
for (const model of models.data) {
console.log(model.id);
}curl https://api.blackfuel.ai/v1/models \
-H "Authorization: Bearer $BLACKFUEL_API_KEY"Error handling
The earlier steps keep each sample to one call. Wrap them like this instead: retry a 429 with bounded backoff, and fail fast on an authentication error, which no amount of retrying fixes. See the Error Handling guide for the full list of error types and retry strategies.
import time
import openai
def chat(messages, retries=3):
for attempt in range(retries):
try:
return client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Flash-0731",
messages=messages,
)
except openai.AuthenticationError:
raise # a bad key never becomes a good one
except (openai.RateLimitError, openai.APIError):
if attempt == retries - 1:
raise
time.sleep(2**attempt)
print(chat([{"role": "user", "content": "Hello!"}]).choices[0].message.content)import OpenAI from 'openai';
async function chat(messages, retries = 3) {
for (let attempt = 0; attempt < retries; attempt++) {
try {
return await client.chat.completions.create({
model: 'deepseek-ai/DeepSeek-V4-Flash-0731',
messages,
});
} catch (e) {
if (e instanceof OpenAI.AuthenticationError) throw e; // a bad key never becomes a good one
if (attempt === retries - 1) throw e;
await new Promise(r => setTimeout(r, 1000 * 2 ** attempt));
}
}
}
const response = await chat([{ role: 'user', content: 'Hello!' }]);
console.log(response.choices[0].message.content);Next Steps
- Available Models - Browse the model catalog
- Models -
GET /v1/modelsendpoint reference - Chat Completions - Full endpoint reference
- Authentication - Learn about API key management
- Rate Limits - Understand usage limits