Try this endpoint →

Service endpoints

Service URL: https://api.fourhz.ai

Method / ProtocolPathContent-Type / FramesAuth
WebSocket/v1/asr/realtimeJSON control + PCM16LE binaryAuthorization: <API Key> / ?token=…

Two variants

Diarization only

speaker_labels=true returns anonymous roles without enrollment.

Diarization + speaker identification

Keep speaker_labels=true and supply fourhz_identify_candidates. Create candidates using enrollment. An unknown result or best_candidate is not a confirmed identity.

Speaker enrollment

Authentication

Use the raw API key without Bearer. Put it in the HTTP Authorization header; keep long-lived keys on the server.

Authorization: $FOURHZ_API_KEY

When a temporary credential is required, exchange the API key for a single-use token on the server and put the returned token in the token parameter of the WebSocket URL below. Mint a fresh token for each connection.

Request parameters

FieldTypeRequiredDefaultDescription
speech_modelstringYesfourhz-focusSelect the speech recognition model for this endpoint.
speaker_labelsbooleanYestrueSet true to separate speakers and return anonymous speaker labels.

WebSocket send parameters

After receiving Begin, send an UpdateConfiguration JSON text message to update background speech rejection on the active connection.

FieldTypeRequiredDescription
typestringYesUpdateConfiguration
reject_background_speechbooleanYesBackground speech rejection. Set to true to filter low-confidence transcripts and help keep background speech out of the results. Set to false to disable this filter.
{"type":"UpdateConfiguration","reject_background_speech":true}

Response fields

Speaker naming and revisions

Handle FourHzSpeakerNaming and FourHzSpeakerRevision, updating existing Turns by turn_order. Termination.fourhz_speaker_names is authoritative; unknown is not a successful match.

FieldTypeMeaning and availability
typestringBegin, Turn, Termination, Error, and documented extension events.
idstringSession ID in Begin for troubleshooting.
expires_atintegerSession expiration Unix time in Begin, distinct from token expiry.
turn_orderintegerStable utterance ID; gaps are allowed. Replace older snapshots of the same ID.
transcriptstringComplete current utterance snapshot, not an append-only delta.
end_of_turnbooleantrue means the utterance is finalized.
turn_is_formattedbooleanWhether the text is formatted.
audio_duration_secondsnumberReceived audio duration in seconds, in Termination.
session_duration_secondsnumberSession duration in seconds, distinct from audio duration.
errorstringError-event message; results may be incomplete.
speaker_label / utterances[].speakerstringAnonymous role A/B/… or UNKNOWN, not a real-person identity.
utterances[].start / endintegerPRE/SYNC utterance start/end in milliseconds.
utterances[].textstringText of this speaker’s utterance.
fourhz_speaker_namestring?Name returned after a server match; absence is not a successful identification.
fourhz_speaker_names[]array?Final speaker matches in Termination; only matched confirms identity.
turns[]arraySpeaker revision entries; update existing Turns by turn_order.

Request examples

Code samples

curl "https://api.fourhz.ai/v1/token?expires_in_seconds=60" \
  -H "Authorization: $FOURHZ_API_KEY"

# Use the returned token in this WebSocket URL (for example with wscat):
TOKEN=$(jq -r .token token.json)
wscat -c "wss://api.fourhz.ai/v1/asr/realtime?speech_model=fourhz-focus&speaker_labels=true&token=$TOKEN"

Sending and receiving

1. Send audio

Send 16 kHz mono PCM16LE as binary audio. A 500 ms frame (16000 bytes) is recommended; do not combine many frames into one oversized message.

# audio.pcm: 16 kHz, mono PCM16LE, without a WAV header
with open("audio.pcm", "rb") as audio:
    while chunk := audio.read(16000):  # 500 ms per frame
        ws.send_binary(chunk)

2. Receive events

