Skip to main content
POST
/
v1
/
contextualizedembeddings
Create Contextualized Embeddings
curl --request POST \
  --url https://api.perplexity.ai/v1/contextualizedembeddings \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "input": [
    [
      "<string>"
    ]
  ]
}
'
import requests

url = "https://api.perplexity.ai/v1/contextualizedembeddings"

payload = { "input": [["<string>"]] }
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({input: [['<string>']]})
};

fetch('https://api.perplexity.ai/v1/contextualizedembeddings', 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://api.perplexity.ai/v1/contextualizedembeddings",
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([
'input' => [
[
'<string>'
]
]
]),
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://api.perplexity.ai/v1/contextualizedembeddings"

payload := strings.NewReader("{\n \"input\": [\n [\n \"<string>\"\n ]\n ]\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://api.perplexity.ai/v1/contextualizedembeddings")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"input\": [\n [\n \"<string>\"\n ]\n ]\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.perplexity.ai/v1/contextualizedembeddings")

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 \"input\": [\n [\n \"<string>\"\n ]\n ]\n}"

response = http.request(request)
puts response.read_body
{
  "object": "list",
  "data": [
    {
      "object": "list",
      "index": 123,
      "data": [
        {
          "object": "embedding",
          "index": 123,
          "embedding": "<string>"
        }
      ]
    }
  ],
  "model": "<string>",
  "usage": {
    "prompt_tokens": 123,
    "total_tokens": 123,
    "cost": {
      "input_cost": 123,
      "total_cost": 123,
      "currency": "USD"
    }
  }
}
{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Request body for creating contextualized embeddings

input
string[][]
required

Nested array structure where each inner array contains chunks from a single document. Chunks within the same document are encoded with document-level context awareness. Maximum 512 documents. Total chunks across all documents must not exceed 16,000. Total tokens per document must not exceed 32K. All chunks in a single request must not exceed 120,000 tokens combined. Empty strings are not allowed.

Required array length: 1 - 512 elements
Minimum array length: 1
Minimum string length: 1
model
enum<string>
required

The contextualized embedding model to use

Available options:
pplx-embed-context-v1-0.6b,
pplx-embed-context-v1-4b
dimensions
integer

Number of dimensions for output embeddings (Matryoshka). Range: 128-1024 for pplx-embed-context-v1-0.6b, 128-2560 for pplx-embed-context-v1-4b. Defaults to full dimensions (1024 or 2560).

Required range: 128 <= x <= 2560
encoding_format
enum<string>
default:base64_int8

Output encoding format for embeddings. base64_int8 returns base64-encoded signed int8 values. base64_binary returns base64-encoded packed binary (1 bit per dimension).

Available options:
base64_int8,
base64_binary

Response

Successful Response

Response body for contextualized embeddings request

object
string

The object type

Example:

"list"

data
Contextualized Embedding Object · object[]

List of contextualized embedding objects

model
string

The model used to generate embeddings

usage
Embeddings Usage · object

Token usage for the embeddings request