import websockets
import asyncio
import json
async def search_streaming():
uri = "wss://api.critique-labs.ai/v1/ws/search"
headers = {
'X-API-Key': '<YOUR API KEY HERE>'
}
async with websockets.connect(uri, extra_headers=headers) as websocket:
# Send the search request
await websocket.send(json.dumps({
'prompt': 'how much are flights to this place from Hong Kong right now',
'source_blacklist': ['expedia.com'], # optional - specify either source_blacklist or source_whitelist, not both
# 'source_whitelist': ['kayak.com'], # optional - specify either source_blacklist or source_whitelist, not both
'output_format': {
'flights': [{"origin": "string", "airline": "string", "destination": "string", "price": "number"}],
"response": "string"
}
}))
# Receive and process streaming responses
while True:
try:
response = await websocket.recv()
data = json.loads(response)
# Handle different types of responses
if data['type'] == 'response':
print('Response:', data['content'])
elif data['type'] == 'context':
print('Context:', data['content'])
elif data['type'] == 'error':
print('Error:', data['content'])
break
except websockets.exceptions.ConnectionClosed:
print("Connection closed")
break
# Run the async function
asyncio.run(search_streaming())
const WebSocket = require("ws");
const ws = new WebSocket('wss://api.critique-labs.ai/v1/ws/search', {
headers: {
'X-API-Key': '<YOUR API KEY HERE>'
}
});
ws.onopen = () => {
// Send the search request
ws.send(JSON.stringify({
prompt: 'how much are flights to this place from Hong Kong right now',
source_blacklist: ['expedia.com'], # optional - specify either source_blacklist or source_whitelist, not both
// source_whitelist: ['kayak.com'], # optional - specify either source_blacklist or source_whitelist, not both
output_format: {
flights: [{"origin": "string", "airline": "string", "destination": "string", "price": "number"}],
response: "string"
}
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
// Handle different types of responses
switch(data.type) {
case 'response':
console.log('Response:', data.content);
break;
case 'context':
console.log('Context:', data.content);
break;
case 'error':
console.log('Error:', data.content);
ws.close();
break;
}
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = () => {
console.log('Connection closed');
};
curl --request GET \
--url https://api.critique-labs.ai/v1/ws/search \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <x-api-key>' \
--data '
{
"prompt": "<string>",
"image": "<string>",
"source_blacklist": [
"<string>"
],
"output_format": {}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.critique-labs.ai/v1/ws/search",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => '<string>',
'image' => '<string>',
'source_blacklist' => [
'<string>'
],
'output_format' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.critique-labs.ai/v1/ws/search"
payload := strings.NewReader("{\n \"prompt\": \"<string>\",\n \"image\": \"<string>\",\n \"source_blacklist\": [\n \"<string>\"\n ],\n \"output_format\": {}\n}")
req, _ := http.NewRequest("GET", url, payload)
req.Header.Add("X-API-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.critique-labs.ai/v1/ws/search")
.header("X-API-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"<string>\",\n \"image\": \"<string>\",\n \"source_blacklist\": [\n \"<string>\"\n ],\n \"output_format\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.critique-labs.ai/v1/ws/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"<string>\",\n \"image\": \"<string>\",\n \"source_blacklist\": [\n \"<string>\"\n ],\n \"output_format\": {}\n}"
response = http.request(request)
puts response.read_bodyStreaming Search
⚠️ Important Note: The auto-generated code samples in the playground will not work for this WebSocket endpoint, with the exception of the Python and JS(WebSocket) examples shown. Please use these provided examples only, and not the auto-generated ones.
This endpoint provides a WebSocket connection for streaming search results in real-time.
Connection
Connect to: wss://api.critique-labs.ai/v1/ws/search
Headers
- X-API-Key: (Required) Your unique API key for authentication.
Message Format
After connecting, send a JSON message with the following structure:
{
"prompt": "your search query",
"image": "optional base64 image or URL",
"source_blacklist": ["optional list of domains to exclude"],
"output_format": {
// Optional structured output format
}
}
Streaming Responses
The server will stream responses as JSON messages with the following structure:
{
"type": "response" | "context" | "error",
"content": "the actual content"
}
type: "response"- Contains generated response contenttype: "context"- Contains source context informationtype: "error"- Contains error messages if any occur
import websockets
import asyncio
import json
async def search_streaming():
uri = "wss://api.critique-labs.ai/v1/ws/search"
headers = {
'X-API-Key': '<YOUR API KEY HERE>'
}
async with websockets.connect(uri, extra_headers=headers) as websocket:
# Send the search request
await websocket.send(json.dumps({
'prompt': 'how much are flights to this place from Hong Kong right now',
'source_blacklist': ['expedia.com'], # optional - specify either source_blacklist or source_whitelist, not both
# 'source_whitelist': ['kayak.com'], # optional - specify either source_blacklist or source_whitelist, not both
'output_format': {
'flights': [{"origin": "string", "airline": "string", "destination": "string", "price": "number"}],
"response": "string"
}
}))
# Receive and process streaming responses
while True:
try:
response = await websocket.recv()
data = json.loads(response)
# Handle different types of responses
if data['type'] == 'response':
print('Response:', data['content'])
elif data['type'] == 'context':
print('Context:', data['content'])
elif data['type'] == 'error':
print('Error:', data['content'])
break
except websockets.exceptions.ConnectionClosed:
print("Connection closed")
break
# Run the async function
asyncio.run(search_streaming())
const WebSocket = require("ws");
const ws = new WebSocket('wss://api.critique-labs.ai/v1/ws/search', {
headers: {
'X-API-Key': '<YOUR API KEY HERE>'
}
});
ws.onopen = () => {
// Send the search request
ws.send(JSON.stringify({
prompt: 'how much are flights to this place from Hong Kong right now',
source_blacklist: ['expedia.com'], # optional - specify either source_blacklist or source_whitelist, not both
// source_whitelist: ['kayak.com'], # optional - specify either source_blacklist or source_whitelist, not both
output_format: {
flights: [{"origin": "string", "airline": "string", "destination": "string", "price": "number"}],
response: "string"
}
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
// Handle different types of responses
switch(data.type) {
case 'response':
console.log('Response:', data.content);
break;
case 'context':
console.log('Context:', data.content);
break;
case 'error':
console.log('Error:', data.content);
ws.close();
break;
}
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = () => {
console.log('Connection closed');
};
curl --request GET \
--url https://api.critique-labs.ai/v1/ws/search \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <x-api-key>' \
--data '
{
"prompt": "<string>",
"image": "<string>",
"source_blacklist": [
"<string>"
],
"output_format": {}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.critique-labs.ai/v1/ws/search",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => '<string>',
'image' => '<string>',
'source_blacklist' => [
'<string>'
],
'output_format' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.critique-labs.ai/v1/ws/search"
payload := strings.NewReader("{\n \"prompt\": \"<string>\",\n \"image\": \"<string>\",\n \"source_blacklist\": [\n \"<string>\"\n ],\n \"output_format\": {}\n}")
req, _ := http.NewRequest("GET", url, payload)
req.Header.Add("X-API-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.critique-labs.ai/v1/ws/search")
.header("X-API-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"<string>\",\n \"image\": \"<string>\",\n \"source_blacklist\": [\n \"<string>\"\n ],\n \"output_format\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.critique-labs.ai/v1/ws/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"<string>\",\n \"image\": \"<string>\",\n \"source_blacklist\": [\n \"<string>\"\n ],\n \"output_format\": {}\n}"
response = http.request(request)
puts response.read_bodyBody
Optional, This string can be the url of the image you want to send. Alternatively, (and the preferred method) is providing a base64 encoded string of the image. If providing a url, the link must start with https:// and ends with a common image file extension like .jpg, .jpeg, .png, .gif, etc.
Response
WebSocket connection established