The server sends Begin, Turn, and Termination in order. Begin confirms the session, Turn carries transcript snapshots, and Termination means the server has finished and the connection can close.

EventWhat it meansClient action
BeginReturns the session id, model, and expiry.Record id and start sending audio.
TurnReturns the current utterance snapshot.Replace the same turn_order; do not append snapshots.
TerminationReturns final session information and received audio duration.Close the WebSocket only after receiving it.
{"type":"Begin","id":"session-id","model":"fourhz-focus"}
{"type":"Turn","turn_order":0,"end_of_turn":true,"transcript":"Hello world.","speaker_label":"A","fourhz_speaker_name":"Alice"}
{"type":"Termination","audio_duration_seconds":4.2,"fourhz_speaker_names":[{"speaker_label":"A","status":"matched","enrollment_id":"enr_a","name":"Alice"}]}

3. How Turn text updates

The same turn_order may receive partial and then final snapshots. Partial is temporary; persist the final snapshot.

FieldPartial Turn (speaking)Final Turn (settled)
transcriptSnapshot of the utterance so far (no punctuation)Punctuated, ITN-normalised final text
utteranceAlways an empty stringMirrors transcript (redundant compatibility field)
end_of_turnfalsetrue — the utterance is done; the next one has a different turn_order
turn_is_formattedfalsetrue — this transcript is the punctuated, normalised final text

4. Session limits

The termination event is documented in “Receive events”. The table below only lists session and input limits for troubleshooting timeouts, idle input, and control-message issues.

Begin pre-Begin buffer512 KiB (≈16 s at 16 kHz PCM16LE); exceeding it → 400 and close
Session durationServer-configured ceiling; a token caps the session to its value at issue time. On timeout you get Error (Session time limit reached.) and close
Audio-frame idle timeoutThe session ends normally after 60 seconds without application input, with session_idle and close code 1000. Reconnect to continue.
Terminate flush windowAfter Terminate the server waits up to 60 s for the upstream to flush; beyond that the session ends with Error (Streaming ASR temporarily unavailable.)
Control messagesUpdateConfiguration updates settings. Terminate ends the session; repeated Terminate messages have no effect, and subsequent audio is ignored.
BillingBilled per received audio second (asr_realtime); audio already received is settled even if the client disconnects mid-session

Error codes

Every HTTP error body contains error_code (machine-readable) and message (human-readable). Legacy fields such as detail, code/msg or an upstream error object are kept and status codes are unchanged. Clients should read error_code and message first.

Before the WebSocket is established, 4xx/5xx values are HTTP status codes. After connection, Error, 1000 and 1011 are WebSocket events/close codes, not HTTP responses. HTTP error bodies usually contain error_code and message.

TypeStatus/codeTrigger
HTTP400 (before upgrade)Missing or invalid query parameters (invalid_request), or a conflicting combination (invalid_config).
HTTP401Missing or invalid API key, or an expired/used single-use token.
HTTP402Insufficient balance.
HTTP404The enrollment does not exist or is not owned by the current API key.
HTTP409The Idempotency-Key is reused by another job.
HTTP422No backend can serve diarization or role naming (unsupported_capability), or the selected model does not support it.
HTTP429Rate limited; wait for the response Retry-After before retrying.
WebSocketsession_timeout / 1000The session reached its maximum lifetime and ends normally.
WebSocketsession_idle / 1000No application input for 60 seconds; the session ends normally, not as a service failure.
WebSocket503 / 1011 (in session)The upstream is temporarily unavailable: dial failure, flush timeout, or engine exit.

Idle session end: session_idle

Applies to all realtime ASR models, including Spectrum and Focus.

{
  "type": "Error",
  "error_code": "session_idle",
  "error": "Session ended after 60 seconds without application input. Reconnect to continue."
}

Send Terminate when recording ends. After an idle end, reconnect when recording resumes. Silent audio frames are input; WebSocket ping/pong does not reset application inactivity.