Image Embedding API Endpoint

Version 2.197 (Release Notes ↗)

Description

The Image Embedding API (img-embed) endpoint from PixLab allows developers to extract high-dimensional semantic vector representations also known as embeddings for any input image. These image embeddings are numerical vectors that capture the visual and contextual features of the image, enabling powerful capabilities such as visual similarity search, clustering, classification, and AI-assisted content understanding.

The img-embed API endpoint is built on top of state-of-the-art vision models from the Vision Platform trained on diverse datasets, allowing you to generate embeddings that remain consistent across lighting conditions, noise, or orientation. Whether you're working on building a visual recommendation engine, automating deduplication, or building an image search backend, this API can plug directly into your workflow.

Developers can submit either:

  • A direct file upload (multipart/form-data)
  • Or a public image URL (via url parameter)
Upon request, the API returns a JSON object containing the normalized image embedding vector as a fixed-length float32[] array, ready for indexing or analysis.

All embeddings are compatible with ANN (Approximate Nearest Neighbor) libraries such as FAISS, HNSWlib, and scikit-learn, enabling real-time, scalable image matching or similarity lookups across massive datasets.

Use Cases

  • Image similarity search - Build a search engine for finding visually similar photos or assets
  • Duplicate detection - Automatically identify near-identical images in large datasets
  • Visual clustering - Group images based on visual themes or categories using K-means or DBSCAN
  • AI-powered moderation - Compare uploads against flagged or inappropriate content
  • Reverse image lookup - Match input image against indexed gallery using ANN

Integration & Developer Notes

The img-embed API endpoint can be integrated via HTTP POST requests using any language (Python, PHP, JavaScript, etc.). It supports both synchronous and batched processing.

You can start right away by obtaining your API Key from the PixLab Console ↗. For integration code samples, refer to the section below ↓

Technical Summary

The img-embed API endpoint is part of PixLab's Vision Platform, optimized for image vectorization, AI-powered image search, photo analysis, and deep learning inference at scale. Whether you're developing a photo tagging system, ML pipeline, or creative application, this API enables fast, scalable, and accurate computer vision solutions through REST.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img BASE64 String BASE 64 encoded string representing the image contents you want to generate an image embedding vector for.
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:

  • multipart/form-data
  • application/json

Use multipart/form-data to directly upload your image from you app (Refer to The PixLab Github Repository↗ for a working example). If you're using JSON, the media file must already be uploaded. Consider calling store to upload an image before invoking this endpoint.

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": 1024,
}
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 image embedding vector.
total_tokens Integer Total number of ingested/output tokens.
error String Error description when status != 200.

Code Samples


import requests
import json

# Generate image embedding vector for a given image using the PixLab image embedding API
# Refer to: https://pixlab.io/endpoints/img-embed for the official documentation.
#
# Convert images into numerical vectors for efficient image classification, similarity search, and so on.

# Target Image URL we want to generate embedding for
# Change to any link or switch to POST if you want to upload your image directly.
imgUrl = 'https://pixlab.io/assets/images/nature31.jpg' 

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://api.pixlab.io/imgembed',params={
  'img': imgUrl,
  'key': key,
  'dimension': 1024, # Output vector dimension
})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
else:
  embedding = reply['embedding']
  print(f"Image embedding vector: {embedding}")
← Return to API Endpoint Listing