Overview
WebSocket support enables real-time, bidirectional communication with AI providers. Use this for interactive applications that require low-latency streaming.Endpoint
Authentication
Query Parameter (Recommended)
Sec-WebSocket-Protocol Header
Disable Authentication (Development Only)
config.yaml
Message Protocol
Client to Server
Send JSON messages to the server:Server to Client
Receive streaming chunks or complete responses:Examples
JavaScript/Browser
Python
Node.js
Message Types
Request Types
Response Types
Configuration
Server Configuration
config.yaml
Custom Route
Register WebSocket on a custom path:Advanced Features
Connection Management
Keep-Alive
Send periodic pings to maintain connection:Request Cancellation
Error Handling
Performance Considerations
Connection Pooling
Connection Pooling
Reuse WebSocket connections instead of creating new ones for each request:
Message Batching
Message Batching
Buffer and send messages in batches when possible:
Compression
Compression
Enable WebSocket compression for large messages:
Troubleshooting
Connection Refused
Cause: WebSocket endpoint not available Solution:- Verify server is running:
http://localhost:18080 - Check WebSocket is enabled in config
- Try HTTP endpoint first:
/v1/models
Authentication Failed
Cause: Invalid or missing API key Solution:- Verify API key in query parameter or header
- Check key is configured in
config.yaml - Confirm
websocket_auth: trueif using authentication
Connection Timeout
Cause: Idle connection exceeded timeout Solution:- Implement periodic ping messages
- Increase
websocket_timeoutin config - Enable automatic reconnection
Next Steps
Chat Completions
Use standard SSE streaming for chat
Authentication
Configure WebSocket authentication