QUERY API Endpoint

Version 2.197 (Release Notes ↗)

Description

The QUERY API endpoint enables retrieval of natural language responses for image-related content, supporting multiple languages. Example queries include: How many people are in the image?, What is in the image?, Where was the image taken?, and so on. The API supports various natural languages, including English, Arabic, Spanish, etc., and is ideal for e-commerce owners, developers, and marketing agencies seeking to integrate image query functionality into their products or catalogs.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL URL to the input image you want to query in the event of a GET request. If you want to upload an image directly from your app, then submit a multipart/form-data POST request instead. Refer to the POST Request Data section below.
query String The query related to the image content you want to ask and receive a response 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
lang String Default to english. Language to which you want to receive the image query response.

POST Request Body

This section details the requirements for using a POST request instead of a simple GET request.

Allowed Content-Types:

  • multipart/form-data
  • application/json

Use multipart/form-data to directly upload your image from you app (see the REST API code samples or 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

This endpoint always returns a JSON object containing the query response message related to the image contents. Response fields include:

Fields Type Description
status Integer HTTP 200 indicates success. Any other code indicates failure.
response String AI-generated natural language response to your image content query, delivered in the selected language (defaults to English).
error String Error description when status != 200.

Code Samples



import requests
import json

# Get natural language responses to image-related queries

# Target Image: Change to any link or switch to POST if you want to upload your image directly, refer to the REST API code samples for more info.
img = 'https://pixlab.io/assets/images/nature31.jpg' 

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

req = requests.get('https://api.pixlab.io/query',params={
  'img':img,
  'key':key,
  'lang':'english',
  'query':'What does this image depict? Can you guess the location where it was taken?'
})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
else:
  response = reply['response']
  print(f"Query Response: {response}")
← Return to API Endpoint Listing