Embeddings

POST /v1/embeddings

Generate a vector embedding (or batch of embeddings) for one or more text inputs. Compatible with the OpenAI Embeddings API.

Headers

Header Required Description
Authorization Yes Bearer <api-key-or-jwt>
Content-Type Yes application/json
X-Quantized-Provider No Pin a provider by slug (openai, openrouter), or one specific connection as <provider>/<connection>. The pin narrows the providers your license allows and never widens them. A malformed value or a disallowed provider returns 400.
X-Quantized-Metadata No A flat JSON object of scalar values, recorded with the request for your own attribution. Invalid JSON or nested values return 400. See Authentication.

Request body

Field Type Required Default Description
model string Yes — Model identifier (e.g. text-embedding-3-small)
input string, array of strings, list[int], or list[list[int]] Yes — Text(s) to embed. A string or list of strings returns one vector per input; pre-tokenized token arrays are also accepted and forwarded to the provider
dimensions integer No null Truncate output vector dimensionality. Supported on text-embedding-3-small and text-embedding-3-large. Must be >= 1
encoding_format string No null (provider default, "float") Output encoding: "float" returns the vector as a JSON array of numbers; "base64" returns it as a base64 string, relayed verbatim from the provider
user string No null End-user identifier forwarded to the provider for abuse monitoring
Strict validation

The serializer uses extra="forbid" — any field not listed above is rejected with 400 invalid_request. This keeps typos from being silently dropped. Notable fields not accepted in v1: input_type, output_dtype, multimodal input.

Examples

cURL — single string
cURL — batch
Python (OpenAI SDK)
Python (httpx)
curl -X POST https://api.quantized.us/v1/embeddings \
  -H "Authorization: Bearer sk-quantized-YOUR-KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The quick brown fox jumps over the lazy dog."
  }'
curl -X POST https://api.quantized.us/v1/embeddings \
  -H "Authorization: Bearer sk-quantized-YOUR-KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-3-small",
    "input": ["one", "two", "three"]
  }'
from openai import OpenAI

client = OpenAI(
    api_key="sk-quantized-YOUR-KEY",
    base_url="https://api.quantized.us/v1",
)

resp = client.embeddings.create(
    model="text-embedding-3-small",
    input=["one", "two", "three"],
)
for item in resp.data:
    print(item.index, len(item.embedding))
import httpx

response = httpx.post(
    "https://api.quantized.us/v1/embeddings",
    headers={"Authorization": "Bearer sk-quantized-YOUR-KEY"},
    json={
        "model": "text-embedding-3-small",
        "input": "Hello world",
        "dimensions": 512,
    },
)
data = response.json()
print(len(data["data"][0]["embedding"]))  # 512

Response

{
  "object": "list",
  "model": "text-embedding-3-small",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [0.0123, -0.0456, 0.0789, ...]
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "total_tokens": 10,
    "credits_used": 2
  }
}

Response fields

Field Type Description
object string Always "list"
model string Model id echoed from the request (with any provider prefix preserved)
data array One entry per input, ordered by index
data[].object string Always "embedding"
data[].index integer Position of this embedding in the input batch
data[].embedding array of floats or string The vector: a JSON array of floats by default, or a base64 string when encoding_format: "base64" was requested
usage.prompt_tokens integer Input token count (provider-reported)
usage.total_tokens integer Equal to prompt_tokens for embeddings (no output tokens)
usage.credits_used integer Micro-credits consumed by this request
No streaming

Embedding endpoints are not streamable on any provider. stream: true is not accepted.

Models

Model id Native dimension Accepts dimensions? Public list rate
text-embedding-3-small 1536 Yes $0.02 / 1M tokens
text-embedding-3-large 3072 Yes $0.13 / 1M tokens
text-embedding-ada-002 1536 No $0.10 / 1M tokens
ada-002 returns a versioned id

When you request text-embedding-ada-002, OpenAI’s response echoes the versioned id text-embedding-ada-002-v2 in the model field. Quantized’s billing rate-table is keyed on the unversioned id, so this has no effect on cost. Client code that round-trips response.model into a follow-up request should preserve whatever id OpenAI returned.

