# search()

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/tools/search/
Language: pt

`api.tools.search(options) → Promise<SearchResult>`

Search runs on IaGenify’s SearXNG index. Use a simple query for web results, or choose keyword research, site discovery, a page audit, or a competitor URL gap. Result caps do not guarantee that upstream indexes contain that many matches.

Status: POST /api/search · 1 credit · cached for a day

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `query` | string | required | What to look for. Missing or not a string raises `query_required` (400). |
| `action` | object | search | Choose `search`, `keyword_research`, `site_discovery`, `seo_audit`, or `competitor_gap`. |
| `maxResults` | integer | 10 | Requested result ceiling, 1–10000. This does not force an upstream index to return that many. |
| `page` | integer | 1 | SearXNG result page, starting at 1. |
| `safeSearch` | integer | 1 | `0` off · `1` moderate · `2` strict. |
| `recencyDays` | integer |  | Restrict to the last 1, 7, 30, or 365 days. |
| `language / region` | string |  | Prefer a language such as `fr` and region such as `TN`. |

## Actions {#actions}

The service uses the configured SearXNG instance only; callers cannot select an engine. `keyword_research` combines suggestions with a seed search. `site_discovery` checks sitemaps, public archives, then a bounded same-site crawl. `seo_audit` inspects one rendered page. `competitor_gap` compares sampled URL paths for one site and 1–5 competitors.

## Returns {#returns}

```javascript
{
  ok: true,
  query: "ISO 8601 week numbering",
  results: [{
    title: "ISO week date",
    url: "https://example.com/iso-week-date",
    snippet: "The ISO week date system is…",
    score: 0.92
  }],
  action: "search",
  page: 1,
  maxResults: 20,
  cached: false,
  creditsUsed: 1,
  timing: { durationMs: 1840 }
}
```

## How the list is built {#ranking}

- The request is sent to the configured SearXNG instance; the public API does not let callers select upstream engines.
- Duplicate result URLs are collapsed and results are ordered by score.
- The returned list is cut to `maxResults`.
- Use `page` to request a later SearXNG result page.

A source that answers slowly is simply not in the merge; the call returns with what arrived.

> **A result ceiling is not a result promise**
>
> SearXNG and its upstream indexes may return fewer results than requested. Increase `maxResults` only to allow a larger response, and use `page` to request later results.

## What is charged {#billing}

| Action | Credits when uncached |
| --- | --- |
| `search` | 1 per result page; empty results are refunded |
| `keyword_research` | 0–2, one per suggestions or result operation returning data |
| `site_discovery` | 1 per 20 URLs returned; unused reservation refunded |
| `seo_audit` | 1 for an uncached rendered page capture |
| `competitor_gap` | 1 for each of the site/competitor result sets that returns data (up to 6) |
| A cache hit | 0 credits |

The cache key includes the action, query, page and relevant filters. Changing `maxResults` or `recencyDays` creates a new request.

```javascript
const found = await api.tools.search({ query, page: 1, maxResults: 20, language: "fr", region: "TN" });

if (found.noResults) {
  // Nothing was charged. Broaden the query rather than retrying it.
}
```

## Errors {#errors}

| Code | Status | When |
| --- | --- | --- |
| query_required | 400 | `query` is missing or is not a string. |
| NotEnoughCredits | 402 | The balance will not cover the price, surcharge included. |

## As a tool {#as-a-tool}

Declared as an agent tool, the SearXNG-backed action has no caller-selected engine and costs according to the selected action. Site discovery may reserve more than one credit and refunds unused capacity.

```javascript
tools: {
  search: { run: api.tools.search, options: { maxResults: 5 }, cost: 1 },
}
```

- [fetch()](/pt/sdk/ref/tools/fetch): Open one of the results and read it.
- [The agent's search](/pt/sdk/agent/tools/search): The same capability inside the local engine.
- [api.tools](/pt/sdk/ref/tools): The fifteen, and the two ways to use them.

```python
{
    "ok": True,
    "query": "ISO 8601 week numbering",
    "results": [
        {
            "title": "ISO week date",
            "url": "https://en.wikipedia.org/wiki/ISO_week_date",
            "snippet": "The ISO week date system is…",
            "engine": "wikipedia",       # the source's own label
            "engineKey": "wiki",         # the name you passed
            "score": 1,
        }
    ],
    "enginesUsed": ["wiki", "arxiv", "searxng"],
    "engineErrors": {"stackex": "timeout"},
    "cached": False,
    "creditsUsed": 1,
    "timing": {"durationMs": 1840},
}
```

```python
found = api.tools.search({"query": query, "engines": ["all"], "recencyDays": 7})

if found.get("noResults"):
    pass  # Nothing was charged. Broaden the query rather than retrying it.
```

```python
tools = {
    "search": {"run": api.tools.search, "options": {"engines": ["all"], "maxResults": 5}, "cost": 5},
}
```
