Expand AI logo
DocsDocs
Glow Active
API Reference
Login

Documentation

Get started

IntroductionWhy ExpandQuickstartAuthenticationConnect your agent (MCP)

Products

OverviewFetching a URLBatched Fetch
API reference
OverviewSearch, then fetchAPI reference

SDKs & tools

TypeScript SDK
MCP tools & resourcesDocs for agents

Reference

API referenceErrors & retriesPricing & UsageLimitsConcurrency tiersFAQ
Browse docs

Get started

IntroductionWhy ExpandQuickstartAuthenticationConnect your agent (MCP)

Products

OverviewFetching a URLBatched Fetch
API reference
OverviewSearch, then fetchAPI reference

SDKs & tools

TypeScript SDK
MCP tools & resourcesDocs for agents

Reference

API referenceErrors & retriesPricing & UsageLimitsConcurrency tiersFAQ

Search, then fetch

Search finds the pages that answer a question. Fetch reads them, and Highlights pulls out the passages that answer it.

Search returns an excerpt of each page, not the page, and no citations. To read a page, or to answer from it with cited evidence, fetch the results you want, and add your question as Highlights to get only the passages that answer it, each linked to where it sits on the page.

Search, then highlight the top results

Send the same question to Search and to each Fetch:

import { ExpandClient, isFetchOriginError } from '@expandai/sdk'

const expand = new ExpandClient()
const query = 'how do I rotate a Stripe API key'

const { results } = await expand.search({ query, maxResults: 3 })

const settled = await Promise.allSettled(
  results.map((result) => expand.fetchJson({ url: result.url, highlights: { query, maxResults: 3 } })),
)

for (const outcome of settled) {
  // Skip pages that failed or were blocked, and keep the rest.
  if (outcome.status === 'rejected') continue





const page = outcome.value
if (isFetchOriginError(page)) continue
for (const snippet of page.data?.highlights?.snippets ?? []) {
console.log(page.meta.url, snippet.score, snippet.text)
}
}
# Find the pages.
expandai search "how do I rotate a Stripe API key" --max-results 3

# Fetch one of them with the same question.
expandai fetch https://docs.stripe.com/keys --highlights "how do I rotate a Stripe API key" --max-results 3
// 1. Arguments for the search tool
{ "query": "how do I rotate a Stripe API key", "maxResults": 3 }

// 2. Arguments for the fetch tool, for each result worth reading
{
  "url": "https://docs.stripe.com/keys",
  "highlights": { "query": "how do I rotate a Stripe API key", 
# Find the pages.
curl https://api.expand.ai/v1/search \
  -H "x-expand-api-key: $EXPAND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"how do I rotate a Stripe API key","maxResults":3}'

# Fetch one of them with the same question.
curl https://api.expand.ai/v1/fetch/json \
  -H "x-expand-api-key: $EXPAND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{


Each page comes back with its snippets under data.highlights.snippets, and a Snapshot you can cite. Working with snippets covers what a snippet contains and how to cite it.

Recommendation
Fetch only the results you need. Each Fetch is billed, so start with the highest scores and stop once you have your answer.

When to skip the fetch

You don't always need to read the pages:

  • The excerpt is enough. For a quick lookup, the title and excerpt may already answer it.
  • You only need the URLs. Pass them to Crawl to capture a whole site, or keep them for later.
  • You want the whole page. Fetch without highlights when you want the whole page and no snippets.

What it costs

A search costs 2 credits. A Fetch with Highlights costs 2 credits per web page. Searching and reading the top three results with Highlights costs 8 credits in all, when all three are web pages. A failed or blocked Fetch costs nothing. See Pricing & Usage.

Next steps

  • Two ways to highlight: Highlights on a new Fetch, or on a Snapshot you already have.
  • Fetching a URL: every Fetch option, and what comes back.
  • Search: the search request, its results, and its errors.
PreviousSearch: Overview
NextCrawl: Overview

On This Page

Search, then highlight the top resultsWhen to skip the fetchWhat it costsNext steps
"
maxResults
"
: 3 }
}
"url": "https://docs.stripe.com/keys",
"highlights": { "query": "how do I rotate a Stripe API key", "maxResults": 3 }
}'