Skip to main content

NewsClient

The NewsClient provides methods for searching and retrieving news stories from X. Retrieves a list of News stories matching the specified search query.
response = client.news.search(
    query="artificial intelligence",
    max_results=10,
    max_age_hours=24,
    news_fields=["id", "title", "description", "url", "created_at"]
)
query
str
required
The search query.
max_results
int
The number of results to return.
max_age_hours
int
The maximum age of the News story to search for.
news_fields
List[str]
A comma separated list of News fields to display.
SearchResponse
object
Response containing news stories matching the search query.

get

Retrieves news story by its ID.
response = client.news.get(
    id="1234567890",
    news_fields=["id", "title", "description", "url", "author"]
)
id
str
required
The ID of the news story.
news_fields
List[str]
A comma separated list of News fields to display.
GetResponse
object
Response containing the news story details.

Build docs developers (and LLMs) love