Summarize Google News Results with LangChain and Serper API

Build a news digest with LangChain: pull Google News results through Serper, summarize each story with OpenAI, and switch to other search APIs.

In previous posts, I used LangChain to generate text and document summaries. This one builds a news digest: give it a topic and a time window, and it finds the top stories, reads each article, summarizes it in two or three sentences, and writes one paragraph on the themes across all of them. It's the News Digest tool in my LangChain examples app.

Get Google News Results with Serper

Serper returns Google Search results as JSON, including a dedicated news endpoint. Sign up, create an API key, and you get 2,500 free queries without a credit card. Each digest uses one query, however many stories you ask for.

Serper dashboard showing API usage and remaining credits
Serper dashboard (source: serper.dev)

The app calls Serper's news endpoint directly with httpx. Google's time filters (qdr:d, qdr:w, qdr:m) map to the past day, week and month:

def _serper(key, query, n, news, days):
    body = {"q": query, "num": n}
    if days:
        body["tbs"] = _tbs(days)
    endpoint = "news" if news else "search"
    data = _send("serper", "POST", f"https://google.serper.dev/{endpoint}", json=body, headers={"X-API-KEY": key})
    items = data.get("news" if news else "organic", [])
    return [Result(r.get("title", ""), r.get("link", ""), r.get("snippet", ""), r.get("date") or "")
            for r in items][:n]

Summarize Each Story, Then Write a Digest

For each result, the app downloads the article and extracts the main text with trafilatura. If a site blocks the request or sits behind a paywall, it falls back to the search snippet, so one failed page doesn't break the digest. The articles are summarized in parallel with LangChain's batch, then a final call writes the digest from those summaries:

model = chat_model()
texts = [_article_text(r) for r in results]
summaries = [m.text for m in model.batch(
    [_article_prompt(r.title, t) for r, t in zip(results, texts)], config={"max_concurrency": 5})]
digest = model.invoke(
    f"Write one paragraph that summarizes the main themes across these stories about '{topic}'.\n\n"
    + "\n\n".join(f"- {r.title}: {s}" for r, s in zip(results, summaries))
).text

max_concurrency caps how many requests go to OpenAI at once, so a ten-story digest sends five requests at a time. Each article is cut to 15,000 characters before summarizing, and the prompt tells the model to ignore any instructions inside the article text, since a news page is content you don't control.

Use Other Search APIs for News

Serper is one of eight search providers the app supports, and you pick one in the sidebar. They don't all treat "news" the same way:

ProviderHow the app asks for newsTime filter
SerperGoogle News endpointPast day, week or month
SerpApiGoogle search with the news tabPast day, week or month
FirecrawlNews source in its search APIPast day, week or month
TavilyNews topicDay, week or month
ExaNews categoryPublished after a date
TinyFishNews domainsRecency in minutes
PerplexityGeneral search, no news filterDay, week or month
ParallelGeneral search, no news filterPublished after a date

Serper and SerpApi give you Google's own news ranking. Firecrawl, Tavily, Exa and TinyFish use their own indexes and ranking. Perplexity and Parallel have no news filter, so a recency window does most of the work.

Deploy the App on Railway

My LangChain Apps template on Railway deploys the app with Postgres and pgvector. Set OPENAI_API_KEY, SERPER_API_KEY (or any other provider's key) and APP_PASSWORD, so strangers can't spend your credits through the public URL.

Deploy on Railway

Build a News Digest

Open News Digest, enter a topic, pick a time window and the number of stories, and click Build digest. You get the digest paragraph first, then a card for each story with its link, date and summary.

News Digest showing a one-paragraph digest and summarized stories with links
News Digest showing a one-paragraph digest and summarized stories with links

Five stories cost six model calls: one per article and one for the digest. For a daily briefing on a narrow topic, five stories over the past day is usually enough.

Frequently Asked Questions

Is the Serper API free? New accounts get 2,500 free queries with no credit card.

Can I summarize Google News without Serper? Yes. SerpApi also returns Google News results, and Firecrawl, Tavily, Exa and TinyFish have their own news search. The app supports all of them.

Why do some stories show the search snippet instead of a full summary? The app couldn't fetch that article, usually because of a paywall or bot protection, so it summarized the snippet instead.

Subscribe to alphasec

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe