PixQuery API Guide
Image Captioning 📷
/caption
Get your api keys from the API dashboard.

Here are some code snippets in different languages on how to use the captioning API.
Replace <your-api-key>
with your API key and <image-base64-string>
with your image’s base64 string.
cURL
curl -X 'POST' \ 'https://api.pixquery.com/caption' \ -H 'accept: application/json' \ -H 'apikey: <your-api-key>' \ -H 'Content-Type: application/json' \ -d '{ "image": "<image-base64-string>" }'
Python
import requests headers = { 'accept': 'application/json', 'apikey': '<your-api-key>', 'Content-Type': 'application/json', } json_data = { 'image': '<image-base64-string>', } response = requests.post('https://api.pixquery.com/caption', headers=headers, json=json_data) # Note: json_data will not be serialized by requests # exactly as it was in the original request. #data = '{\n "image": "<image-base64-string>",\n "q": "<question>"\n}' #response = requests.post('https://api.pixquery.com/ask', headers=headers, data=data)
Javascript
Node-Fetch
import fetch from 'node-fetch'; fetch('https://api.pixquery.com/caption', { method: 'POST', headers: { 'accept': 'application/json', 'apikey': '<your-api-key>', 'Content-Type': 'application/json' }, // body: '{\n "image": "<image-base64-string>"\n}', body: JSON.stringify({ 'image': '<image-base64-string>' }) });
Axios
const axios = require('axios'); const response = await axios.post( 'https://api.pixquery.com/caption', // '{\n "image": "<image-base64-string>"\n}', { 'image': '<image-base64-string>' }, { headers: { 'accept': 'application/json', 'apikey': '<your-api-key>', 'Content-Type': 'application/json' } } );
Go
package main import ( "fmt" "io" "log" "net/http" "strings" ) func main() { client := &http.Client{} var data = strings.NewReader(`{ "image": "<image-base64-string>" }`) req, err := http.NewRequest("POST", "http://api.pixquery.com/caption", data) if err != nil { log.Fatal(err) } req.Header.Set("accept", "application/json") req.Header.Set("apikey", "<your-api-key>") req.Header.Set("Content-Type", "application/json") resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() bodyText, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", bodyText) }
C#
using System.Net.Http; using System.Net.Http.Headers; HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://api.pixquery.com/caption"); request.Headers.Add("accept", "application/json"); request.Headers.Add("apikey", "<your-api-key>"); request.Content = new StringContent("{\n \"image\": \"<image-base64-string>\"\n}"); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync();
Java
java.net.http
import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.Scanner; class Main { public static void main(String[] args) throws IOException { URL url = new URL("https://api.pixquery.com/caption"); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.setRequestMethod("POST"); httpConn.setRequestProperty("accept", "application/json"); httpConn.setRequestProperty("apikey", "<your-api-key>"); httpConn.setRequestProperty("Content-Type", "application/json"); httpConn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream()); writer.write("{\n \"image\": \"<image-base64-string>\"\n}"); writer.flush(); writer.close(); httpConn.getOutputStream().close(); InputStream responseStream = httpConn.getResponseCode() / 100 == 2 ? httpConn.getInputStream() : httpConn.getErrorStream(); Scanner s = new Scanner(responseStream).useDelimiter("\\A"); String response = s.hasNext() ? s.next() : ""; System.out.println(response); } }
OkHttp
OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\n \"image\": \"<image-base64-string>\"\n}"); Request request = new Request.Builder() .url("https://api.pixquery.com/caption") .post(body) .addHeader("accept", "application/json") .addHeader("apikey", "<your-api-key>") .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute();
PHP
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.pixquery.com/caption'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'accept: application/json', 'apikey: <your-api-key>', 'Content-Type: application/json', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"image\": \"<image-base64-string>\"\n}"); $response = curl_exec($ch); curl_close($ch);
Ruby
require 'net/http' require 'json' uri = URI('https://api.pixquery.com/caption') req = Net::HTTP::Post.new(uri) req.content_type = 'application/json' req['accept'] = 'application/json' req['apikey'] = '<your-api-key>' # The object won't be serialized exactly like this # req.body = "{\n \"image\": \"<image-base64-string>\"\n}" req.body = { 'image' => '<image-base64-string>' }.to_json req_options = { use_ssl: uri.scheme == 'https' } res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| http.request(req) end
Swift
import Foundation let headers = [ "accept": "application/json", "apikey": "<your-api-key>", "Content-Type": "application/json" ] let parameters = ["image": "<image-base64-string>"] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.pixquery.com/caption")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume()
Visual Question Answering ❓
/ask
- The API Keys for the caption and ask endpoints are same (for now). Get your API keys from the dashboard.

Here are some code snippets in different languages on how to use the VQA API.
Replace <your-api-key>
with your API key and <image-base64-string>
with your image’s base64 string and <question>
with the question you want to ask the image.
cURL
curl -X 'POST' \ 'https://api.pixquery.com/ask' \ -H 'accept: application/json' \ -H 'apikey: <your-api-key>' \ -H 'Content-Type: application/json' \ -d '{ "image": "<image-base64-string>", "q": "<question>" }'
Python
import requests headers = { 'accept': 'application/json', 'apikey': '<your-api-key>', 'Content-Type': 'application/json', } json_data = { 'image': '<image-base64-string>', 'q': '<question>', } response = requests.post('https://api.pixquery.com/ask', headers=headers, json=json_data)
Javascript
Node-Fetch
import fetch from 'node-fetch'; fetch('https://api.pixquery.com/ask', { method: 'POST', headers: { 'accept': 'application/json', 'apikey': '<your-api-key>', 'Content-Type': 'application/json' }, // body: '{\n "image": "<image-base64-string>",\n "q": "<question>"\n}', body: JSON.stringify({ 'image': '<image-base64-string>', 'q': '<question>' }) });
Axios
const axios = require('axios'); const response = await axios.post( 'https://api.pixquery.com/ask', // '{\n "image": "<image-base64-string>",\n "q": "<question>"\n}', { 'image': '<image-base64-string>', 'q': '<question>' }, { headers: { 'accept': 'application/json', 'apikey': '<your-api-key>', 'Content-Type': 'application/json' } } );
Go
package main import ( "fmt" "io" "log" "net/http" "strings" ) func main() { client := &http.Client{} var data = strings.NewReader(`{ "image": "<image-base64-string>", "q": "<question>" }`) req, err := http.NewRequest("POST", "https://api.pixquery.com/ask", data) if err != nil { log.Fatal(err) } req.Header.Set("accept", "application/json") req.Header.Set("apikey", "<your-api-key>") req.Header.Set("Content-Type", "application/json") resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() bodyText, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", bodyText) }
C#
using System.Net.Http; using System.Net.Http.Headers; HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.pixquery.com/ask"); request.Headers.Add("accept", "application/json"); request.Headers.Add("apikey", "<your-api-key>"); request.Content = new StringContent("{\n \"image\": \"<image-base64-string>\",\n \"q\": \"<question>\"\n}"); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync();
Java
java.net.http
import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.Scanner; class Main { public static void main(String[] args) throws IOException { URL url = new URL("https://api.pixquery.com/ask"); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.setRequestMethod("POST"); httpConn.setRequestProperty("accept", "application/json"); httpConn.setRequestProperty("apikey", "<your-api-key>"); httpConn.setRequestProperty("Content-Type", "application/json"); httpConn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream()); writer.write("{\n \"image\": \"<image-base64-string>\",\n \"q\": \"<question>\"\n}"); writer.flush(); writer.close(); httpConn.getOutputStream().close(); InputStream responseStream = httpConn.getResponseCode() / 100 == 2 ? httpConn.getInputStream() : httpConn.getErrorStream(); Scanner s = new Scanner(responseStream).useDelimiter("\\A"); String response = s.hasNext() ? s.next() : ""; System.out.println(response); } }
OkHttp
OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\n \"image\": \"<image-base64-string>\",\n \"q\": \"<question>\"\n}"); Request request = new Request.Builder() .url("https://api.pixquery.com/ask") .post(body) .addHeader("accept", "application/json") .addHeader("apikey", "<your-api-key>") .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute();
PHP
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.pixquery.com/ask'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'accept: application/json', 'apikey: <your-api-key>', 'Content-Type: application/json', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"image\": \"<image-base64-string>\",\n \"q\": \"<question>\"\n}"); $response = curl_exec($ch); curl_close($ch);
Ruby
require 'net/http' require 'json' uri = URI('https://api.pixquery.com/ask') req = Net::HTTP::Post.new(uri) req.content_type = 'application/json' req['accept'] = 'application/json' req['apikey'] = '<your-api-key>' # The object won't be serialized exactly like this # req.body = "{\n \"image\": \"<image-base64-string>\",\n \"q\": \"<question>\"\n}" req.body = { 'image' => '<image-base64-string>', 'q' => '<question>' }.to_json req_options = { use_ssl: uri.scheme == 'https' } res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| http.request(req) end
Swift
import Foundation let headers = [ "accept": "application/json", "apikey": "<your-api-key>", "Content-Type": "application/json" ] let parameters = [ "image": "<image-base64-string>", "q": "<question>" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.pixquery.com/ask")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume()
Python 🐍 Example →

from PIL import Image
#read the image
im = Image.open("image.jpg")
#show image
display(im)
import base64
import requests
with open('image.jpg', 'rb') as image_file:
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
api_key = '3imw41hnSONtdWG0Swqkxg'
headers = {
'accept': 'application/json',
'apikey': api_key,
'Content-Type': 'application/json',
}
json_data = {
'image': encoded_string,
}
response = requests.post('https://api.pixquery.com/caption', headers=headers, json=json_data)
response.text