When routing through OpenRouter, the openai/ prefix is optional: the router translates text-embedding-3-small to OpenRouter’s name for the model. Sending openai/text-embedding-3-small also works and keeps the request on OpenRouter.

Billing uses the catalog rate for the model on every provider; upstream cost data is not used. A model id the catalog cannot resolve is billed at a conservative fallback rate of $1.10 / 1M tokens.

Discovery via /v1/models

The three OpenAI embedding models are listed in GET /v1/models alongside chat models. Filter for embeddings either by:

  • supported_features contains "embeddings" (recommended, semantic):
    models = response.json()["data"]  # GET /v1/models returns {"object": "list", "data": [...]}
    embedding_models = [m for m in models if "embeddings" in m.get("supported_features", [])]
    
  • output_modality.text == false — embedding models declare no media-modality output because the response is a vector, not generated text. Chat models have output_modality.text == true.

The catalog entries also expose pricing in cost.prompt (USD per 1M input tokens).

Providers

Provider Slug
OpenRouter openrouter
OpenAI Direct openai

Without X-Quantized-Provider, the router picks among the providers that carry the requested model, preferring your institution’s own provider keys, then the providers marked as default for your institution, and picks randomly among ties. Pin X-Quantized-Provider when you need a repeatable provider.

# Force OpenRouter passthrough
curl -X POST https://api.quantized.us/v1/embeddings \
  -H "Authorization: Bearer sk-quantized-YOUR-KEY" \
  -H "X-Quantized-Provider: openrouter" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/text-embedding-3-small", "input": "hello"}'

Errors

Status Code Condition
400 invalid_request Request body failed validation: a missing or invalid field, or an unrecognized field (e.g. stream, input_type, or dimensions < 1). param names the field
400 invalid_request Malformed X-Quantized-Provider header (param: "X-Quantized-Provider")
400 invalid_metadata_header Invalid X-Quantized-Metadata header
400 invalid_request The provider rejected the request (e.g. invalid token ids); the provider’s message is returned
400 context_length_exceeded An input is longer than the model accepts
400 no_provider_available No provider available for the model or endpoint (e.g. an unknown X-Quantized-Provider slug, or a pin your license doesn’t allow)
401 missing_api_key, invalid_api_key, api_key_expired, license_inactive Missing, invalid, or expired API key, or an inactive license
402 budget_exhausted Your license is out of budget. metadata names the limit that blocked the request
403 policy_denied Your license’s policy does not allow this service or parameter value (param names the parameter)
403 content_policy_violation Request blocked by a guardrail
404 model_not_found Unknown model id (forwarded from the provider)
429 rate_limit_exceeded The provider rate-limited the request. retry-after is set when the provider sent one
500 internal_error Unexpected error, or a budget configuration error
502 provider_error The provider returned a 5xx or an invalid response, or the connection dropped
503 provider_misconfigured Our credentials for the provider are missing or were rejected
503 policy_unavailable Your license’s policy can’t be evaluated
504 upstream_timeout The provider timed out

Every error uses the standard error body. Branch on the status and code; see the Error reference for each.

Empty input is accepted

An empty string "" (or a list containing one) is not rejected — OpenAI returns a valid embedding with prompt_tokens: 0. The transaction is recorded with zero cost.

Out of scope on this endpoint

The following are not accepted by /v1/embeddings (the OpenAI-shape endpoint) and may be added in a future release:

  • Multimodal input (ContentPart[])
  • output_dtype quantized embeddings
  • input_type / task_type task-conditioning fields
Native-shape sibling endpoints

For provider-specific fields the OpenAI shape doesn’t cover, use the native-shape endpoints:

  • /v1/aws-bedrock/embeddings — Amazon Titan v2 (with normalize, embeddingTypes) and Cohere v3 (with input_type, quantized output)
  • /v1/gemini/embeddings — Google Gemini (with task_type, output_dimensionality, title); automatic single/batch routing