Building Low-Latency Realtime WebSocket & Multimodal RAG Pipelines on Zopyr
Step-by-step tutorial on combining /v1/files, /v1/embeddings, and persistent /v1/realtime WebSocket sessions for interactive multimodal assistants.
1. Uploading Documents with /v1/files and Indexing via /v1/embeddings
Zopyr provides an encrypted, organization-scoped /v1/files API that accepts PDFs, Markdown, CSVs, and source code up to 20 MB. Once uploaded, a file can be referenced directly by its file_id inside any /v1/chat/completions or /v1/responses request without re-transmitting megabytes of Base64 data on every turn.
For semantic retrieval over large repositories, call POST /v1/embeddings with configurable vector dimensions and store the resulting normalized vectors in pgvector.
// Upload once via /v1/files, reference by file_id across turns
const upload = await fetch('https://api.zopyr.com/v1/files', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.ZOPYR_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
filename: 'runbook.md',
purpose: 'user_data',
content: '# Production Incident Runbook\n1. Check Redis latency...',
}),
}).then((r) => r.json());
// Reference file_id in chat completions
const chat = await fetch('https://api.zopyr.com/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.ZOPYR_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'google/gemini-4-argon',
messages: [{
role: 'user',
content: [
{ type: 'text', text: 'Summarize step 1 of the attached runbook.' },
{ type: 'file', file: { file_id: upload.id } },
],
}],
}),
});2. Streaming Over Persistent WebSockets (/v1/realtime)
When building voice assistants or live collaborative canvases, establishing a new HTTP connection per turn adds unnecessary handshake overhead. Connect to wss://api.zopyr.com/v1/realtime to maintain a stateful session where conversation.item.create and response.create stream response.text.delta frames in real time.