APITube Help Center

How to Stream News in Real Time with SSE

Receive matching articles through one open connection

Erick Horn

Written by Erick Horn

June 27, 2026

Updated October 16, 2026

How to stream news in real time with SSE

Open /v1/news/stream to receive new matching articles through Server-Sent Events (SSE). SSE keeps one HTTP connection open and sends each article as an event. Add your search filters to the URL:

curl -N -H "X-API-Key: YOUR_API_KEY" \
  "https://api.apitube.io/v1/news/stream?language.code=en"

The -N flag makes cURL print events as they arrive. Send your key through the X-API-Key header or the api_key query parameter.

How does the SSE stream work?

The stream checks for matches about every 30 seconds and sends up to 50 articles per cycle. A heartbeat comment about every 30 seconds keeps the connection open. Heartbeats are free.

Connections last up to six hours. Error ER0362 asks you to reconnect. Without a resume header, a fresh connection sends new matches without a historical backlog. For older articles, search /v1/news/everything. Your plan’s data delay still applies.

What does an SSE message look like?

Each article arrives as an article event, with its ID in id: and its JSON object in data::

event: article
id: 123456
data: {"id":123456,"title":"...","source":{"domain":"reuters.com"},...}

The article has the same fields as a news search result. Keep the latest event ID to resume later. An error event can contain a code and message, such as ER0301 with “Balance exhausted”, before the connection closes.

How do I filter what the stream sends?

Add filters for language, category, source, sentiment or entities to the URL. Use fl to choose fields:

# English sport news from one source, only the fields you need
curl -N -H "X-API-Key: YOUR_API_KEY" \
  "https://api.apitube.io/v1/news/stream?language.code=en&category.id=medtop:15000000&source.domain=reuters.com&fl=id,title,source.domain"

See how to select response fields and filter by language. Narrow filters help you receive relevant articles. The SSE reference has more client examples.

How do I reconnect without losing articles?

Send the last event ID you received in the Last-Event-Id header:

curl -N -H "X-API-Key: YOUR_API_KEY" \
  -H "Last-Event-Id: 123456" \
  "https://api.apitube.io/v1/news/stream?language.code=en"

The stream resumes after that ID, then continues with new matches. The browser’s EventSource reconnects and sends the last ID automatically.

What does streaming cost?

Each delivered article uses one streaming credit. The open connection and heartbeats are free. SSE has a separate quota from regular search requests.

When streaming quota runs out, delivery can use pay-as-you-go balance if enabled and within your spending limit. With no available funds, a new connection returns 402 ER0176. If funds run out during delivery, an error event with ER0301 closes the connection. Reconnect after adding funds or your quota renews.

Common Questions

How is SSE different from webhooks?

SSE sends articles through a connection your client keeps open. A webhook sends HTTP requests to your server’s URL. Use SSE for a continuously connected client, or a webhook for server alerts. Both charge per delivered article.

How many streams can I run at once?

Free allows 1 SSE connection, Starter and Basic allow 2 each, Professional allows 10, and Corporate allows 50. Going over the limit returns 429 ER0360. Close unused connections to free their slots.

Can I open the stream from a browser?

Yes. Use new EventSource('https://api.apitube.io/v1/news/stream?api_key=YOUR_API_KEY&language.code=en'). Listen for article events and parse event.data.

EventSource cannot set custom headers, so the key goes in the URL. Browser code exposes it to visitors; use a suitably restricted key.

Do test keys work with the stream?

Yes. Test keys return preview content without using your quota. Use one to check connection, event parsing and reconnection, then switch to a live key for normal delivery.


Related Articles