Text Embedding API

Version 2.197 (Release Notes ↗)

Description

The TEXT-EMBED API endpoint converts text into dense vector representations that capture semantic meaning, context, and topical similarity. It is a practical building block for retrieval-augmented generation, semantic search, support automation, text classification, clustering, deduplication, and content recommendation workflows.

Developers can send a sentence, paragraph, or longer text input and receive an embedding vector that is ready for indexing in vector databases, ranking pipelines, or downstream machine learning systems. The endpoint supports multilingual text processing and fits well in both product-facing features and internal knowledge workflows.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
input string The input text to convert into an embedding vector. A maximum of 8192 tokens is allowed per request.
key String Your PixLab API Key ↗. You can also send the key in the WWW-Authenticate HTTP header and omit this parameter.

Optional

Fields Type Description
dimension integer The output embedding vector dimension. Supported values are 512 and 1024. The default is 1024.

POST Request Body

Use a POST request when you prefer sending the input in a JSON body instead of query parameters.

Allowed Content-Types:

  • application/json

For application/json requests, send the text value in the input field along with your API key and any optional parameters such as dimension. This endpoint is designed for text input and does not require file uploads.

HTTP Response

application/json

This endpoint returns a lightweight JSON response containing the generated embedding vector, model identifier, token usage, and any error details when a request fails.

Text Embedding Response Format


{
  "status": 200,
  "embedding": [2.8765, 1.9870, 4.9076],
  "model": "pixlab-text-embed",
  "total_tokens": 512
}
Fields Type Description
status Integer HTTP 200 indicates success. Any other code indicates failure.
embedding List An array of floating-point values containing the generated text embedding vector.
model String Identifier of the embedding model used to process the request.
total_tokens Integer Total token count reported for the request.
error String Error details returned when status != 200.

Code Samples


import requests
import json

# Generate text embedding vector for a given sentence or piece of text.
# Refer to: https://pixlab.io/endpoints/text-embed for the official documentation.

key = 'PIXLAB_API_KEY' # Get your API key from https://console.pixlab.io/

# Make the API call. Switch to POST if you prefer sending JSON in the request body.
req = requests.get('https://llm.pixlab.io/embedding',params={
  'input': "What is the meaning of life?",
  'key': key,
  'dimension': 1024, # Desired output vector dimension
})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
else:
  embedding = reply['embedding']
  print(f"Text embedding vector: {embedding}")
← Return to API Endpoint Listing