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.
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
# 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.
You don't always need to read the pages:
highlights when you want the whole page and no snippets.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.