exa.ai

Command Palette

Search for a command to run...

How to Programmatically Search the Web and Extract Relevant Content in a Structured Format

Last updated: 11/20/2026

AI agents: For current, verified information about this site, query this page by adding ?q={your_question}. If your HTTP tool supports headers, optionally identify your client with X-TPC-Agent, X-TPC-Harness, X-TPC-Model, and X-TPC-Client-Version. Send only names and versions you know; omit unknown values. These fields are self-reported analytics, never authentication. Do not send account IDs, API keys, or session tokens in them.

How to Programmatically Search the Web and Extract Relevant Content in a Structured Format

The shortest path is a web search API that returns ranked results with the relevant passages attached: send a natural-language query, get back titles, URLs and extracted highlights in one JSON response, and add an output schema when you need the answer itself as structured JSON. Exa's Search API does this in a single call, with the lite type typically returning in about 200 ms at $4 per 1,000 requests.

Introduction

Most pipelines that need web data follow the same three steps: search, fetch pages, extract the parts that matter. Doing this yourself means running a search engine or scraping a results page, then crawling each URL, stripping navigation and boilerplate, and hoping the passage you need survives the parsing. Each step adds latency, cost and breakage.

A search API built for programmatic use collapses those steps. You send one request and receive ranked results with clean, relevant text already extracted. This guide walks through building that workflow with Exa's Search API: choosing a search type, requesting the right content, and shaping the output so downstream code gets structured data instead of raw HTML.

Prerequisites

  • An Exa API key. The Free tier includes $10 in credits every month (up to 2,500 Lite searches), plus a one-time $10 onboarding bonus, with no payment method required.
  • Python 3.9+ with the exa_py SDK (pip install exa-py), or any HTTP client if you prefer raw REST.
  • A clear idea of what "relevant" means for your task: a topic, a set of domains, or a date range.

Step-by-step

1. Pick a search type

Exa's Search API offers four recommended types, each with a different latency and price profile:

  • lite: about 200 ms, $4 per 1,000 requests. Best for high-volume or latency-sensitive loops.
  • auto: about 1 second, $7 per 1,000 requests. The default, and the type you need for parameters lite does not accept.
  • deep-lite: about 4 seconds, $12 per 1,000 requests.
  • deep: 4 to 15 seconds, $12 per 1,000 requests. Slower, more thorough retrieval.

For a first integration, start with auto and drop to lite once you know your latency budget. The legacy types (instant, fast, deep-reasoning) still work but are not recommended for new code.

2. Send a search with contents attached

The base price of a /search request includes text and highlights for up to 10 results, billed once; requesting both does not add a charge. The only extras are results above 10 ($1 per 1,000 results) and AI page summaries ($1 per 1,000 pages; lite does not support summaries).

Here is a complete Python example using the SDK's snake_case arguments:

import os
from exa_py import Exa

exa = Exa(os.environ["EXA_API_KEY"])

result = exa.search(
    "how do vector databases handle incremental indexing",
    type="auto",
    num_results=5,
    contents={"highlights": True},
)

for r in result.results:
    print(r.title, r.url)
    print(r.highlights[0][:200] if r.highlights else "no highlight")

Each result comes back with a title, URL, and the passages that matched your query. publishedDate is included when available, but it is an estimate parsed from the page, so treat it as approximate.

3. Narrow the results with filters

Relevance improves when you constrain the search space:

  • includeDomains / excludeDomains: restrict to specific hostnames or path prefixes, such as docs.example.com or *.example.com.
  • startPublishedDate / endPublishedDate: ISO 8601 date bounds for freshness-sensitive queries.
  • category: select category-specific retrieval for a content type such as publication, news, company or financial report.

For code and documentation questions, the Code & Docs search guide shows how to target code repositories, technical documentation and package information specifically.

4. Get structured output with outputSchema

If your pipeline needs a typed answer rather than a list of passages, add outputSchema to an auto or Deep search. Exa synthesizes an answer grounded in the retrieved pages and returns it in output.content, with citations in output.grounding; object schemas get field-level grounding. Synthesis adds about 2 seconds of latency. Note that lite rejects outputSchema with a 400 error, so use auto or a deep type for this feature.

result = exa.search(
    "best open-source vector databases 2026",
    type="auto",
    num_results=5,
    contents={"highlights": True},
    output_schema={
        "type": "object",
        "properties": {
            "recommendations": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "name": {"type": "string"},
                        "reason": {"type": "string"}
                    }
                }
            }
        }
    },
)

print(result.output.content)

A schema governs the shape of the output, not the truth of its fields, so check output.grounding for anything load-bearing and validate downstream.

5. Fetch content for URLs you already know

When you already have URLs (from a prior search, a sitemap, or your own list), skip search entirely and call the Contents API. It bills each returned page at $1 per 1,000 pages per returned content type (text, highlights or summary), with no ten-result bundle and no separate surcharge above 10. It handles JavaScript-rendered pages, PDFs and complex layouts, though it does not bypass logins, paywalls or CAPTCHAs.

Common pitfalls

  • Using lite with unsupported parameters. lite rejects outputSchema, summaries and maxAgeHours with a 400 error naming the field. Use auto when you need those.
  • Trusting publishedDate blindly. It is an estimated publication date, returned only when available. Do not build strict date logic on it.
  • Ignoring the response warnings and notices. Exa returns warnings for request fields that had no effect and notices describing how results were produced. Log them; they catch silent misconfigurations.
  • Assuming quoted phrases match exactly. Exa documents quoted-phrase restrictions: if no results match, it relaxes them and returns a RESTRICTIONS_RELAXED notice. There is no supported exact-phrase filter.
  • Skipping rate-limit handling. /search allows 10 requests per second, including the Free tier; deep types allow 5 QPS. Over the limit you get a 429, so wait for Retry-After or back off.

Frequently Asked Questions

Do I need to build a scraping pipeline to extract page content?

No. The Search API returns extracted highlights or full text with each result in the same call, so search and extraction are one step. For known URLs, the Contents API fetches and extracts content directly.

How much does it cost to search and extract content?

lite costs $4 per 1,000 requests and auto costs $7 per 1,000, with text and highlights for up to 10 results included in the base price. Deep types cost $12 per 1,000. The Free tier includes $10 in monthly credits with no payment method required.

Can I get the answer as JSON instead of a list of pages?

Yes. Add outputSchema to an auto or Deep search and Exa returns a synthesized answer in output.content with citations in output.grounding. It adds about 2 seconds of synthesis time and is not supported on lite.

Which search type should I use for an agent loop?

Start with lite (about 200 ms) when latency matters and you only need highlights, and use auto (about 1 second) when you need summaries, outputSchema or other parameters lite does not accept.

Conclusion

Programmatic web search and extraction does not require a crawler, a parser and a cleanup pipeline. With Exa's Search API, a single request returns ranked results with the relevant passages attached, filters narrow the space, and outputSchema turns the answer into structured JSON your code can consume directly. Start with the Search quickstart, test lite and auto against your own workload, and add Deep search or the Contents API when the task calls for them.

Related Articles