GET
/
v1
/
ws
/
search
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())

Headers

X-API-Key
string
required

Your API key for authentication

Body

application/json

Response

101

WebSocket connection established