Real-time bidirectional communication for streaming AI responses, live updates, and instant notifications.
wss://ws.vigthoria.io/v1const ws = new WebSocket('wss://ws.vigthoria.io/v1');
// Authentication
ws.onopen = () => {
ws.send(JSON.stringify({
type: 'auth',
token: 'YOUR_API_KEY'
}));
};
// Handle messages
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received:', message);
};
// Handle errors
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
// Handle disconnection
ws.onclose = () => {
console.log('Disconnected');
};const ws = new WebSocket('wss://ws.vigthoria.io/v1');
ws.onopen = () => {
// Authenticate
ws.send(JSON.stringify({ type: 'auth', token: API_KEY }));
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
if (msg.type === 'auth_success') {
// Start streaming chat
ws.send(JSON.stringify({
type: 'chat.stream',
message: 'Write a poem about AI',
model: 'vigthoria-creative'
}));
}
if (msg.type === 'chat.chunk') {
// Append chunk to output
process.stdout.write(msg.content);
if (msg.done) {
console.log('\\n\\nTokens used:', msg.tokens_used);
}
}
};The server sends a ping every 30 seconds. Respond with a pong to keep the connection alive:
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
if (msg.type === 'ping') {
ws.send(JSON.stringify({ type: 'pong' }));
}
};Get AI responses as they're generated, token by token, for instant feedback.
Subscribe to generation jobs and receive real-time progress updates.
Receive instant notifications for account events, credits, and more.
Direct WebSocket connection for minimal latency compared to polling.
Common error codes: auth_failed, rate_limited, invalid_message, subscription_required