Skip to main content

Embeddings API

Use the Embeddings API to transform text into dense vector representations for semantic search, clustering, reranking, and Retrieval-Augmented Generation (RAG) workflows. TokenFlux forwards requests to the configured provider for the requested model and normalizes the response so that every embedding arrives as an array of floats.
This endpoint is wire-compatible with OpenAI’s /v1/embeddings, so you can reuse existing SDKs by swapping the base URL.

Create embeddings

Endpoint

Authentication

Send an API key using either header format. Quota is checked before the upstream provider is contacted; requests are rejected with 403 Forbidden when the remaining balance is below 0.01 credits.
or

Request body

Input formats

  • Single string: Generates one embedding.
  • Array of strings: Generates one embedding per entry.
  • Array of token arrays: Forward raw token IDs. TokenFlux falls back to a character-count heuristic if the tokenizer is unavailable.

Response

TokenFlux returns an OpenAI-style embedding response with normalized float vectors and usage accounting. Errors are serialized by the global error handler into { "success": false, "code": <status>, "message": "..." }.

Usage object

TokenFlux records embedding usage even when the upstream provider omits token counts by estimating tokens locally. prompt_tokens and total_tokens always reflect the tokenized length of input so that your dashboards and quotas remain accurate.

Error handling

Examples

cURL

Python

JavaScript (OpenAI SDK)

Operational notes

  • Base64 responses are decoded server-side so that every client receives consistent float arrays regardless of provider quirks.
  • TokenFlux saves usage immediately after the upstream response is received, ensuring accurate quotas and billing dashboards.
  • Use the Models API to determine which embedding models support adjustable dimensions and what token pricing applies.