Skip to contentNewDeepSeek V4.1 Flash 1017 is now availableTry it now
Docs / Embeddings

Embeddings

Turn text or images into vectors with an OpenAI-compatible embeddings endpoint.

The Embeddings API returns one vector for each input in one request. It is compatible with the OpenAI embeddings API. Use it with an embedding model. An embedding model serves only embeddings requests.

Endpoint

text
POST https://api.inference.net/v1/embeddings

Send your API key in the Authorization: Bearer header, as for other endpoints. The response is one JSON object. The endpoint does not stream.

To send embeddings requests asynchronously, use POST /v1/slow/embeddings. See Asynchronous Inference.

Request

FieldTypeRequiredDescription
modelstringYesThe identifier of an embedding model.
inputstring or arrayYesThe input to embed: a string, an array of strings, a token-id array, or an array of token-id arrays. Image models also accept image messages (see below).
encoding_formatstringNofloat (the default) returns each vector as an array of numbers. base64 returns each vector as a base64 string of little-endian float32 values.
dimensionsintegerNoThe number of dimensions of each vector. Only models that support shortened vectors accept it.
userstringNoAn identifier for your end user.

An image input is an array that holds one user message with one image_url part. The URL is a base64 data URI (image/png, image/jpeg, image/gif or image/webp) or an https URL. To embed several images, send an array of these messages (at most 50).

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.inference.net/v1",
  apiKey: process.env.INFERENCE_API_KEY,
});

const response = await client.embeddings.create({
  model: "<embedding-model>",
  input: ["The quick brown fox", "jumps over the lazy dog"],
});

console.log(response.data[0].embedding);

An image input:

json
{
  "model": "<image-embedding-model>",
  "input": [
    {
      "role": "user",
      "content": [{ "type": "image_url", "image_url": { "url": "https://example.com/cat.png" } }]
    }
  ]
}

Response

FieldTypeDescription
objectstringAlways list.
dataarrayOne item for each input, in input order. Each item is {"object": "embedding", "index": <position>, "embedding": <vector>}.
modelstringThe model identifier you sent.
usage.prompt_tokensintegerThe number of input tokens.
usage.total_tokensintegerThe same as usage.prompt_tokens.
json
{
  "object": "list",
  "data": [
    { "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456, "..."] },
    { "object": "embedding", "index": 1, "embedding": [0.0789, 0.0012, "..."] }
  ],
  "model": "<embedding-model>",
  "usage": { "prompt_tokens": 10, "total_tokens": 10 }
}

The x-inference-id response header contains the generation id.

Billing

You pay for usage.prompt_tokens as input tokens. There are no output tokens.

Errors

Errors use the same JSON shape as other endpoints: {"error": {"message": "...", "type": "..."}}.

StatusCause
400The body is not valid: input or model is missing, input has the wrong shape, encoding_format is not float or base64, or dimensions is not a positive integer. error.fields names each bad field.
400The model is not an embedding model.
403Your team does not have access to the model.
404The model does not exist.