> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stophy.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Page through results

> Get more than one page from Stophy: send page 2, 3 and on until a page has no results, or send back the cursor from each response until none comes back.

One call returns one page, the way the site shows it. A page holds what the site puts on it, so the number of results changes from call to call. Each endpoint pages in one of three ways, and its page in the [API reference](/api-reference/introduction) says which:

| The endpoint takes | How to get the next page | Examples |
| - | - | - |
| `page` | Send the same input with `page: 2`, then `3`, until `data.results` is empty. An empty page costs nothing. | Google search, Google News, Google Maps search, Zillow, Amazon, Upwork |
| `cursor` | Send the same input with the `cursor` from the last response, until a response has no `cursor`. | YouTube, Reddit, TikTok, Instagram |
| neither | There is no next page. One call returns everything the site shows for that input. | Google Maps place, App Store search, Google Images |

Keep the rest of the input the same between pages. Each page is a normal call and costs its normal price.

## Loop through numbered pages

<CodeGroup>
  ```ts Node.js theme={null}
  const results = [];
  for (let page = 1; page <= 5; page += 1) {
    const response = await fetch("https://api.stophy.dev/v1/google/search", {
      method: "POST",
      headers: {
        authorization: `Bearer ${process.env.STOPHY_API_KEY}`,
        "content-type": "application/json",
      },
      body: JSON.stringify({ query: "rust tutorial", page }),
    });
    const { data } = await response.json();
    results.push(...data.results);
    if (data.results.length === 0) break;
  }
  ```

  ```python Python theme={null}
  import os
  import requests

  results = []
  for page in range(1, 6):
      response = requests.post(
          "https://api.stophy.dev/v1/google/search",
          headers={"Authorization": f"Bearer {os.environ['STOPHY_API_KEY']}"},
          json={"query": "rust tutorial", "page": page},
          timeout=30,
      )
      data = response.json()["data"]
      results += data["results"]
      if not data["results"]:
          break
  ```
</CodeGroup>

## Loop through cursors

<CodeGroup>
  ```ts Node.js theme={null}
  const results = [];
  let cursor: string | undefined;
  do {
    const response = await fetch("https://api.stophy.dev/v1/youtube/search", {
      method: "POST",
      headers: {
        authorization: `Bearer ${process.env.STOPHY_API_KEY}`,
        "content-type": "application/json",
      },
      body: JSON.stringify({ query: "rust tutorial", cursor }),
    });
    const { data } = await response.json();
    results.push(...data.results);
    cursor = data.cursor;
  } while (cursor && results.length < 100);
  ```

  ```python Python theme={null}
  import os
  import requests

  results = []
  cursor = None
  while True:
      body = {"query": "rust tutorial"}
      if cursor:
          body["cursor"] = cursor
      response = requests.post(
          "https://api.stophy.dev/v1/youtube/search",
          headers={"Authorization": f"Bearer {os.environ['STOPHY_API_KEY']}"},
          json=body,
          timeout=30,
      )
      data = response.json()["data"]
      results += data["results"]
      cursor = data.get("cursor")
      if not cursor or len(results) >= 100:
          break
  ```
</CodeGroup>

Set your own stop, like the 5 pages or 100 results above. Some sources have many pages.

## Keep fewer results

Only `google.images`, `youtube.charts`, `appstore.search`, `appstore.top` and `google.play.search` take `limit`. Send it to return fewer results and pay for fewer: these endpoints cost 1 credit per 10 results. On every other endpoint, sending `limit` returns a 400. To keep a model's context small, take the rows you need from `data.results`, or use `fields` through the [MCP server](/mcp-server) to keep only some keys.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.