API Endpoint Access URL
https://api.pixlab.io/query
Get your API key and test query ↗Description
The QUERY API endpoint lets you ask natural-language questions about an image and receive a grounded response based on the visual content. It is useful for product catalogs, support tools, moderation review, visual assistants, and internal workflows where teams need more than static labels or captions.
Typical prompts include questions about visible objects, scene details, product attributes, counts, likely setting, or other contextual information present in the image. The endpoint supports multiple languages, making it practical for customer-facing features as well as developer and business workflows across regions.
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 question or instruction you want to ask about the submitted image. |
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 |
|---|---|---|
lang |
String | Response language. Defaults to english. |
POST Request Body
This section explains when to use a POST request instead of a simple GET request.
Allowed Content-Types:
multipart/form-dataapplication/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 JSON object containing the generated answer for your image prompt. Response fields include:
| Fields | Type | Description |
|---|---|---|
status |
Integer | HTTP 200 indicates success. Any other code indicates failure. |
response |
String | Natural-language answer generated from the submitted image and prompt, returned in the selected language. |
error |
String |
Error details returned 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}")
// Ask a natural-language question about an image and get a grounded response.
// 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.
const img = 'https://pixlab.io/assets/images/nature31.jpg';
const key = 'PIXLAB_API_KEY'; // Get your API key from https://console.pixlab.io/
fetch('https://api.pixlab.io/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
img: img,
key: key,
lang: 'english',
query: 'What does this image depict?'
})
})
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.error(reply.error);
} else {
const response = reply.response;
console.log(`Query Response: ${response}`);
}
})
.catch(error => console.error('Error:', error));
<?php
# 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/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/query?img=' . urlencode($img) . '&key=' . $key . '&query=What does this image depict?');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$reply = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
$response = $reply['response'];
echo "Query Response: " . $response;
}
require 'net/http'
require '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/
uri = URI('https://api.pixlab.io/query')
params = {
'img' => img,
'key' => key,
'query' => 'What does this image depict?',
}
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
response = reply['response']
puts "Query Response: #{response}"
end
Similar API Endpoints
tagimg, nsfw, img-embed, docscan, text-embed, chat, mogrify, facelookup ↗, faceverify ↗, describe