Image Embedding API

Version 2.197 (Release Notes ↗)

Description

The Image Embedding API (img-embed) converts an image into a dense vector representation that you can compare, index, and search. It gives developers a practical way to build visual similarity search, product matching, duplicate detection, recommendation systems, and image understanding workflows over standard HTTP requests.

These embeddings are useful when you need fast visual retrieval across ecommerce catalogs, media libraries, marketplaces, moderation datasets, or internal asset systems. Because the output captures high-level visual features instead of raw pixels, it works well for near-duplicate matching, related image discovery, and downstream classification or ranking pipelines.

You can submit images in either of these ways:

  • A direct file upload with multipart/form-data
  • A public image URL passed to img

The API returns a JSON response containing the generated image embedding vector as a fixed-length float32[] array, ready for indexing, retrieval, and analysis.

All embeddings are compatible with ANN libraries such as FAISS, HNSWlib, and scikit-learn, making it straightforward to plug this endpoint into production search, recommendation, or catalog analysis stacks.

Use Cases

  • Visual search - Find related photos, product shots, or design assets in large image libraries
  • Duplicate detection - Identify near-identical images across catalogs, uploads, or archives
  • Visual clustering - Group images by style, theme, or subject for tagging and organization
  • Moderation workflows - Compare uploads against flagged reference sets or policy datasets
  • Reverse image lookup - Match an input image against an indexed gallery using ANN search

Integration & Developer Notes

The img-embed endpoint can be integrated from any stack over HTTP. It fits cleanly into retrieval systems, vector databases, recommendation services, and ML preprocessing pipelines.

You can start by getting an API key from the PixLab Console ↗. For working integration examples in Python, JavaScript, and PHP, refer to the code samples below ↓.

Technical Summary

The img-embed API endpoint is part of PixLab's Vision Platform and is built for teams that need reliable image vectorization without running their own embedding infrastructure. Use it to power catalog search, asset organization, recommendation features, or downstream computer vision pipelines through a simple REST interface.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img String Input image source. For simple GET requests, pass a public image URL. For direct uploads, send a multipart/form-data POST 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. The value must be either 512 or 1024. Defaults to 1024.

POST Request Body

This section outlines when to use POST requests instead of a simple GET request.

Allowed Content-Types:

  • multipart/form-data
  • application/json

Use multipart/form-data to upload an image directly from your app. Refer to the PixLab GitHub Repository ↗ for a working example. If you're using application/json, pass a public image URL or a previously stored asset reference in img. The store endpoint can help when you want to upload media before invoking this endpoint.

HTTP Response

application/json

This endpoint returns a lightweight JSON response that includes the generated embedding vector, request token usage, and any error details when a call fails.

Image Embedding Response Format


{
  "status": 200,
  "embedding": [2.8765, 1.9870, 4.9076],
  "total_tokens": 1024
}
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 image embedding vector.
total_tokens Integer Total token count reported for the request.
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