Skip to main content

POST /v1/embeddings

Converts input into a high-dimensional vector representation (embedding). Embeddings are used for semantic search, clustering, classification, and retrieval-augmented generation (RAG). The gateway supports text, image, and video embedding inputs depending on the provider. The response always includes a data array with embedding vectors indexed to match the input.

Request headers

x-portkey-provider
string
The provider to route the request to (e.g. openai, cohere, google-vertex-ai). Required when not using a config.
x-portkey-api-key
string
Your provider API key.
x-portkey-config
string
A JSON config object or config ID that defines routing, fallbacks, retries, and more.
x-portkey-virtual-key
string
A virtual key ID from Portkey Cloud.

Request body

model
string
required
The embedding model to use (e.g. text-embedding-3-small, embed-english-v3.0).
input
string | string[] | object[]
required
The text or texts to embed. Accepts:
  • A single string
  • An array of strings for batch embedding
  • An array of EmbedInput objects with text, image, or video fields for multimodal providers
encoding_format
string
default:"float"
The format of the returned embeddings. One of float or base64.
dimensions
integer
The number of dimensions in the output embedding. Only supported by models that accept a dimensions parameter (e.g. text-embedding-3-small).
user
string
A unique identifier for the end user, used for monitoring.

Response

object
string
Always list.
data
object[]
An array of embedding objects, one per input item, in the same order as the input.
model
string
The model used to generate the embeddings.
usage
object
Token usage for this request.

Code examples

curl http://localhost:8787/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "x-portkey-provider: openai" \
  -H "x-portkey-api-key: $OPENAI_API_KEY" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The Portkey AI Gateway routes requests to 250+ LLMs.",
    "encoding_format": "float"
  }'

Build docs developers (and LLMs) love