BLACKFUEL
API Reference

Embeddings

Create text embeddings using Blackfuel's embedding models

POST /v1/embeddings

This endpoint is compatible with the OpenAI Embeddings API, so the OpenAI SDKs work against it unchanged.

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer token with your API key
Content-TypeYesMust be application/json

Body Parameters

ParameterTypeRequiredDescription
modelstringYesModel identifier (e.g., BAAI/bge-multilingual-gemma2)
inputstring/arrayYesText to embed (single string or array of strings)
encoding_formatstringNoOutput format: float (default) returns embedding as an array of numbers, base64 returns it as a base64-encoded string

Code Examples

import os
import openai

client = openai.OpenAI(
    base_url="https://api.blackfuel.ai/v1",
    api_key=os.environ["BLACKFUEL_API_KEY"],
)

# Single text embedding
response = client.embeddings.create(
    model="BAAI/bge-multilingual-gemma2",
    input="Your text to embed"
)

embedding = response.data[0].embedding
print(f"Embedding dimension: {len(embedding)}")
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.blackfuel.ai/v1',
  apiKey: process.env.BLACKFUEL_API_KEY
});

// Single text embedding
const response = await client.embeddings.create({
  model: 'BAAI/bge-multilingual-gemma2',
  input: 'Your text to embed'
});

const embedding = response.data[0].embedding;
console.log(`Embedding dimension: ${embedding.length}`);
curl -X POST https://api.blackfuel.ai/v1/embeddings \
  -H "Authorization: Bearer $BLACKFUEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "BAAI/bge-multilingual-gemma2",
    "input": "Your text to embed"
  }'

Response

Success Response

200 OK
{
  "id": "embd-cffc94f6-0286-460f-bfaf-45a6172c535b",
  "object": "list",
  "created": 1785161169,
  "model": "BAAI/bge-multilingual-gemma2",
  "data": [
    {
      "index": 0,
      "object": "embedding",
      "embedding": [-0.88671875, -1.0234375, 3.421875, "..."]
    }
  ],
  "usage": {
    "prompt_tokens": 6,
    "total_tokens": 6,
    "completion_tokens": 0,
    "prompt_tokens_details": null
  }
}

Response Fields

FieldTypeDescription
idstringIdentifier for this response, prefixed embd-
objectstringAlways "list"
createdintegerUnix timestamp of the response
modelstringModel used for embedding
dataarrayArray of embedding objects. See Embedding Object.
usageobjectToken usage. See Usage Object.

Embedding Object

FieldTypeDescription
indexintegerIndex of this embedding in the request
objectstringAlways "embedding"
embeddingarray | stringThe embedding vector: an array of numbers, or a base64-encoded string when encoding_format is base64. Its length is the model's embedding dimension, and the values are unnormalised. The samples above print it with len(embedding).

Usage Object

FieldTypeDescription
prompt_tokensintegerTokens consumed by the input
total_tokensintegerTotal tokens billed for the request
completion_tokensintegerOutput tokens; embedding requests bill on prompt_tokens
prompt_tokens_detailsnullCached-input token breakdown

Batch Embeddings

Process multiple texts in a single request for better efficiency:

texts = [
    "First document to embed",
    "Second document to embed",
    "Third document to embed"
]

response = client.embeddings.create(
    model="BAAI/bge-multilingual-gemma2",
    input=texts
)

for i, item in enumerate(response.data):
    print(f"Document {i}: {len(item.embedding)} dimensions")

# Access specific embedding
first_embedding = response.data[0].embedding
const texts = [
  'First document to embed',
  'Second document to embed',
  'Third document to embed'
];

const response = await client.embeddings.create({
  model: 'BAAI/bge-multilingual-gemma2',
  input: texts
});

response.data.forEach((item, i) => {
  console.log(`Document ${i}: ${item.embedding.length} dimensions`);
});
curl -X POST https://api.blackfuel.ai/v1/embeddings \
  -H "Authorization: Bearer $BLACKFUEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "BAAI/bge-multilingual-gemma2",
    "input": [
      "First document to embed",
      "Second document to embed",
      "Third document to embed"
    ]
  }'

Embed a set of documents and a query in one batch each, then rank the documents by cosine similarity to the query. Rate limits are retried with exponential backoff — see the error handling guide for the full retry contract.

import os
import time

import openai

client = openai.OpenAI(
    base_url="https://api.blackfuel.ai/v1",
    api_key=os.environ["BLACKFUEL_API_KEY"],
)

documents = [
    "Python is a programming language",
    "Machine learning uses algorithms",
    "Cats are domestic animals",
]
query = "What programming languages exist?"


def embed(texts):
    for attempt in range(5):
        try:
            response = client.embeddings.create(
                model="BAAI/bge-multilingual-gemma2",
                input=texts,
            )
            return [item.embedding for item in response.data]
        except openai.RateLimitError:
            time.sleep(2**attempt)
    raise RuntimeError("rate limited after 5 attempts")


def cosine(a, b):
    dot = sum(x * y for x, y in zip(a, b))
    magnitude = sum(x * x for x in a) ** 0.5 * sum(y * y for y in b) ** 0.5
    return dot / magnitude


document_vectors = embed(documents)
query_vector = embed(query)[0]

ranked = sorted(
    ((cosine(query_vector, vector), document)
     for vector, document in zip(document_vectors, documents)),
    reverse=True,
)
for score, document in ranked:
    print(f"{score:.3f}  {document}")
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.blackfuel.ai/v1',
  apiKey: process.env.BLACKFUEL_API_KEY
});

const documents = [
  'Python is a programming language',
  'Machine learning uses algorithms',
  'Cats are domestic animals'
];
const query = 'What programming languages exist?';

async function embed(input) {
  for (let attempt = 0; attempt < 5; attempt++) {
    try {
      const response = await client.embeddings.create({
        model: 'BAAI/bge-multilingual-gemma2',
        input
      });
      return response.data.map((item) => item.embedding);
    } catch (error) {
      if (!(error instanceof OpenAI.RateLimitError)) throw error;
      await new Promise((resolve) => setTimeout(resolve, 2 ** attempt * 1000));
    }
  }
  throw new Error('rate limited after 5 attempts');
}

function cosine(a, b) {
  const dot = a.reduce((sum, value, i) => sum + value * b[i], 0);
  const norm = (v) => Math.sqrt(v.reduce((sum, value) => sum + value * value, 0));
  return dot / (norm(a) * norm(b));
}

const documentVectors = await embed(documents);
const [queryVector] = await embed(query);

documents
  .map((document, i) => ({ document, score: cosine(queryVector, documentVectors[i]) }))
  .sort((a, b) => b.score - a.score)
  .forEach(({ document, score }) => console.log(`${score.toFixed(3)}  ${document}`));

Available Embedding Models

Embedding model IDs, context windows, and per-token pricing come from the live catalog:

  • Model catalog — human-readable tables, including EU variants.
  • GET /v1/models — the same data as JSON. Filter on task equal to embedding, then read context_length for the input limit and pricing.prompt for the per-token price. See Models.

Error Responses

To read an error response and decide whether to retry, follow Error Handling.

Best Practices

See the best practices guide for caching, concurrency, and cost. Two points are specific to this endpoint: batch several texts into one request (see Batch Embeddings), and keep each input within the model's context_length from GET /v1/models.

On this page