Skip to main content

Overview

WebSocket support enables real-time, bidirectional communication with AI providers. Use this for interactive applications that require low-latency streaming.
WebSocket support is currently available for relay functionality. Standard chat completions use Server-Sent Events (SSE) for streaming.

Endpoint

Upgrade from HTTP to WebSocket using standard WebSocket handshake.

Authentication

Sec-WebSocket-Protocol Header

Disable Authentication (Development Only)

config.yaml
Disabling WebSocket authentication allows unauthenticated access. Only use in development environments.

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

Reuse WebSocket connections instead of creating new ones for each request:
Buffer and send messages in batches when possible:
Enable WebSocket compression for large messages:

Troubleshooting

Connection Refused

Cause: WebSocket endpoint not available Solution:
  1. Verify server is running: http://localhost:18080
  2. Check WebSocket is enabled in config
  3. Try HTTP endpoint first: /v1/models

Authentication Failed

Cause: Invalid or missing API key Solution:
  1. Verify API key in query parameter or header
  2. Check key is configured in config.yaml
  3. Confirm websocket_auth: true if using authentication

Connection Timeout

Cause: Idle connection exceeded timeout Solution:
  1. Implement periodic ping messages
  2. Increase websocket_timeout in config
  3. Enable automatic reconnection

Next Steps

Chat Completions

Use standard SSE streaming for chat

Authentication

Configure WebSocket authentication