API

Events & SSE

Real-time event streaming via Server-Sent Events

SSE provides a persistent connection for real-time events. For one-off notifications, see Webhooks.

Endpoint

GET /api/events — Server-Sent Events stream

Opens a persistent SSE connection that delivers events as they occur across your account.

Authentication

SSE connections don't support custom headers, so pass your API key via the token query parameter:

GET https://api.trunx.io/api/events?token=YOUR_API_KEY

Channel Filtering

Use the optional channels query parameter (comma-separated) to subscribe to specific event channels:

GET /api/events?token=KEY&channels=sms,voice
ChannelDescription
smsSMS send, receive, delivery, and failure events
voiceCall lifecycle events (initiate, answer, complete, DTMF, AMD)
campaignCampaign call outcomes, prospect updates, stats
didDID purchases, releases, state changes
ivrIVR session events
billingUsage tracking events
webhookWebhook delivery events
reputationDID reputation changes

If channels is omitted, all channels are streamed.


Event Format

Each SSE message includes the event type, a unique id, and a JSON data payload:

event: sms.sent
id: 12345
data: {"channel":"sms","eventType":"sms.sent","payload":{"id":"msg_abc123","from":"+14155559876","to":"+14155551234","status":"sent"},"customerId":"cust_123","timestamp":"2026-01-01T00:00:00.000Z"}

Event Types by Channel

SMS

EventDescription
sms.sentMessage sent to carrier
sms.receivedInbound message received
sms.deliveredCarrier confirmed delivery
sms.failedDelivery failed

Voice

EventDescription
voice.initiatedOutbound call initiated
voice.ai.initiatedAI-powered call initiated
voice.inboundInbound call received
voice.answeredCall answered
voice.completedCall completed
voice.ai.completedAI call completed
voice.failedCall failed
voice.amdAnswering machine detection result
voice.dtmfDTMF tone received

Campaign

EventDescription
campaign.call.initiatedCampaign call started
campaign.call.voicemailReached voicemail
campaign.call.human_connectedLive person connected
campaign.call.human_hangupPerson hung up
campaign.call.no_answerNo answer
campaign.call.busyLine busy
campaign.call.failedCall failed
campaign.prospect.dncProspect on DNC list
campaign.stats.updatedCampaign stats refreshed
campaign.paused.no_didsCampaign paused (no healthy DIDs)

DID

EventDescription
did.purchasedNew DID purchased
did.releasedDID released
did.state_changedDID state transition (warming, active, cooling)

Billing

EventDescription
billing.usageUsage event recorded

Replay

Pass the Last-Event-ID header to replay missed events (up to the last 1000). The server sends all events after the given ID before switching to live streaming.

GET /api/events?token=KEY
Last-Event-ID: 12345

This is useful for recovering from disconnections without missing events.


Code Examples

const source = new EventSource(
  "https://api.trunx.io/api/events?token=tk_live_...&channels=sms,voice"
);

source.addEventListener("sms.sent", (e) => {
  const data = JSON.parse(e.data);
  console.log("SMS sent:", data.payload);
});

source.addEventListener("voice.completed", (e) => {
  const data = JSON.parse(e.data);
  console.log("Call completed:", data.payload);
});

source.onerror = (e) => {
  console.error("SSE connection error:", e);
};
import { fetchEventSource } from "@microsoft/fetch-event-source";

await fetchEventSource(
  "https://api.trunx.io/api/events?token=tk_live_...&channels=campaign",
  {
    onmessage(ev) {
      const data = JSON.parse(ev.data);
      console.log(`${ev.event}:`, data.payload);
    },
    onerror(err) {
      console.error("SSE error:", err);
    },
    // Automatically sends Last-Event-ID on reconnect
  }
);
import sseclient
import requests

url = "https://api.trunx.io/api/events?token=tk_live_...&channels=sms,voice"
response = requests.get(url, stream=True)
client = sseclient.SSEClient(response)

for event in client.events():
    print(f"{event.event}: {event.data}")

On this page