Skip to main content
POST
/
embeddings
Submit an embedding request
curl --request POST \
  --url https://openrouter.ai/api/v1/embeddings \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "dimensions": 1536,
  "input": "The quick brown fox jumps over the lazy dog",
  "model": "openai/text-embedding-3-small"
}
'
import requests

url = "https://openrouter.ai/api/v1/embeddings"

payload = {
"dimensions": 1536,
"input": "The quick brown fox jumps over the lazy dog",
"model": "openai/text-embedding-3-small"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
dimensions: 1536,
input: 'The quick brown fox jumps over the lazy dog',
model: 'openai/text-embedding-3-small'
})
};

fetch('https://openrouter.ai/api/v1/embeddings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/embeddings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'dimensions' => 1536,
'input' => 'The quick brown fox jumps over the lazy dog',
'model' => 'openai/text-embedding-3-small'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://openrouter.ai/api/v1/embeddings"

payload := strings.NewReader("{\n \"dimensions\": 1536,\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"model\": \"openai/text-embedding-3-small\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/embeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"dimensions\": 1536,\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"model\": \"openai/text-embedding-3-small\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://openrouter.ai/api/v1/embeddings")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"dimensions\": 1536,\n \"input\": \"The quick brown fox jumps over the lazy dog\",\n \"model\": \"openai/text-embedding-3-small\"\n}"

response = http.request(request)
puts response.read_body
{
  "data": [
    {
      "embedding": [
        0.0023064255,
        -0.009327292,
        0.015797347
      ],
      "index": 0,
      "object": "embedding"
    }
  ],
  "model": "openai/text-embedding-3-small",
  "object": "list",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}
{
"error": {
"code": 400,
"message": "Invalid request parameters"
}
}
{
"error": {
"code": 401,
"message": "Missing Authentication header"
}
}
{
"error": {
"code": 402,
"message": "Insufficient credits. Add more using https://openrouter.ai/credits"
}
}
{
"error": {
"code": 404,
"message": "Resource not found"
}
}
{
"error": {
"code": 429,
"message": "Rate limit exceeded"
}
}
{
"error": {
"code": 500,
"message": "Internal Server Error"
}
}
{
"error": {
"code": 502,
"message": "Provider returned error"
}
}
{
"error": {
"code": 503,
"message": "Service temporarily unavailable"
}
}
{
"error": {
"code": 524,
"message": "Request timed out. Please try again later."
}
}
{
"error": {
"code": 529,
"message": "Provider returned error"
}
}

Authorizations

Authorization
string
header
required

API key as bearer token in Authorization header

Body

application/json

Embeddings request input

input
required

Text, token, or multimodal input(s) to embed

Example:

"The quick brown fox jumps over the lazy dog"

model
string
required

The model to use for embeddings

Example:

"openai/text-embedding-3-small"

dimensions
integer

The number of dimensions for the output embeddings

Required range: x >= 1
Example:

1536

encoding_format
enum<string>

The format of the output embeddings

Available options:
float,
base64
Example:

"float"

input_type
string

The type of input (e.g. search_query, search_document)

Example:

"search_query"

provider
object | null

Provider routing preferences for the request.

Example:
{ "allow_fallbacks": true }
user
string

A unique identifier for the end-user

Example:

"user-1234"

Response

Embedding response

Embeddings response containing embedding vectors

data
object[]
required

List of embedding objects

Example:
[
{
"embedding": [0.0023064255, -0.009327292, 0.015797347],
"index": 0,
"object": "embedding"
}
]
model
string
required

The model used for embeddings

Example:

"openai/text-embedding-3-small"

object
enum<string>
required
Available options:
list
id
string

Unique identifier for the embeddings response

Example:

"embd-1234567890"

usage
object

Token usage statistics

Example:
{ "prompt_tokens": 8, "total_tokens": 8 }