This project is a command-line news summarizer that:
- fetches top headlines from NewsAPI by category
- summarizes each article with OpenAI
- analyzes the summary sentiment with Anthropic
- falls back to Anthropic for summarization if the OpenAI request fails
- tracks token usage, request count, and estimated API cost
- supports both sequential and asynchronous article processing
The application starts in the terminal, asks the user for:
- a news category
- how many articles to process
- whether to use async processing
It then fetches articles from NewsAPI, processes them through the LLM pipeline, and prints a final report with:
- article title
- source
- publication date
- article URL
- generated summary
- sentiment analysis
- total request and cost summary
Core files:
Requirements:
- Python 3.10+
- a NewsAPI key
- an OpenAI API key
- an Anthropic API key
Install dependencies:
pip install -r requirements.txtCreate your environment file from the template included in the repo:
cp .env.example .envThen add real values to .env:
OPENAI_API_KEY=your-openai-key-here
ANTHROPIC_API_KEY=your-anthropic-key-here
NEWS_API_KEY=your-newsapi-key-here
ENVIRONMENT=development
MAX_RETRIES=3
REQUEST_TIMEOUT=30
DAILY_BUDGET=5.00Notes:
config.pyvalidates the required keys on import.- without valid API keys, the app will stop before running
- the repo also contains a local
.condaenvironment, but it is not required if you install fromrequirements.txt
Run the CLI application:
python main.pyYou will be prompted for:
- category:
business,entertainment,general,health,science,sports, ortechnology - number of articles:
1to10 - async mode:
yorn
You can also run the test suite. In this repo, tests were verified with the bundled Conda environment:
./.conda/bin/python test_summarizer.pyExample interactive flow:
================================================================================
NEWS SUMMARIZER - Multi-Provider Edition
================================================================================
Enter news category (technology/business/health/general): technology
How many articles to process? (1-10): 2
Use async processing? (y/n): n
Fetching 2 articles from category: technology
✓ Fetched 2 articles from News API
Processing 2 articles...
Processing: Example article title...
→ Summarizing with OpenAI...
✓ Summary generated
→ Analyzing sentiment with Anthropic...
✓ Sentiment analyzed
================================================================================
NEWS SUMMARY REPORT
================================================================================
1. Example article title
Source: Example Source | Published: 2026-05-01T08:00:00Z
URL: https://example.com/article
SUMMARY:
Short article summary generated by the model.
SENTIMENT:
Neutral tone with moderate confidence.
================================================================================
COST SUMMARY
================================================================================
Total requests: 4
Total cost: $0.00xx
Total tokens: ...
Average cost per request: $...
================================================================================
The exact article text, token counts, and total cost will vary on each run because they depend on live news results and model responses.
The project already includes cost tracking in llm_providers.py.
Current behavior:
- 1 OpenAI request is used to summarize each article
- 1 Anthropic request is used to analyze sentiment for each article
- if the OpenAI summary request fails, Anthropic is used as the fallback summarizer
- after each request, the app updates total tokens, total requests, and estimated total cost
Practical implication:
- normal case: about 2 LLM requests per article
- fallback case: up to 3 LLM requests for an article if OpenAI fails and Anthropic handles both steps
DAILY_BUDGETin.envstops processing if the tracked total exceeds the configured budget
The tracked pricing table in the code currently includes:
gpt-4o-minigpt-4o- Anthropic Sonnet pricing through the default pricing fallback path
Because costs are computed from token counts and live model usage, the most accurate cost analysis for this project is the runtime report printed under COST SUMMARY.
The repository includes unit tests for:
- cost tracking
- token counting
- NewsAPI response handling
- OpenAI request integration through mocking
- summarizer initialization
- single-article summarization flow
Verified command:
./.conda/bin/python test_summarizer.pyVerified result:
8 passed, 1 warning in 0.52s
Test run screenshot from the repo:
