PAGINATION
Paginate search results
Search results are paged with page and page_size. Each response includes totalResults, page and pageSize, so you always know how far there is to go.
Parameters
| Parameter | Type | Default | Constraints |
|---|---|---|---|
page | integer | 1 | minimum: 1, maximum: 10000 |
page_size | integer | 10 | minimum: 1, maximum: 100 |
Pages start at 1, and page × page_size can't exceed 10,000. Results are newest-first by default, so new articles arriving while you page can shift items between pages; pass a fixed to timestamp for a more stable snapshot.
Loop through pages
Stop when a page comes back short or you reach the reachable total. Each page is one request; use up to 100 articles per request to reduce call count.
async function* allArticles(query, pageSize = 50) {
for (let page = 1; ; page++) {
const url = new URL("https://apis.newssearchapi.com/v1/articles");
url.search = new URLSearchParams({ ...query, page: String(page), page_size: String(pageSize) }).toString();
const body = await (await fetch(url, { headers: { "X-Api-Key": process.env.NEWSSEARCHAPI_API_KEY } })).json();
if (body.status !== "ok") throw new Error(`${body.code}: ${body.message}`);
yield* body.articles;
const reachable = Math.min(body.totalResults, 10_000);
if (body.articles.length < pageSize || page * pageSize >= reachable) return;
}
}
for await (const article of allArticles({ q: "climate", from: "2026-10-01" })) console.log(article.title);import os
import requests
def all_articles(query, page_size=50):
page = 1
while True:
response = requests.get(
"https://apis.newssearchapi.com/v1/articles",
params={**query, "page": page, "page_size": page_size},
headers={"X-Api-Key": os.environ["NEWSSEARCHAPI_API_KEY"]},
timeout=10,
)
body = response.json()
if body["status"] != "ok":
raise RuntimeError(f"{body['code']}: {body['message']}")
yield from body["articles"]
reachable = min(body["totalResults"], 10_000)
if len(body["articles"]) < page_size or page * page_size >= reachable:
return
page += 1
for article in all_articles({"q": "climate", "from": "2026-10-01"}):
print(article["title"])The SDKs provide this as articles.iterate().
More than 10,000 results
totalResults can be larger than 10,000, but only the first 10,000 are reachable by paging. To export more, split the query into date windows with from and to (for example one day at a time) and page through each window.
Page size and credits
The global maximum is page_size=100. One credit is $0.01. Searches cost 0.1 credit, covering the first 10 returned articles; each additional article costs 0.01 credit. Each successful search costs its 0.1-credit base even with no results. A search also costs 0.2 credit per started day beyond 30 days. When dates are omitted, the default search window is 7 days; that is separate from the 30 days of history included in pricing. Article lookups cost 0.1 credit; errors are not charged.