DarhimLabs API
Real-time inbox updates via SSE
Subskrypcja live updates konwersacji przez Server-Sent Events.
Real-time inbox updates via SSE
Subskrypcja live updates konwersacji przez Server-Sent Events.
Kiedy tego uzyc
Uzyj tego przepisu, gdy chcesz: Odswiezac inbox bez pollingu i bez opoznien przy nowych wiadomosciach.
Endpoint referencyjny: GET /inbox/events/stream.
Implementacja
Node.js
import { DarhimLabs } from "@darhimlabs/node";
const client = new DarhimLabs(process.env.DARHIMLABS_API_KEY!);
const source = new EventSource('/api/v2/inbox/events/stream'); source.onmessage = (e) => render(JSON.parse(e.data));
Python
import os
from darhimlabs import DarhimLabs
client = DarhimLabs(api_key=os.environ["DARHIMLABS_API_KEY"])
for event in sse_client('/api/v2/inbox/events/stream'):
handle(event)
PHP
<?php
$client = new DarhimLabs\Client(["api_key" => $_ENV["DARHIMLABS_API_KEY"]]);
$stream = $client->inbox->events->stream(); foreach ($stream as $event) { handle($event); }
Ruby
client = DarhimLabs::Client.new(api_key: ENV["DARHIMLABS_API_KEY"])
client.inbox.events.stream { |event| handle(event) }
Test it
- Wykonaj request w sandboxie z kluczem
dl_test_.... - Sprawdz
X-Request-IDw odpowiedzi. - Dla webhookow uzyj Webhook Playground, zeby zobaczyc payload live.
Common pitfalls
- Dodaj reconnect z last-event-id, inaczej zgubisz eventy przy deployu.
- Loguj
request_idievent_id, zeby support mogl odtworzyc problem. - Dla mutacji dodawaj
Idempotency-Key, szczegolnie jesli request moze byc retryowany.
Production checklist
- Dodaj retry z exponential backoff i jitterem.
- Ogranicz scopes API key do minimalnego zestawu.
- Monitoruj rate limit headers i latency P95.
- Przetestuj bledy
401,409,422i429.