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

# Google Search

> Search Google and retrieve structured web results with metadata.

# Google Search

**Base URL:** `https://drain.lat/api/v1/googlesearch`

<Note>
  Powered by Google Custom Search API. Results are cached for 10 minutes per unique query to reduce API quota usage.
</Note>

<AccordionGroup>
  <Accordion title="GET /search" icon="magnifying-glass">
    Search Google and retrieve structured web results with metadata.

    ```
    GET /api/v1/googlesearch/search
    ```

    <ParamField query="q" type="string" required>
      Search query/keywords.
    </ParamField>

    <ParamField query="num" type="number">
      Number of results to return. Max `10`. Default `10`.
    </ParamField>

    <ParamField query="start" type="number">
      Starting index for pagination. Default `1`.
    </ParamField>

    <ParamField query="safe" type="string">
      Safe search level. Options: `off`, `medium`, `high`.
    </ParamField>

    <ParamField query="lr" type="string">
      Language restrict (e.g. `lang_en` for English, `lang_es` for Spanish).
    </ParamField>

    <ParamField query="dateRestrict" type="string">
      Date restrict filter (e.g. `d7` for last 7 days, `m1` for last month, `y1` for last year).
    </ParamField>

    <ParamField query="siteSearch" type="string">
      Restrict results to a specific site (e.g. `github.com`).
    </ParamField>

    <ParamField query="fileType" type="string">
      File type filter (e.g. `pdf`, `doc`, `ppt`, `xls`).
    </ParamField>

    <CodeGroup>
      ```bash cURL theme={null}
      curl "https://drain.lat/api/v1/googlesearch/search?q=nodejs&num=5" \
        -H "x-api-key: YOUR_API_KEY"
      ```

      ```bash cURL (with filters) theme={null}
      curl "https://drain.lat/api/v1/googlesearch/search?q=machine+learning&num=10&lr=lang_en&dateRestrict=m1" \
        -H "x-api-key: YOUR_API_KEY"
      ```

      ```javascript JavaScript theme={null}
      const res = await fetch(
        "https://drain.lat/api/v1/googlesearch/search?q=nodejs&num=5",
        { headers: { "x-api-key": "YOUR_API_KEY" } }
      );
      const data = await res.json();
      ```

      ```javascript JavaScript (with filters) theme={null}
      const params = new URLSearchParams({
        q: "react tutorial",
        num: 10,
        siteSearch: "github.com",
        dateRestrict: "m6"
      });

      const res = await fetch(
        `https://drain.lat/api/v1/googlesearch/search?${params}`,
        { headers: { "x-api-key": "YOUR_API_KEY" } }
      );
      const data = await res.json();
      ```

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

      res = requests.get(
          "https://drain.lat/api/v1/googlesearch/search",
          params={"q": "nodejs", "num": 5},
          headers={"x-api-key": "YOUR_API_KEY"}
      )
      print(res.json())
      ```

      ```python Python (with filters) theme={null}
      import requests

      params = {
          "q": "python tutorial",
          "num": 10,
          "lr": "lang_en",
          "dateRestrict": "y1",
          "fileType": "pdf"
      }

      res = requests.get(
          "https://drain.lat/api/v1/googlesearch/search",
          params=params,
          headers={"x-api-key": "YOUR_API_KEY"}
      )
      print(res.json())
      ```
    </CodeGroup>

    <ResponseField name="query" type="string">The search query used.</ResponseField>
    <ResponseField name="totalResults" type="number">Estimated total results available.</ResponseField>
    <ResponseField name="searchTime" type="number">Search execution time in seconds.</ResponseField>

    <ResponseField name="results" type="array">
      <Expandable title="result object">
        <ResponseField name="title" type="string">Page title.</ResponseField>
        <ResponseField name="link" type="string">URL to the page.</ResponseField>
        <ResponseField name="snippet" type="string">Text snippet/description from the page.</ResponseField>
        <ResponseField name="displayLink" type="string">Domain name displayed.</ResponseField>
        <ResponseField name="formattedUrl" type="string">Formatted URL for display.</ResponseField>
        <ResponseField name="image" type="string">Image URL if result has an associated image. `null` otherwise.</ResponseField>
        <ResponseField name="thumbnail" type="string">Thumbnail URL if available. `null` otherwise.</ResponseField>
      </Expandable>
    </ResponseField>

    ```json Response theme={null}
    {
      "query": "nodejs",
      "totalResults": 1250000000,
      "searchTime": 0.42,
      "results": [
        {
          "title": "Node.js — Run JavaScript Everywhere",
          "link": "https://nodejs.org/",
          "snippet": "Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.",
          "displayLink": "nodejs.org",
          "formattedUrl": "https://nodejs.org/",
          "image": null,
          "thumbnail": null
        },
        {
          "title": "Node.js - Wikipedia",
          "link": "https://en.wikipedia.org/wiki/Node.js",
          "snippet": "Node.js is a cross-platform, open-source JavaScript runtime environment that can run on Windows, Linux, Unix, macOS, and more.",
          "displayLink": "en.wikipedia.org",
          "formattedUrl": "https://en.wikipedia.org/wiki/Node.js",
          "image": "https://upload.wikimedia.org/wikipedia/commons/...",
          "thumbnail": "https://encrypted-tbn0.gstatic.com/images?q=..."
        }
      ],
      "scrapedAt": "2026-06-01T12:00:00.000Z"
    }
    ```

    ## Pagination

    To get the next page of results, increment the `start` parameter by the number of results per page:

    ```bash theme={null}
    # First page (results 1-10)
    GET /api/v1/googlesearch/search?q=nodejs&num=10

    # Second page (results 11-20)
    GET /api/v1/googlesearch/search?q=nodejs&num=10&start=11

    # Third page (results 21-30)
    GET /api/v1/googlesearch/search?q=nodejs&num=10&start=21
    ```

    ## Filter Examples

    ```bash theme={null}
    # Search within a specific site
    GET /api/v1/googlesearch/search?q=react&siteSearch=github.com

    # Search for PDFs only
    GET /api/v1/googlesearch/search?q=machine+learning&fileType=pdf

    # Search in English, last 7 days
    GET /api/v1/googlesearch/search?q=news&lr=lang_en&dateRestrict=d7

    # Search for recent tutorials
    GET /api/v1/googlesearch/search?q=python+tutorial&dateRestrict=m1

    # Safe search enabled
    GET /api/v1/googlesearch/search?q=education&safe=high
    ```

    ## Date Restrict Options

    | Value  | Description                               |
    | ------ | ----------------------------------------- |
    | `d[n]` | Last n days (e.g. `d7` = last 7 days)     |
    | `w[n]` | Last n weeks (e.g. `w2` = last 2 weeks)   |
    | `m[n]` | Last n months (e.g. `m6` = last 6 months) |
    | `y[n]` | Last n years (e.g. `y1` = last year)      |

    ## Language Codes

    | Code         | Language             |
    | ------------ | -------------------- |
    | `lang_en`    | English              |
    | `lang_es`    | Spanish              |
    | `lang_fr`    | French               |
    | `lang_de`    | German               |
    | `lang_ja`    | Japanese             |
    | `lang_zh-CN` | Chinese (Simplified) |
    | `lang_ar`    | Arabic               |
    | `lang_pt`    | Portuguese           |

    <Warning>
      Uses Google Custom Search API quota (100 queries per day on free tier). Returns `429` error when quota is exceeded. Results are cached for 10 minutes to reduce quota usage.
    </Warning>
  </Accordion>
</AccordionGroup>
