Embeddings
Create vector embeddings
POST /v1/embeddings
Authorization: Bearer YOUR_TOKENFLUX_KEY
Content-Type: application/jsoncurl https://tokenflux.ai/v1/embeddings \
-H "Authorization: Bearer YOUR_TOKENFLUX_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_EMBEDDING_MODEL_ID",
"input": "TokenFlux API documentation"
}'Select an embedding-capable model from Models & pricing. The response uses the OpenAI-compatible embeddings shape.
Inputs and options
Use embeddings for semantic search, clustering or retrieval-augmented generation (RAG). model must select an embedding model available to your key. input can be one string or an array of strings for a batch. Token-array input depends on provider support; text input is the portable choice.
Use encoding_format: "float" for numeric vectors, or "base64" only with a model and client that support it. Do not assume the gateway converts every base64 response to floats. dimensions requests an output size only for models that support that option. Keep the same model and dimensions for stored documents and search queries.
Batch example
Install the OpenAI Python SDK with pip install openai. Set TOKENFLUX_API_KEY and TOKENFLUX_EMBEDDING_MODEL in your environment:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKENFLUX_API_KEY"],
base_url="https://tokenflux.ai/v1",
)
result = client.embeddings.create(
model=os.environ["TOKENFLUX_EMBEDDING_MODEL"],
input=["The quick brown fox", "A similar sentence for comparison"],
encoding_format="float",
)
for item in result.data:
print(item.index, len(item.embedding))Response
data contains an embedding per input. Use index to associate each vector with its input. With float encoding, embedding is an array of numbers. Its length depends on the model and supported dimensions. This example shortens the vector for readability:
{
"object": "list",
"data": [{ "object": "embedding", "index": 0, "embedding": [0.0023, -0.0093, 0.0182] }],
"model": "YOUR_EMBEDDING_MODEL_ID",
"usage": { "prompt_tokens": 8, "total_tokens": 8 }
}usage reports token counts when supplied. Check Usage for request costs. See the API overview for errors and retries, and Models for model discovery.