Skip to main content

WebSocket Connection for Natural Language

The WebSocket API provides real-time, bidirectional communication for interactive AI conversations, enabling immediate responses to queries and live data updates.

Connection Setup

WebSocket URL Format

wss://app.infino.ws/fino/nl?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ACCESS_KEY%2FDATE%2Fus-east-1%2Fes%2Faws4_request&X-Amz-Date=TIMESTAMP&X-Amz-SignedHeaders=host&X-Amz-Signature=SIGNATURE

Required Headers

x-infino-client-id: <unique-client-identifier>
x-infino-thread-id: <thread-id>

Authentication

WebSocket connections use AWS Signature Version 4 authentication with query parameters. The signature must be generated using the same process as REST API requests.

URL Components

ParameterValueDescription
X-Amz-AlgorithmAWS4-HMAC-SHA256Fixed signing algorithm
X-Amz-CredentialACCESS_KEY/DATE/us-east-1/es/aws4_requestCredential scope
X-Amz-DateYYYYMMDDTHHMMSSZRequest timestamp
X-Amz-SignedHeadershostHeaders included in signature
X-Amz-Signature<calculated-signature>Request signature

Connection Example

Using websocat (WebSocket client):

# Generate signed WebSocket URL (implementation-specific)
WEBSOCKET_URL="wss://app.infino.ws/fino/nl?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=IAK_ExampleKey123456%2F20240120%2Fus-east-1%2Fes%2Faws4_request&X-Amz-Date=20240120T123000Z&X-Amz-SignedHeaders=host&X-Amz-Signature=abc123def456..."

# Connect with required headers
websocat "$WEBSOCKET_URL" \
--header "x-infino-client-id: client-analytics-001" \
--header "x-infino-thread-id: thread-uuid-123"

Message Protocol

Client to Server Messages

User Query Message

Send a query to the AI system for processing:

{
"content": {
"user_query": "Show me top 10 customers by revenue",
"context": "customer_analysis",
"parameters": {
"limit": 10,
"metric": "total_revenue",
"time_period": "last_quarter"
}
},
"type": "query"
}

Message Fields

FieldTypeRequiredDescription
content.user_querystringYesNatural language query
content.contextstringNoAnalysis context identifier
content.parametersobjectNoQuery parameters and filters
typestringYesMessage type (query, command, ping)

Server to Client Messages

AI Response Message

Receive AI-generated analysis and results:

{
"content": {
"type": "result",
"data": {
"query_results": [
{
"customer_id": "cust_001",
"name": "TechCorp Inc.",
"total_revenue": 125000.50,
"order_count": 45
},
{
"customer_id": "cust_002",
"name": "Global Solutions LLC",
"total_revenue": 98750.25,
"order_count": 32
}
],
"total_count": 10,
"query_metadata": {
"execution_time": "1.2s",
"index_used": "customer-revenue-index"
}
},
"summary": "Found top 10 customers by revenue for last quarter. TechCorp Inc. leads with $125K total revenue from 45 orders.",
"visualization": {
"chart_type": "horizontal_bar",
"data_points": 10,
"recommended_view": "revenue_breakdown"
}
},
"role": "assistant",
"created_at": "2024-01-20T12:45:00Z"
}

Response Fields

FieldTypeDescription
content.typestringResponse type (result, error, progress)
content.dataobjectQuery results and metadata
content.summarystringHuman-readable summary
content.visualizationobjectChart and visualization recommendations
rolestringMessage sender (assistant, system)
created_atstringMessage timestamp

Progress Message

Real-time updates during query processing:

{
"content": {
"type": "progress",
"stage": "analyzing_data",
"progress": 0.65,
"message": "Processing customer revenue calculations..."
},
"role": "system"
}

Heartbeat Message

Keep-alive messages to maintain connection:

{
"type": "heartbeat",
"message": "keep-alive",
"timestamp": "2024-01-20T12:45:30Z"
}

Message Types

Query Processing Flow

  1. Client sends query - User sends natural language query with context
  2. Server acknowledges - Server confirms receipt and begins processing
  3. Progress updates - Real-time processing status updates
  4. Result delivery - Complete analysis results and data
  5. Visualization suggestions - Chart and visualization recommendations

Error Handling

Error Message Format

{
"content": {
"type": "error",
"error_code": "QUERY_PARSE_ERROR",
"message": "Unable to parse natural language query",
"details": {
"query": "Show me undefined metrics",
"suggestion": "Try specifying a clear metric like 'revenue' or 'customer count'"
}
},
"role": "system"
}

Common Error Codes

CodeDescriptionResolution
QUERY_PARSE_ERRORQuery cannot be understoodRephrase with clearer language
INDEX_NOT_FOUNDTarget index doesn't existVerify index name and permissions
THREAD_NOT_FOUNDThread ID is invalidCheck that thread exists and is accessible
RATE_LIMIT_EXCEEDEDToo many concurrent queriesWait and retry request
AUTHENTICATION_ERRORInvalid or expired credentialsRegenerate connection signature

Connection Management

Connection States

  • Connecting - Establishing WebSocket connection
  • Connected - Ready to send/receive messages
  • Processing - Query in progress
  • Idle - Connected but no active queries
  • Reconnecting - Attempting to restore connection
  • Disconnected - Connection closed