Architecture & integration
One durable request.
One clear lifecycle.
Integrate from your server with a product credential. Loqui owns telephony capacity; your durable worker owns submission, polling, and business finalisation.
The path of a call
Four steps. One source of truth.
Capacity helps you plan. Admission decides. Polling keeps the lifecycle durable.
01 · Product
Store intent
Persist one body and stable key.
02 · Loqui
Admit & queue
202 or a retryable 429.
03 · Runtime
Converse
Stream turns to your Brain.
04 · Product
Finalise
Poll to a terminal state.
REST admission
A replay-safe create.
Capacity is useful context, never a lock. The create endpoint is authoritative and accepted work returns immediately.
curl
curl -i https://api.loqui.sneakpeak.fun/v1/sessions/outbound \
-H "x-loqui-api-key: $LOQUI_API_KEY" \
-H "Idempotency-Key: workflow_123_attempt_1" \
-H "Content-Type: application/json" \
--data @session.json
# HTTP/2 202 Accepted
# { "id": "…", "status": "queued", "queue": { "position": 1 } }Server-side TypeScript
The complete lifecycle.
Use REST directly when you need structured access to status, error codes, and Retry-After. The private SDK is intentionally not presented as a public package.
TypeScript
const headers = {
"x-loqui-api-key": process.env.LOQUI_API_KEY!,
"content-type": "application/json"
};
const capacity = await fetch(`${process.env.LOQUI_URL}/v1/capacity`,
{ headers }).then(r => r.json()); // advisory snapshot
const admitted = await fetch(`${process.env.LOQUI_URL}/v1/sessions/outbound`, {
method: "POST",
headers: { ...headers, "Idempotency-Key": stableKey },
body: JSON.stringify(request) // reuse this exact body on retry
});
if (admitted.status === 429) {
const retryAfter = admitted.headers.get("Retry-After");
// retry later with the same key and body
}
let session = await admitted.json(); // 202, often queued
while (!["completed", "canceled", "failed"].includes(session.status)) {
await delay(2_000);
session = await fetch(`${process.env.LOQUI_URL}/v1/sessions/${session.id}`,
{ headers }).then(r => r.json());
}
await fetch(`${process.env.LOQUI_URL}/v1/sessions/${session.id}/end`,
{ method: "POST", headers }); // idempotent cancellationIntegration discipline
Rules that matter
- Keep the product API key and Agent Brain credentials on your server.
- Retry transport ambiguity and queue-full responses with the identical body and idempotency key.
- Persist the Loqui session ID as soon as the 202 response arrives.
- Treat queue position and estimated windows as advisory.
- Recognise completed, canceled, and failed as terminal; intermediate states may pass too quickly to observe.
- Poll durably because public webhooks and session listing are not currently available.