Skip to main content
Use POST /v2/embed to create one embedding per input sample. The endpoint returns all results in one JSON response, in input order. It uses the served model’s existing embedding and pooling implementation. The request and response format targets vLLM v0.32.0’s Cohere-style embedding API. For the OpenAI request format, use /v1/embeddings.

Start an embedding server

The commands below target Linux with one NVIDIA CUDA GPU and a SGLang build that includes /v2/embed. Install SGLang using the installation guide. The client example requires the Python requests package. Start Qwen/Qwen3-Embedding-0.6B:
This example uses a short context for testing. The model override declares support for 128-dimensional output so you can run the dimension example below. It does not change the model weights. Do not use this override to claim dimension-reduction support for a model that lacks it. The commands use a public Hugging Face model and do not set an API key. If you configure server authentication, include Authorization: Bearer YOUR_API_KEY in each request. Keep the tokenizer enabled; /v2/embed requires it.

Embed text

After the server is ready, send a JSON request:
The first vector represents the apple sentence. The second represents the spaceship sentence. Omitting model selects the model already served by this process; the request does not load another model.

Request fields

Send Content-Type: application/json. Provide exactly one non-null field among texts, images, and inputs, and give it a nonempty list. For example, sending both texts and images returns HTTP 400. Use inputs to combine text and images in one sample. All samples in a request share the task, dimension, encoding, and truncation settings. Unknown JSON fields are ignored. In particular, stream: true does not enable streaming.

Task instructions

input_type is a model-defined key. The server reads string-valued entries from the model’s task_instructions configuration. If that mapping is empty, it reads prompts from config_sentence_transformers.json. For example, a model with this instruction mapping accepts "input_type": "query":
An unknown key returns HTTP 400 and lists the available keys. There is no automatic search_document instruction. For texts, a nonempty instruction becomes the system message when a chat template is available. Without a chat template, the server concatenates the instruction and the text exactly; it inserts no separator. In the example above, the instruction’s trailing space separates it from the text. When input_type is omitted, texts are tokenized without adding a task instruction or rendering a chat template. images and inputs always use a chat template, including inputs containing only text.

Image and mixed inputs

Image request conversion is implemented. Real image-model GPU inference and Nemotron 3.5 Embed HF-reference validation have not been completed for this endpoint. The examples below specify the request format; they do not provide a validated multimodal model deployment recipe.
Image requests require a multimodal embedding model and an embedding-compatible chat template that represents images. The text-only Qwen3 server above rejects image requests with HTTP 400. An unavailable template also returns HTTP 400. Image strings can be HTTP(S) URLs or base64 data URLs such as data:image/png;base64,.... The server must be able to fetch or decode the image. A content block uses one of these forms: The image_url field is an object containing url, not a string. Audio and video content blocks are not accepted. The following example constructs two request bodies from a local PNG. Place an existing PNG at image.png before running it:
Send one of these bodies as the JSON body of POST /v2/embed to a multimodal embedding server. In mixed_request, vector 0 represents the text and image together; vector 1 represents the text-only sample. Each content list must be nonempty and can contain multiple images.

Token limits and truncation

The budget applies separately to each sample after task instructions, templates, special tokens, and multimodal preprocessing have been applied. The server input limit accounts for context length, reserved tokens, and scheduling limits; it is not necessarily equal to --context-length. Let B be the server’s available input-token limit and N a positive max_tokens value. For texts not rendered through a chat template, tokens added by the tokenizer (such as BOS or EOS) are kept and count toward the budget; only text tokens are removed. If the budget cannot fit the required special tokens, the request returns HTTP 400. A budget equal to their count can leave only special tokens. For example, if the tokenizer produces [A, B, C, D, <|endoftext|>], with the final EOS token added by the tokenizer and max_tokens: 3:
  • END removes text tokens from the end and retains [A, B, <|endoftext|>].
  • START removes text tokens from the start and retains [C, D, <|endoftext|>].
  • NONE returns HTTP 400 instead of truncating.
This preservation rule does not apply to tokens already present in a rendered chat template. For template-rendered texts and text-only inputs, END keeps the beginning of the token sequence and START keeps the end, up to the effective budget; template tokens outside that slice can be removed. A final empty token sequence returns HTTP 400. An empty string is not rejected solely for being empty: the result depends on the tokens added during preprocessing. For multimodal inputs, truncation has additional restrictions:
  • START returns HTTP 400 when shortening is required.
  • END can remove only a trailing text region while keeping every image token span and boundary token.
  • Image inputs with MRoPE or separate vision-position metadata cannot be shortened by this endpoint. Missing or invalid image span boundaries also cause HTTP 400 when shortening is required.
  • Image inputs without a complete, consistent expanded token sequence return HTTP 400 in all three modes, even if the input fits the token budget.

Output dimensions and encodings

Set output_dimension to request a shorter vector. The server checks that the model supports Matryoshka embeddings, that the dimension is in its configured allowed list when one exists, and that it does not exceed the model’s maximum dimension. A failed check returns HTTP 400. The server command above explicitly enables 128-dimensional output. Request that dimension and two encodings:
For N samples with dimension D, the response contains: Binary encodings require D to be divisible by 8; otherwise the request returns HTTP 400. Each component greater than or equal to zero maps to bit 1, and each negative component maps to bit 0. The first component occupies the most significant bit. For example, [1, -1, 1, -1, 1, -1, 1, -1] becomes 10101010, so ubinary is [170] and binary is [42]. Requesting several encodings converts the same inference result into each format.

Response fields

A successful request returns HTTP 200 with these fields: Token counts include preprocessing and reflect truncation. For a mixed batch containing an image, image_tokens includes text tokens and tokens from text-only samples as well. It is request-level accounting, not a count of visual tokens alone or a monetary charge.

Errors

The endpoint uses an error object containing message, type, param, and code. param is null when no parameter name is supplied. For example, requesting an unknown task key on a model with no configured instructions returns HTTP 400 with this structure:
Every 5xx response uses the generic message Internal server error; the detail is written to the server log. The response keeps its status code, such as 503, and headers such as Retry-After. Server authentication and scheduling also apply their existing checks.

Current scope

  • GPU integration tests cover text requests with Alibaba-NLP/gte-Qwen2-1.5B-instruct, Qwen/Qwen3-Embedding-0.6B, and nvidia/Nemotron-3-Embed-1B-BF16. These tests compare results with /v1/embeddings. The Nemotron test also checks the model-defined query and document task prefixes.
  • The endpoint adapts requests to installed model implementations. It does not add Nemotron model implementations.
  • Encoder/language disaggregation is not supported for these embedding requests. Use a server that runs the model and its encoder together for image requests.
  • The endpoint returns embeddings only. It does not implement Cohere chat, text generation, reranking, audio/video inputs, or streaming.