Text Embedding API Endpoint

Version 2.197 (Release Notes ↗)

Description

The TEXT-EMBED API endpoint transforms textual data into numerical vectors, effectively capturing the semantic meaning and context of a stream of words (tokens). It supports multiple major languages and provides efficient embedding services for text data. This is beneficial for natural language processing tasks such as RAG, text classification, sentiment analysis, and text indexing.

HTTP Methods

JSON POST

HTTP Parameters

Required

Fields Type Description
input string The input text to generate an embedding vector for. A maximum 8192 tokens is allowed for each input sentence.
key String Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to.

Optional

Fields Type Description
dimension integer The output embedding vector dimension. The value must be either 512 or 1024. Defaults to 1024.

POST Request Body

This section outlines the requirements for POST requests, which are used instead of GET requests in specific scenarios.

Allowed Content-Types:

  • application/json

JSON is the default format for POST requests. If you are uploading a file via a JSON POST request, please ensure the file is base64 encoded within the JSON payload.

HTTP Response

application/json

The default response format is the PixLab simple LLM response format which is unified across our vLM API endpoints, and is suitable for most applications that includes the bare minimum information including the embedding vector, tokens count, etc.

PixLab Simple vLM Response Format


{
  "status": 200,
  "embedding": [2.8765, 1.9870, 4.9076, 7.9177, ...],
  "total_tokens": 512
}
Fields Type Description
status Integer HTTP 200 indicates success. Any other code indicates failure.
embedding List An array (or list) of floating points stream containing the complete output text embedding vector.
model String Underlying LLM model ID/Name.
total_tokens Integer Total number of ingested/output tokens.
error String Error description 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 want to upload your image directly.
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