Skip to main content

Embeddings

/v1/embeddings returns vector embeddings for text, and for some models images, in the OpenAI format. Embedding calls go through the same virtual keys, budgets, routing and logging as chat calls, and the gateway can cache them so that repeated inputs cost nothing.

What this is for​

Search, retrieval and clustering all start with embeddings, and they are usually produced in bulk. Running them through the gateway means one key format for every provider, spend that shows up next to chat spend, a cache for inputs you embed again and again, and the ability to switch providers by changing one deployment instead of every pipeline.

Scenario​

A team indexes its internal wiki for retrieval. They deploy text-embedding-3-large on the gateway, give the indexing job a key with a monthly budget, and turn on caching so re-indexing unchanged pages is free. Later they add a second embedding model from another provider under its own name to compare search quality, without changing the job's credentials.

Steps​

  1. Deploy an embedding model. In the Admin UI open Models + Endpoints, pick the Add Model tab, choose OpenAI as the Provider, pick text-embedding-3-large, set Mode to Embedding - /embeddings, choose the credential and click Add Model. From the command line:

    curl -X POST http://localhost:4000/model/new \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{
    "model_name": "text-embedding-3-large",
    "spanway_params": {"model": "openai/text-embedding-3-large", "api_key": "os.environ/OPENAI_API_KEY"},
    "model_info": {"mode": "embedding"}
    }'

    In config.yaml the same deployment, plus a second provider, looks like this:

    model_list:
    - model_name: text-embedding-3-large
    spanway_params:
    model: openai/text-embedding-3-large
    api_key: os.environ/OPENAI_API_KEY
    model_info:
    mode: embedding
    - model_name: voyage-4-large
    spanway_params:
    model: voyage/voyage-4-large
    api_key: os.environ/VOYAGE_API_KEY
    model_info:
    mode: embedding

    Set mode: embedding so health checks send an embedding request, the Test Connect button uses the embeddings route, and the AI hub lists the model under the right mode.

  2. Test it before anyone depends on it. Click Test Connect on the Add Model tab, or open the model's detail view and run a health check. From the command line:

    curl -X POST http://localhost:4000/v1/embeddings \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "model": "text-embedding-3-large",
    "input": ["Spanway routes requests to providers.", "Virtual keys carry budgets."],
    "encoding_format": "float"
    }'

    input is a string or a list of strings. dimensions shortens the vectors on models that support it, encoding_format is float or base64, and user identifies the end user. Provider specific options such as an input_type are forwarded as described in provider specific params.

  3. Turn on caching for the indexing job as described in caching. Embeddings are cached by default once caching is on, so identical inputs are served from the cache. Only a cache with a custom supported_call_types list needs aembedding added to it.

  4. Watch spend. The Usage page and GET /model-insights show embedding spend per model next to chat spend, and GET /model_group/info?model_group=text-embedding-3-large shows the price per token and the vector size.

Expected result​

{
"object": "list",
"data": [
{"object": "embedding", "index": 0, "embedding": [0.0123, -0.0456, "..."]},
{"object": "embedding", "index": 1, "embedding": [0.0087, 0.0312, "..."]}
],
"model": "text-embedding-3-large",
"usage": {"prompt_tokens": 16, "total_tokens": 16}
}

Each vector for text-embedding-3-large has 3072 numbers unless you pass dimensions. The response carries x-spanway-model-id with the deployment that served it, and a cached answer carries x-spanway-cache-key. The spend log prices the call from the price map's per token embedding price.

Image and multimodal embeddings​

Models with the supports_embedding_image_input flag accept image parts in input, which the gateway converts to the provider format. See the provider pages for the models that support it.

Errors​

What you seeWhyFix
400 Invalid model name passed in model=text-embedding-3-largeNo deployment has that public name.Deploy it as in step 1, or check the name in GET /v1/models.
403 with key_model_access_deniedThe key may not call this model.Add the model, or its access group, to the key.
400 from the provider about dimensionsThe model does not support shortened vectors.Remove dimensions, or pick a model that supports it.
400 from the provider about the input lengthA string in input exceeds the model's token limit.Split long documents into chunks before embedding.
A health check sends a chat request and failsmodel_info.mode is not embedding.Set Mode to Embedding - /embeddings on the deployment.
Repeated inputs still cost moneyCaching is off, or the cache has a custom supported_call_types list without aembedding.Turn caching on, or add aembedding to the list.

Logs​

Each call is one row on the Logs page (/ui/logs) with its key, team, model group, deployment, tokens, cost, latency and status, failed calls included. Prompt and response text is kept only when the gateway is set to store it, see what the gateway stores. Operator log lines for routing, retries and fallbacks are in the log reference.

Providers​

The gateway's endpoint support matrix marks 35 provider integrations as supporting this endpoint:

AIHubMix (aihubmix), AI/ML API, Apertis (apertis), Azure, Azure AI, AWS - Bedrock, Chutes (chutes), Cohere, CometAPI, Eden AI, GigaChat, Hosted VLLM, Huggingface, Infinity, Jina AI, Mistral AI API, NanoGPT (nanogpt), Nebius AI Studio, Ollama, OpenAI, OpenAI-like (openai_like), OpenRouter, Pinstripes, Poe (poe), Qianwen AI Platform, QwenCloud, AWS - Sagemaker, Scaleway, Spanway Proxy, Synthetic (synthetic), Google - Vertex AI, VLLM, VoyageAI by MongoDB, IBM - Watsonx.ai, Xinference.