# Web Search

> Execute web searches with the Bing API using retrieval.webSearch in scripts.

The `retrieval.webSearch` executes a web search using [Tavily](https://docs.tavily.com/) or the Bing Web Search.

## Web Pages

[Section titled “Web Pages”](#web-pages)

By default, the API returns the first 10 web pages in the `webPages` field as an array of files, similarly to `env.files`. The content contains the summary snippet returned by the search engine.

```js
const webPages = await retrieval.webSearch("microsoft")
def("PAGES", webPages)
```

You can use `fetchText` to download the full content of the web page.

## Tavily Configuration[]()

[Section titled “Tavily Configuration ”](#tavily-configuration)

The [Tavily API](https://docs.tavily.com/docs/rest-api/api-reference#endpoint-post-search) provides access to a powerful search engine for LLM agents.

.env

```txt
TAVILY_API_KEY="your-api-key"
```

## Tool

[Section titled “Tool”](#tool)

Add the [system.retrieval\_web\_search](https://github.com/microsoft/genaiscript/blob/main/packages/core/src/genaisrc/system.retrieval_web_search.genai.mjs) system script to register a [tool](/genaiscript/reference/scripts/tools) that uses `retrieval.webSearch`.

```js
script({
    ...,
    system: ["system.retrieval_web_search"]
})
...
```