# LatenTX API integration Help the user get a working integration in their existing project. Start with their chosen transport and language; do not create a custom model or management resources unless reuse is needed. ## Discover the current contract Read https://api.latenth.com/llms.txt, then only the relevant linked API documentation. The service uses an OpenAI Realtime GA-style **WebSocket subset**, not full OpenAI parity. Read [protocol.md](protocol.md) before generating events. For exact fields use https://api.latenth.com/docs/realtime-events.html and https://api.latenth.com/docs/realtime.schema.json. For management use https://api.latenth.com/docs/admin.openapi.json. Browser voice is a separate SIP/WebRTC SDK, not OpenAI SDP `/v1/realtime/calls`. - HTTPS base: `https://api.latenth.com` - WebSocket: `wss://api.latenth.com/v1/realtime?model=MODEL` - Server header: `Authorization: Bearer ${LATENTX_API_KEY}` - Discover allowed public and published model IDs with `GET /v1/models`. For speech, select the corresponding entry in `GET /voice/v1/catalog` → `voice_models`; use that entry’s languages, voices and default_voice. - Same tenant Key for `/voice/v1` management. No separate admin Key. - Key + model + `session.instructions` is enough. No Agent registration required. `instructions` is the exact field name; do not invent `instruct` or a separate `mcp` session field. Functions and MCP both use `tools`. ## Complete a first integration 1. Inspect existing backend, frontend and secret configuration. Keep the permanent Key server-side in `LATENTX_API_KEY`; never put it in browser bundles, URLs, chat, logs or source control. Missing credentials do not prevent generating code and an `.env.example`. 2. For backend WS, adapt [scripts/realtime-smoke.mjs](../scripts/realtime-smoke.mjs). Requires Node 20+ and `ws`; install `ws` using the project's existing package manager. It requests one short billed text response with tools disabled, reports text response usage only, and closes with a bounded WebSocket close handshake. It does not test audio, tool execution or saved history; a successful response is not a persistence acknowledgement. Run only within the user's authorized test scope. 3. For live microphone conversations, read [网页语音模块](voice-app.md) and the linked SDK docs. Issue temporary credentials from an authenticated backend and start from a user click. Do not ship the WS smoke example as a browser microphone client. 4. Add tools, business Skills or Knowledge only when requested; read [knowledge.md](knowledge.md) for the distinction and [management.md](management.md) for resource publication. [protocol.md](protocol.md) covers the two distinct types of Skill, tool execution, MCP approval and saved references. Fetch the live management reference for create/validate/publish payloads. 5. Verify the actual response completion, audio playback if applicable, usage and cleanup. Record model, response/call ID, timings and errors without secrets. State what was tested; a successful text round does not prove microphone, tool execution or audio quality. ## Debugging decisions - 401/403: check Key, tenant/model access and backend Authorization; don't expose credentials. - 400/event error: compare exact event with documented subset; don't silently retry unsupported fields. - Model absent: discover `/v1/models`; use returned custom ID, never compose one. - No sound: distinguish generated audio, decoded PCM, media transport and browser autoplay. WebRTC requires microphone permission and media connectivity; test packet loss/jitter separately from model latency. - Ended call: stop SDK/local tracks and poll recorded status for settlement; don't assume `response.done` or UI hangup is a final bill. For voice usage, choose the connection mode before writing accounting code. Default: consume response usage. In transcription mode, consume both completed transcription items and response usage; either can occur without the other. See [protocol.md](protocol.md#metering) for negotiation and deduplication. Use current catalog sales prices and the account bill. For a chat frontend, continue with [im-app.md](im-app.md). For business configuration, use [agent-design.md](agent-design.md).