Skip to content

Realtime ​

See the Realtime voice guide for the flow, the full protocol and limits.

Create a session ​

http
POST /v1/realtime/sessions

Scope: realtime:session. Call it from your backend; give only the token to the end user's app.

Body fieldTypeDescription
agentstring (1–64)required; slug of a published realtime agent
externalUserIdstring (1–200)your end user's id
metadataobjectstored with the session

Response 201:

FieldDescription
tokensingle-use session token
urlthe WebSocket URL (wss://…/v1/realtime)
expiresAtconnect before this time (about two minutes)
sessionIdthe session's id
bash
curl "$HEVKAR_BASE_URL/v1/realtime/sessions" \
  -H "Authorization: Bearer $HEVKAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agent": "voice-concierge", "externalUserId": "user_42"}'
ts
const { token, url, expiresAt, sessionId } = await hevkar.realtime.createSession({
  agent: 'voice-concierge',
  externalUserId: 'user_42',
  metadata: { plan: 'pro' },
});
StatusCodeWhen
403MISSING_SCOPEthe key lacks realtime:session
404NOT_FOUNDno agent with this slug
403AGENT_NOT_ALLOWEDthe key is restricted to other agents
400AGENT_NOT_REALTIMEnot a realtime agent (checked before publication)
409AGENT_NOT_PUBLISHEDthe agent has no published version
403ORG_SUSPENDEDthe organization is suspended
402QUOTA_EXCEEDEDmonthly spend cap reached
400REALTIME_NOT_CONFIGUREDthe agent has no realtime settings
400MODEL_UNAVAILABLEthe realtime model is unknown, disabled or not usable
429REALTIME_SESSION_LIMITconcurrent session limit reached

The checks run in the order of this table; the first failing one answers.

WebSocket ​

text
GET wss://api.example.com/v1/realtime?token=<token>

or with Sec-WebSocket-Protocol: hevkar-realtime, token.<token> (the server answers with hevkar-realtime). Frames are JSON text with a type; audio is base64 PCM16 little-endian mono 24 kHz, and clients may send raw PCM16 binary frames. Maximum client frame: 1 MiB.

DirectionEvents
client → serverinput_audio.append, input_audio.commit, input_audio.clear, conversation.item.create, response.create, response.cancel, session.update
server → clientsession.ready, audio.delta, audio.done, transcript.delta, transcript.done, speech.started, speech.stopped, tool.call, tool.result, response.done, error, session.ended

Fields, end reasons and close codes: Protocol. Error codes: Realtime WebSocket errors.

Hevkar public API v1