Kura API Documentation

Integrate AI-powered voice and chat into your applications with our REST + WebSocket API.

How it works

Every integration follows a two-step pattern:

  1. Create a session via REST (POST /api/v1/sessions)
  2. Connect a WebSocket to the returned URL for real-time voice or chat
// Flow diagram
Your App ──POST /api/v1/sessions──► Kura Backend
         ◄── { session_id, websocket_url } ──┘

Your App ──WebSocket(websocket_url)──► Kura Backend
         ◄──► bidirectional audio/text ──┘

Authentication

All requests require an API key generated from the Kura dashboard (Settings → API Keys).

REST requests

Authorization: Bearer kura_live_xxxxxxxxxxxxxxxxxx

WebSocket connections

The API key is embedded in the websocket_url returned by session creation. No extra auth step needed.

Required Permissions

PermissionPurpose
sessions:createCreate new sessions
sessions:connectConnect WebSocket
assistants:readLoad assistant config

Quick Start

Create a voice session and connect in under 10 lines of code.

import requests, websocket # 1. Create session session = requests.post( "https://api.yourdomain.com/api/v1/sessions", headers={"Authorization": "Bearer kura_live_xxx"}, json={"assistant_id": 1, "mode": "voice"} ).json() # 2. Connect WebSocket ws = websocket.create_connection(session["websocket_url"]) # 3. Send audio, receive AI responses ws.send(json.dumps({"type": "audioChunk", "audio": base64_pcm_data}))

Create Session

POST /api/v1/sessions

Request Body

FieldTypeRequiredDescription
assistant_idintegerYesAssistant ID from dashboard
modestringNo"voice" (default) or "chat"
phone_numberstringNoCaller number for contact tracking
language_codestringNoBCP-47 code, default "en-US"
metadataobjectNoCustom metadata attached to session

Response (201)

{ "session_id": "550e8400-e29b-41d4-a716-446655440000", "mode": "voice", "websocket_url": "ws://host:8080/api/v1/sessions/550e.../connect?api_key=...", "expires_at": "2026-01-26T12:05:00Z", "assistant": { "id": 1, "name": "Customer Support" } }

Connect the WebSocket within 5 minutes or the session expires.

All Endpoints

MethodEndpointDescription
GET/api/v1/healthHealth check
GET/api/v1/assistantsList assistants
GET/api/v1/assistants/:idGet assistant details
POST/api/v1/sessionsCreate session
GET/api/v1/sessions/:idGet session status
DELETE/api/v1/sessions/:idEnd session

Rate Limiting

Default: 60 requests/minute per API key. Check response headers:

X-RateLimit-Limit: 60 X-RateLimit-Remaining: 45 X-RateLimit-Reset: 1706270400

WebSocket Protocol

After creating a session, connect to the websocket_url for bidirectional communication.

Audio Format

PropertyValue
EncodingLinear PCM, 16-bit signed, little-endian
Sample rate24,000 Hz
ChannelsMono (1)
TransportBase64-encoded over JSON

Message Types

Client → Server

// Send audio (voice mode) { "type": "audioChunk", "audio": "<base64_pcm16_24khz>" } // Send text (chat mode) { "type": "textMessage", "text": "Hello" } // Interrupt agent speech { "type": "interrupt" } // End session { "type": "stopSession" }

Server → Client

// Session ready { "type": "sessionOpen", "provider": "gemini", "mode": "voice" } // Agent audio (voice mode) { "type": "agentAudioChunk", "audio": "<base64>" } // Real-time transcription { "type": "transcriptionUpdate", "source": "input|output", "text": "..." } // Turn finished { "type": "turnComplete", "fullInput": "...", "fullOutput": "..." } // Session idle timeout { "type": "sessionTimeout", "reason": "idle", "timeoutSeconds": 120 } // Error { "type": "sessionError", "error": "..." }

Chat Embed Widget

Add a live AI chat assistant to any website with a single script tag.

<script src="https://app.yourdomain.com/embed/chat-widget.js" data-api-key="kura_live_xxx" data-assistant-id="1" data-backend-url="https://api.yourdomain.com" data-theme="light" data-primary-color="#6366F1" data-title="Chat Support" ></script>

Configuration

AttributeDefaultDescription
data-api-keyrequiredAPI key with chat permissions
data-assistant-idrequiredAssistant ID (must support chat)
data-backend-urlrequiredBackend URL
data-themelightlight or dark
data-positionbottom-rightbottom-right or bottom-left
data-primary-color#6366F1Primary color (hex)

Webhooks

When an AI assistant calls a webhook tool during a conversation, Kura sends a POST request to your configured URL.

Webhook Payload

{ "tool_name": "book_appointment", "tool_args": { "customer_name": "John Smith", "date": "2026-02-15" }, "assistant_id": 1, "timestamp": "2026-02-13T10:30:00.000Z" }

Python

pip install websocket-client requests pyaudio

import json, base64, threading, requests, websocket, pyaudio KURA_HOST = "https://api.yourdomain.com" API_KEY = "kura_live_xxxxxxxxxxxxxxxxxx" ASSISTANT_ID = 1 SAMPLE_RATE = 24000 # Create session session = requests.post( f"{KURA_HOST}/api/v1/sessions", headers={"Authorization": f"Bearer {API_KEY}"}, json={"assistant_id": ASSISTANT_ID, "mode": "voice"}, ).json() # Connect and handle messages ws = websocket.WebSocketApp( session["websocket_url"], on_message=lambda ws, msg: print(json.loads(msg)), ) ws.run_forever()

JavaScript / Node.js

npm install ws

import WebSocket from 'ws'; const KURA_HOST = 'https://api.yourdomain.com'; const API_KEY = 'kura_live_xxxxxxxxxxxxxxxxxx'; // Create session const res = await fetch(`${KURA_HOST}/api/v1/sessions`, { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}` }, body: JSON.stringify({ assistant_id: 1, mode: 'chat' }), }); const session = await res.json(); // Connect WebSocket const ws = new WebSocket(session.websocket_url); ws.on('message', (raw) => { const msg = JSON.parse(raw.toString()); console.log(msg.type, msg); });

More Languages

Full working examples are available for all major languages:

Go

gorilla/websocket + net/http

Rust

tokio-tungstenite + reqwest

C# / .NET

ClientWebSocket + HttpClient

Java

Java-WebSocket + Gson

Dart / Flutter

web_socket_channel + http

cURL

websocat for WebSocket testing

Contact us for complete code samples for your language.

Error Handling

ErrorCodeRecovery
Invalid API key401Check key, regenerate if expired
Insufficient permissions403Add required permissions to key
Session expired404Create a new session
Rate limit exceeded429Wait for Retry-After seconds
WebSocket disconnect-Create new session and reconnect