APITube Help Center

How to Aggregate News Results with Facets

Count matching articles by source, language, topic or date

Kent Hudson

Written by Kent Hudson

August 22, 2026

Updated October 16, 2026

Open this example in the API Playground ↗

How to aggregate news results with facets

Add facet=true and facet.field to get article counts grouped by a field. For example, group a search by source and language without downloading all matching articles:

curl "https://api.apitube.io/v1/news/everything?title=tesla&facet=true&facet.field=source.id,language.id&api_key=YOUR_API_KEY"

The response includes a facets object alongside the articles. You can also send your key in the X-API-Key header.

How does the facet parameter work?

Set facet=true or facet=1, then list up to five fields in facet.field. Each group contains articles matching your search filters, including any source filter.

Counts cover the full matching set. page and per_page limit the returned articles, but do not limit the facet counts.

Each field has a list of { value, count } pairs:

{
  "status": "ok",
  "results": [...],
  "facets": {
    "source.id": [
      { "value": 12345, "count": 150 },
      { "value": 12346, "count": 120 }
    ],
    "language.id": [
      { "value": 1, "count": 450 },
      { "value": 2, "count": 120 }
    ]
  }
}

The IDs and counts above illustrate the response shape.

Which fields can I facet on?

Common choices are:

  • Source and language: source.id, source.country.id, source.bias, source.rank.opr, language.id, author.id.
  • Subject: category.id, topic.id, industry.id, entity.id.
  • Sentiment: sentiment.overall.polarity, sentiment.title.polarity, sentiment.body.polarity, sentiment.strength.
  • Article details: is_duplicate, is_free, is_important, read_time, content.length, media.images.count, media.videos.count.
  • Publication time: published.year, published.month, published.day_of_week, published.hour, published.weekday, published.time_of_day.

For example, count entities mentioned in the news and group the same results by sentiment:

curl "https://api.apitube.io/v1/news/everything?topic.id=business&facet=true&facet.field=entity.id,sentiment.overall.polarity&api_key=YOUR_API_KEY"

An article can belong to several entity or topic groups, so adding those group counts may exceed the number of matching articles.

How to control how many facet values come back

facet.limit sets the maximum values per field: 10 by default, up to 100. facet.mincount sets the minimum article count needed for a value to appear; its default is 1.

Most fields list the largest groups first. Time and computed fields use value order.

curl "https://api.apitube.io/v1/news/everything?facet=true&facet.field=source.id&facet.limit=20&facet.mincount=5&api_key=YOUR_API_KEY"

This returns up to 20 source groups, each with at least five articles.

How to facet over ranges (dates and numbers)

Set facet.range=true, choose facet.range.field and provide both facet.range.start and facet.range.end. facet.range.gap sets the width of each group; the date default is +1DAY.

Supported range fields include published_at, read_time, source.rank.opr, image and video counts, and title, body or overall sentiment scores.

curl "https://api.apitube.io/v1/news/everything?facet.range=true&facet.range.field=published_at&facet.range.start=2026-06-01&facet.range.end=2026-06-26&facet.range.gap=+1DAY&api_key=YOUR_API_KEY"

When building a URL, encode a literal + as %2B, or let your HTTP client encode the parameter. Range results use a key such as published_at_ranges; each entry contains range_start, range_end and count.

Common Questions

Which endpoints support faceting?

Use facets on /v1/news/everything, /v1/news/top-headlines, /v1/news/article, /v1/news/story, /v1/news/category, /v1/news/topic, /v1/news/industry and /v1/news/entity.

Can I get only the counts without the articles?

Facets accompany the normal results array. Use per_page=1 and select only the fields you need to reduce article data. Counts still cover all matches.

What errors can faceting return?

HTTP 400 errors include ER0310 for a missing facet.field, ER0312 for more than five fields and ER0313 for an unsupported field. Range facets return ER0332 when a start or end is missing. Check the News API parameters reference for supported fields.

Why don’t my facet counts match the number of results?

The article list contains one page. Facet counts cover every match. For fields where an article can have several values, the same article can also count in more than one group.


Related Articles