[{"data":1,"prerenderedAt":622},["ShallowReactive",2],{"navigation":3,"\u002Fdocs\u002Frealtime\u002Fconnection-lifecycle":235,"surround-\u002Fdocs\u002Frealtime\u002Fconnection-lifecycle":619},[4],{"title":5,"path":6,"stem":7,"children":8,"page":18},"Docs","\u002Fdocs","docs",[9,33,68,95,130,161,208],{"title":10,"path":11,"stem":12,"children":13,"page":18,"type":32},"Start","\u002Fdocs\u002Fstart","docs\u002F1.start",[14,20,24,28],{"title":15,"path":16,"stem":17,"new":18,"type":19,"children":-1},"Get started with Lanson Live API","\u002Fdocs\u002Fstart\u002Fquickstart","docs\u002F1.start\u002F2.quickstart",false,"page",{"title":21,"path":22,"stem":23,"new":18,"type":19,"children":-1},"Authentication","\u002Fdocs\u002Fstart\u002Fauthentication","docs\u002F1.start\u002F3.authentication",{"title":25,"path":26,"stem":27,"new":18,"type":19,"children":-1},"Choose an API","\u002Fdocs\u002Fstart\u002Fchoose-an-api","docs\u002F1.start\u002F5.choose-an-api",{"title":29,"path":30,"stem":31,"new":18,"type":19,"children":-1},"Pricing","\u002Fdocs\u002Fstart\u002Fpricing","docs\u002F1.start\u002F6.pricing","group",{"title":34,"path":35,"stem":36,"children":37,"new":18,"type":32},"Realtime","\u002Fdocs\u002Frealtime","docs\u002F2.realtime\u002F1.index",[38,40,44,48,52,56,60,64],{"title":39,"path":35,"stem":36,"new":18,"type":19,"children":-1},"Realtime Overview",{"title":41,"path":42,"stem":43,"new":18,"type":19,"children":-1},"Realtime Quickstart","\u002Fdocs\u002Frealtime\u002Fquickstart","docs\u002F2.realtime\u002F2.quickstart",{"title":45,"path":46,"stem":47,"new":18,"type":19,"children":-1},"Connection Lifecycle","\u002Fdocs\u002Frealtime\u002Fconnection-lifecycle","docs\u002F2.realtime\u002F3.connection-lifecycle",{"title":49,"path":50,"stem":51,"new":18,"type":19,"children":-1},"Audio Input","\u002Fdocs\u002Frealtime\u002Faudio-input","docs\u002F2.realtime\u002F4.audio-input",{"title":53,"path":54,"stem":55,"new":18,"type":19,"children":-1},"Transcript Lifecycle","\u002Fdocs\u002Frealtime\u002Ftranscript-lifecycle","docs\u002F2.realtime\u002F5.transcript-lifecycle",{"title":57,"path":58,"stem":59,"new":18,"type":19,"children":-1},"Realtime Translation","\u002Fdocs\u002Frealtime\u002Frealtime-translation","docs\u002F2.realtime\u002F6.realtime-translation",{"title":61,"path":62,"stem":63,"new":18,"type":19,"children":-1},"Session Configuration","\u002Fdocs\u002Frealtime\u002Fsession-configuration","docs\u002F2.realtime\u002F7.session-configuration",{"title":65,"path":66,"stem":67,"new":18,"type":19,"children":-1},"Handling Interruptions & Silence","\u002Fdocs\u002Frealtime\u002Finterruptions-silence","docs\u002F2.realtime\u002F8.interruptions-silence",{"title":69,"path":70,"stem":71,"children":72,"new":18,"type":32},"Recorded","\u002Fdocs\u002Frecorded","docs\u002F3.recorded\u002F1.index",[73,75,79,83,87,91],{"title":74,"path":70,"stem":71,"new":18,"type":19,"children":-1},"Recorded Overview",{"title":76,"path":77,"stem":78,"new":18,"type":19,"children":-1},"Transcribe Audio","\u002Fdocs\u002Frecorded\u002Ftranscribe-audio","docs\u002F3.recorded\u002F2.transcribe-audio",{"title":80,"path":81,"stem":82,"new":18,"type":19,"children":-1},"Timestamps & Speakers","\u002Fdocs\u002Frecorded\u002Ftimestamps-speakers","docs\u002F3.recorded\u002F3.timestamps-speakers",{"title":84,"path":85,"stem":86,"new":18,"type":19,"children":-1},"Subtitles","\u002Fdocs\u002Frecorded\u002Fsubtitles","docs\u002F3.recorded\u002F4.subtitles",{"title":88,"path":89,"stem":90,"new":18,"type":19,"children":-1},"Recorded Translation","\u002Fdocs\u002Frecorded\u002Ftranslation","docs\u002F3.recorded\u002F5.translation",{"title":92,"path":93,"stem":94,"new":18,"type":19,"children":-1},"Structured Results","\u002Fdocs\u002Frecorded\u002Fstructured-results","docs\u002F3.recorded\u002F6.structured-results",{"title":96,"path":97,"stem":98,"children":99,"new":18,"type":32},"Concepts","\u002Fdocs\u002Fconcepts","docs\u002F4.concepts\u002F1.index",[100,102,106,110,114,118,122,126],{"title":101,"path":97,"stem":98,"new":18,"type":19,"children":-1},"Voice Context Layer",{"title":103,"path":104,"stem":105,"new":18,"type":19,"children":-1},"Stable vs. Partial Text","\u002Fdocs\u002Fconcepts\u002Fstable-vs-partial-text","docs\u002F4.concepts\u002F2.stable-vs-partial-text",{"title":107,"path":108,"stem":109,"new":18,"type":19,"children":-1},"StableStream™","\u002Fdocs\u002Fconcepts\u002Fstablestream","docs\u002F4.concepts\u002F3.stablestream",{"title":111,"path":112,"stem":113,"new":18,"type":19,"children":-1},"Context-Aware Processing","\u002Fdocs\u002Fconcepts\u002Fcontext-aware-processing","docs\u002F4.concepts\u002F4.context-aware-processing",{"title":115,"path":116,"stem":117,"new":18,"type":19,"children":-1},"Understanding Latency","\u002Fdocs\u002Fconcepts\u002Flatency","docs\u002F4.concepts\u002F5.latency",{"title":119,"path":120,"stem":121,"new":18,"type":19,"children":-1},"Live Translation","\u002Fdocs\u002Fconcepts\u002Flive-translation","docs\u002F4.concepts\u002F6.live-translation",{"title":123,"path":124,"stem":125,"new":18,"type":19,"children":-1},"Trinity Engine","\u002Fdocs\u002Fconcepts\u002Ftrinity-engine","docs\u002F4.concepts\u002F7.trinity-engine",{"title":127,"path":128,"stem":129,"new":18,"type":19,"children":-1},"LiveFinal™","\u002Fdocs\u002Fconcepts\u002Flivefinal","docs\u002F4.concepts\u002F8.livefinal",{"title":131,"path":132,"stem":133,"children":134,"new":18,"type":32},"Guides","\u002Fdocs\u002Fguides","docs\u002F5.guides\u002F1.index",[135,137,141,145,149,153,157],{"title":136,"path":132,"stem":133,"new":18,"type":19,"children":-1},"Browser Live Captions",{"title":138,"path":139,"stem":140,"new":18,"type":19,"children":-1},"Server-side Streaming","\u002Fdocs\u002Fguides\u002Fserver-side-streaming","docs\u002F5.guides\u002F2.server-side-streaming",{"title":142,"path":143,"stem":144,"new":18,"type":19,"children":-1},"Build a Stable Caption UI","\u002Fdocs\u002Fguides\u002Fstable-caption-ui","docs\u002F5.guides\u002F3.stable-caption-ui",{"title":146,"path":147,"stem":148,"new":18,"type":19,"children":-1},"Build Live Translation","\u002Fdocs\u002Fguides\u002Flive-translation","docs\u002F5.guides\u002F4.live-translation",{"title":150,"path":151,"stem":152,"new":18,"type":19,"children":-1},"Save a Transcript","\u002Fdocs\u002Fguides\u002Fsave-transcript","docs\u002F5.guides\u002F5.save-transcript",{"title":154,"path":155,"stem":156,"new":18,"type":19,"children":-1},"Reconnect a Live Session","\u002Fdocs\u002Fguides\u002Freconnection","docs\u002F5.guides\u002F6.reconnection",{"title":158,"path":159,"stem":160,"new":18,"type":19,"children":-1},"Client-VAD speech segments","\u002Fdocs\u002Fguides\u002Fclient-vad-segments","docs\u002F5.guides\u002F7.client-vad-segments",{"title":162,"path":163,"stem":164,"children":165,"new":18,"type":32},"API Reference","\u002Fdocs\u002Fapi-reference","docs\u002F6.api-reference\u002F1.index",[166,168,172,176,180,184,188,192,196,200,204],{"title":167,"path":163,"stem":164,"new":18,"type":19,"children":-1},"API Reference Overview",{"title":169,"path":170,"stem":171,"new":18,"type":19,"children":-1},"Realtime API","\u002Fdocs\u002Fapi-reference\u002Frealtime-api","docs\u002F6.api-reference\u002F2.realtime-api",{"title":173,"path":174,"stem":175,"new":18,"type":19,"children":-1},"Client Messages","\u002Fdocs\u002Fapi-reference\u002Fclient-messages","docs\u002F6.api-reference\u002F3.client-messages",{"title":177,"path":178,"stem":179,"new":18,"type":19,"children":-1},"Server Events","\u002Fdocs\u002Fapi-reference\u002Fserver-events","docs\u002F6.api-reference\u002F4.server-events",{"title":181,"path":182,"stem":183,"new":18,"type":19,"children":-1},"Segment Transcription API","\u002Fdocs\u002Fapi-reference\u002Fsegment-transcription","docs\u002F6.api-reference\u002F5.segment-transcription",{"title":185,"path":186,"stem":187,"new":18,"type":19,"children":-1},"Batch Transcription Jobs","\u002Fdocs\u002Fapi-reference\u002Fbatch-jobs","docs\u002F6.api-reference\u002F6.batch-jobs",{"title":189,"path":190,"stem":191,"new":18,"type":19,"children":-1},"Languages & Models","\u002Fdocs\u002Fapi-reference\u002Flanguages","docs\u002F6.api-reference\u002F7.languages",{"title":193,"path":194,"stem":195,"new":18,"type":19,"children":-1},"Errors","\u002Fdocs\u002Fapi-reference\u002Ferrors","docs\u002F6.api-reference\u002F8.errors",{"title":197,"path":198,"stem":199,"new":18,"type":19,"children":-1},"Rate Limits","\u002Fdocs\u002Fapi-reference\u002Frate-limits","docs\u002F6.api-reference\u002F9.rate-limits",{"title":201,"path":202,"stem":203,"new":18,"type":19,"children":-1},"Admin API","\u002Fdocs\u002Fapi-reference\u002Fadmin","docs\u002F6.api-reference\u002F10.admin",{"title":205,"path":206,"stem":207,"new":18,"type":19,"children":-1},"Language Detection","\u002Fdocs\u002Fapi-reference\u002Flanguage-detection","docs\u002F6.api-reference\u002F11.language-detection",{"title":209,"path":210,"stem":211,"children":212,"new":18,"type":32},"Production","\u002Fdocs\u002Fproduction","docs\u002F7.production\u002F1.index",[213,215,219,223,227,231],{"title":214,"path":210,"stem":211,"new":18,"type":19,"children":-1},"Production Checklist",{"title":216,"path":217,"stem":218,"new":18,"type":19,"children":-1},"Reconnection & Retries","\u002Fdocs\u002Fproduction\u002Freconnection-retries","docs\u002F7.production\u002F2.reconnection-retries",{"title":220,"path":221,"stem":222,"new":18,"type":19,"children":-1},"Latency Best Practices","\u002Fdocs\u002Fproduction\u002Flatency-best-practices","docs\u002F7.production\u002F3.latency-best-practices",{"title":224,"path":225,"stem":226,"new":18,"type":19,"children":-1},"Security & Privacy","\u002Fdocs\u002Fproduction\u002Fsecurity-privacy","docs\u002F7.production\u002F4.security-privacy",{"title":228,"path":229,"stem":230,"new":18,"type":19,"children":-1},"Data Retention","\u002Fdocs\u002Fproduction\u002Fdata-retention","docs\u002F7.production\u002F5.data-retention",{"title":232,"path":233,"stem":234,"new":18,"type":19,"children":-1},"Changelog","\u002Fdocs\u002Fproduction\u002Fchangelog","docs\u002F7.production\u002F6.changelog",{"id":236,"title":45,"body":237,"description":610,"extension":611,"links":612,"meta":613,"navigation":615,"new":18,"path":46,"rawbody":616,"seo":617,"stem":47,"technology":612,"__hash__":618},"content\u002Fdocs\u002F2.realtime\u002F3.connection-lifecycle.md",{"type":238,"value":239,"toc":593},"minimark",[240,244,249,256,260,263,282,285,300,304,307,317,321,328,334,345,349,352,367,371,392,395,399,404,413,417,526,530,533,541,545,566,572,576],[241,242,243],"p",{},"The full lifecycle of a realtime WebSocket connection.",[245,246,248],"h2",{"id":247},"stages","Stages",[241,250,251],{},[252,253],"img",{"alt":254,"src":255},"Realtime WebSocket Connection Lifecycle","\u002Fimages\u002Fdocs\u002Fconnection-lifecycle-flow.png",[245,257,259],{"id":258},"_1-connect","1. Connect",[241,261,262],{},"WebSocket handshake:",[264,265,266,275],"ul",{},[267,268,269,270,274],"li",{},"Server-side: ",[271,272,273],"code",{},"Authorization: Bearer sk-..."," header",[267,276,277,278,281],{},"Browser: ",[271,279,280],{},"?access_token=rt_..."," query parameter",[241,283,284],{},"Conditions checked on connect:",[264,286,287,290,297],{},[267,288,289],{},"WebSocket upgrade required (else 426)",[267,291,292,293,296],{},"Gateway enabled (else 503 ",[271,294,295],{},"gateway_disabled",")",[267,298,299],{},"Connection quota passes (concurrent + rate)",[245,301,303],{"id":302},"_2-sessioncreated","2. session.created",[241,305,306],{},"Received immediately on connect:",[308,309,315],"pre",{"className":310,"code":312,"language":313,"meta":314},[311],"language-json","{\n  \"type\": \"session.created\",\n  \"session_id\": \"sess_...\",\n  \"limits\": {\n    \"max_concurrent_utterances\": 2,\n    \"max_session_seconds\": 900,\n    \"idle_timeout_seconds\": 60,\n    \"remaining_audio_seconds\": 3600\n  }\n}\n","json","",[271,316,312],{"__ignoreMap":314},[245,318,320],{"id":319},"_3-configure-optional","3. Configure (optional)",[241,322,323,324,327],{},"Send ",[271,325,326],{},"session.update"," to set parameters:",[308,329,332],{"className":330,"code":331,"language":313,"meta":314},[311],"{ \"type\": \"session.update\", \"language\": \"zh\" }\n",[271,333,331],{"__ignoreMap":314},[241,335,336,337,340,341,344],{},"The gateway applies the configuration and confirms it with ",[271,338,339],{},"session.updated",". Configure optional refinement and translation before audio; see ",[342,343,61],"a",{"href":62},".",[245,346,348],{"id":347},"_4-stream-audio","4. Stream audio",[241,350,351],{},"Continuously send PCM16LE audio frames:",[264,353,354,361,364],{},[267,355,356,357,360],{},"Text frames: ",[271,358,359],{},"input_audio_buffer.append"," (base64 JSON) — the supported transport today",[267,362,363],{},"Binary frames: not transcribed by the public gateway today; use base64",[267,365,366],{},"Speech boundaries: detected by server-side VAD as you continue sending audio, including natural pauses",[245,368,370],{"id":369},"_5-receive-events","5. Receive events",[372,373,374,380,386],"ol",{},[267,375,376,379],{},[271,377,378],{},"input_audio_buffer.speech_started"," — Voice Activity Detector detects speech onset.",[267,381,382,385],{},[271,383,384],{},"input_audio_buffer.speech_stopped"," — VAD detects silence or segment boundary.",[267,387,388,391],{},[271,389,390],{},"conversation.item.input_audio_transcription.completed"," — Final stable transcription payload emitted.",[241,393,394],{},"This cycle repeats for each speech segment.",[245,396,398],{"id":397},"_6-close-reconnect","6. Close \u002F Reconnect",[400,401,403],"h3",{"id":402},"normal-close","Normal close",[241,405,406,407,410,411,344],{},"Client calls ",[271,408,409],{},"ws.close()"," after receiving expected utterance results. Closing finalizes usage accounting, but is not a guarantee of pending transcript delivery or a session-wide final event. See ",[342,412,127],{"href":128},[400,414,416],{"id":415},"timeout-close","Timeout close",[418,419,420,437],"table",{},[421,422,423],"thead",{},[424,425,426,430,434],"tr",{},[427,428,429],"th",{},"Close code",[427,431,433],{"align":432},"right","Cause \u002F close reason",[427,435,436],{},"Trigger",[438,439,440,457,473,487,499,512],"tbody",{},[424,441,442,446,451],{},[443,444,445],"td",{},"4408",[443,447,448],{"align":432},[271,449,450],{},"idle_timeout",[443,452,453,454],{},"No audio received within ",[271,455,456],{},"idle_timeout_seconds",[424,458,459,462,467],{},[443,460,461],{},"1008",[443,463,464],{"align":432},[271,465,466],{},"session_duration_limit",[443,468,469,470],{},"Exceeded ",[271,471,472],{},"max_session_seconds",[424,474,475,477,482],{},[443,476,461],{},[443,478,479],{"align":432},[271,480,481],{},"session_audio_limit",[443,483,469,484],{},[271,485,486],{},"max_audio_seconds_per_session",[424,488,489,491,496],{},[443,490,461],{},[443,492,493],{"align":432},[271,494,495],{},"audio_quota_exhausted",[443,497,498],{},"Billing-window audio budget exhausted",[424,500,501,504,509],{},[443,502,503],{},"1009",[443,505,506],{"align":432},[271,507,508],{},"frame_too_large",[443,510,511],{},"Single frame exceeds 1 MiB",[424,513,514,517,523],{},[443,515,516],{},"1011",[443,518,519,522],{"align":432},[271,520,521],{},"client_error"," \u002F internal error",[443,524,525],{},"Client socket error or unexpected gateway failure",[245,527,529],{"id":528},"idle-timeout","Idle timeout",[241,531,532],{},"To avoid idle timeout, either:",[264,534,535,538],{},[267,536,537],{},"Send silent frames to keep the connection alive",[267,539,540],{},"Or close explicitly and reconnect when needed",[245,542,544],{"id":543},"recommended-reconnect-design","Recommended reconnect design",[372,546,547,554,557,560],{},[267,548,549,550,553],{},"Listen for ",[271,551,552],{},"close"," events, decide reconnect based on close code",[267,555,556],{},"4408 (idle) and 1008 (duration limit): reconnect directly",[267,558,559],{},"1000 (normal): do not reconnect",[267,561,562,563,565],{},"After reconnect, re-send ",[271,564,326],{}," to restore configuration",[241,567,568,569,571],{},"See ",[342,570,154],{"href":155}," for a detailed guide.",[245,573,575],{"id":574},"related","Related",[264,577,578,583,588],{},[267,579,580,582],{},[342,581,169],{"href":170}," — endpoint reference",[267,584,585,587],{},[342,586,216],{"href":217}," — retry strategies",[267,589,590,592],{},[342,591,197],{"href":198}," — plan timeout parameters",{"title":314,"searchDepth":594,"depth":594,"links":595},2,[596,597,598,599,600,601,602,607,608,609],{"id":247,"depth":594,"text":248},{"id":258,"depth":594,"text":259},{"id":302,"depth":594,"text":303},{"id":319,"depth":594,"text":320},{"id":347,"depth":594,"text":348},{"id":369,"depth":594,"text":370},{"id":397,"depth":594,"text":398,"children":603},[604,606],{"id":402,"depth":605,"text":403},3,{"id":415,"depth":605,"text":416},{"id":528,"depth":594,"text":529},{"id":543,"depth":594,"text":544},{"id":574,"depth":594,"text":575},"Connect → configure → stream audio → receive events → close\u002Freconnect.","md",null,{"updated":614},"2026-11-08",true,"---\ntitle: Connection Lifecycle\ndescription: Connect → configure → stream audio → receive events → close\u002Freconnect.\nupdated: 2026-11-08\n---\nThe full lifecycle of a realtime WebSocket connection.\n\n## Stages\n\n![Realtime WebSocket Connection Lifecycle](\u002Fimages\u002Fdocs\u002Fconnection-lifecycle-flow.png)\n\n## 1. Connect\n\nWebSocket handshake:\n\n- Server-side: `Authorization: Bearer sk-...` header\n- Browser: `?access_token=rt_...` query parameter\n\nConditions checked on connect:\n- WebSocket upgrade required (else 426)\n- Gateway enabled (else 503 `gateway_disabled`)\n- Connection quota passes (concurrent + rate)\n\n## 2. session.created\n\nReceived immediately on connect:\n\n```json\n{\n  \"type\": \"session.created\",\n  \"session_id\": \"sess_...\",\n  \"limits\": {\n    \"max_concurrent_utterances\": 2,\n    \"max_session_seconds\": 900,\n    \"idle_timeout_seconds\": 60,\n    \"remaining_audio_seconds\": 3600\n  }\n}\n```\n\n## 3. Configure (optional)\n\nSend `session.update` to set parameters:\n\n```json\n{ \"type\": \"session.update\", \"language\": \"zh\" }\n```\n\nThe gateway applies the configuration and confirms it with `session.updated`. Configure optional refinement and translation before audio; see [Session Configuration](\u002Fdocs\u002Frealtime\u002Fsession-configuration).\n\n## 4. Stream audio\n\nContinuously send PCM16LE audio frames:\n\n- Text frames: `input_audio_buffer.append` (base64 JSON) — the supported transport today\n- Binary frames: not transcribed by the public gateway today; use base64\n- Speech boundaries: detected by server-side VAD as you continue sending audio, including natural pauses\n\n## 5. Receive events\n\n1. `input_audio_buffer.speech_started` — Voice Activity Detector detects speech onset.\n2. `input_audio_buffer.speech_stopped` — VAD detects silence or segment boundary.\n3. `conversation.item.input_audio_transcription.completed` — Final stable transcription payload emitted.\n\nThis cycle repeats for each speech segment.\n\n## 6. Close \u002F Reconnect\n\n### Normal close\n\nClient calls `ws.close()` after receiving expected utterance results. Closing finalizes usage accounting, but is not a guarantee of pending transcript delivery or a session-wide final event. See [LiveFinal™](\u002Fdocs\u002Fconcepts\u002Flivefinal).\n\n### Timeout close\n\n| Close code | Cause \u002F close reason | Trigger |\n|---|---:|---|\n| 4408 | `idle_timeout` | No audio received within `idle_timeout_seconds` |\n| 1008 | `session_duration_limit` | Exceeded `max_session_seconds` |\n| 1008 | `session_audio_limit` | Exceeded `max_audio_seconds_per_session` |\n| 1008 | `audio_quota_exhausted` | Billing-window audio budget exhausted |\n| 1009 | `frame_too_large` | Single frame exceeds 1 MiB |\n| 1011 | `client_error` \u002F internal error | Client socket error or unexpected gateway failure |\n\n## Idle timeout\n\nTo avoid idle timeout, either:\n- Send silent frames to keep the connection alive\n- Or close explicitly and reconnect when needed\n\n## Recommended reconnect design\n\n1. Listen for `close` events, decide reconnect based on close code\n2. 4408 (idle) and 1008 (duration limit): reconnect directly\n3. 1000 (normal): do not reconnect\n4. After reconnect, re-send `session.update` to restore configuration\n\nSee [Reconnect a Live Session](\u002Fdocs\u002Fguides\u002Freconnection) for a detailed guide.\n\n## Related\n\n- [Realtime API](\u002Fdocs\u002Fapi-reference\u002Frealtime-api) — endpoint reference\n- [Reconnection & Retries](\u002Fdocs\u002Fproduction\u002Freconnection-retries) — retry strategies\n- [Rate Limits](\u002Fdocs\u002Fapi-reference\u002Frate-limits) — plan timeout parameters\n",{"title":45,"description":610},"gd7Yzify5evJqLfLhX2eeDvHY_Ir_s7Rj5CZs7gr6Dc",[620,621],{"title":41,"path":42,"stem":43,"children":-1},{"title":49,"path":50,"stem":51,"children":-1},1795064384569]