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

Send a question and get back the pages on the web most relevant to it, ranked, each with its title and an excerpt, for two credits.

Your agent can read any page, but first it has to find the right one. Search takes a question and returns the pages on the web most relevant to it, ranked, each with its URL, its title, an excerpt and a score. Each search costs two credits.

Search reads no page. Each excerpt is the passage of the page most relevant to your query, enough to decide which page to open. To read a page, pass its URL to Fetch, or ask it your question with Highlights. Search, then fetch shows both.

Your first search

import { ExpandClient } from '@expandai/sdk'

const expand = new ExpandClient()

const { results } = await expand.search({ query: 'how do I rotate a Stripe API key', maxResults: 3 })
expandai search "how do I rotate a Stripe API key" --max-results 3
// Arguments for the search tool
{
  "query": "how do I rotate a Stripe API key",
  "maxResults": 3
}
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}'

To get an API key and run this yourself, follow the Quickstart.

The settings:

SettingDefinitionDefault
queryWhat to search for, as a question or keywords, up to 2,000 characters. Spaces at either end are removed.Required
maxResultsThe most results to return, from 1 to 10. You may get fewer.10

What you get back

{
  "results": [
    {
      "url": "https://docs.stripe.com/keys",
      "title": "API keys | Stripe Documentation",
      "excerpt": "On the API keys page, click the overflow menu ( ) for the key you want to rotate. Select Rotate key. Select an expiration date from the Expiration dropdown. ...",
      "score": 0.994
    },













FieldDefinition
urlThe page.
titleThe page's title.
excerptThe passage of the page most relevant to your query, as the web results give it.
score

The results come back best first, one per page. title and excerpt are empty strings when the web results have none for the page. A query with no matches returns an empty results list. If ranking is briefly unavailable, the results still come back in the web results' order, and score only gives that order.

Note
An excerpt is the web's excerpt of the page, not the page, and carries no citation back to it. To read a page, or for cited evidence, fetch it.

Tuning the results

Search asks the web for twenty results, ranks them against your query, and returns the best maxResults in score order. One kind of query keeps the web's order instead: a query looking for pages that are things, such as grants, vendors or products, rather than pages that answer a question, because ranking favours pages about the things over the things themselves.

  • Try a full question. If keywords such as stripe api key miss, try how do I rotate a Stripe API key.
  • Start with a few results. Lower maxResults to read less, and raise it if the page you need is not there.
  • Use score to order one search. It orders the results of one search.

Credit usage

A search costs 2 credits. A search that fails, or finds nothing, costs nothing. See Pricing & Usage.

Search errors

Search returns only the standard errors:

CodeWhenRetryable
400The request is invalid, for example an empty query or a maxResults above 10.No
401The API key is missing or invalid.No

Next steps

  • Search, then fetch: read the pages Search finds, and pull out the passages that answer your question.
  • Fetch: turn a URL into Markdown your agent can read.
  • Highlights: get ranked, cited snippets that answer a question about a page.
  • TypeScript SDK: Search: the method, its options, and the response type.
  • API reference: the request and response, field by field.
PreviousWorking with snippets
NextSearch, then fetch

On This Page

Your first searchWhat you get backTuning the resultsCredit usageSearch errorsNext steps
{
"url": "https://howtorotate.com/docs/tutorials/stripe/",
"title": "Stripe - How to Rotate Leaked API Keys",
"excerpt": "This tutorial provides step-by-step instructions on how to rotate a Stripe API key. Generate a new Stripe API key Step 1 - Navigate to the API key page ...",
"score": 0.994
},
{
"url": "https://support.stripe.com/questions/how-do-i-rotate-change-update-my-stripe-api-key",
"title": "How do I rotate/change/update my Stripe API key?",
"excerpt": "Rotating a key revokes it and generates a replacement key. You can rotate a key immediately or schedule a key to rotate after a certain time. See the technical ...",
"score": 0.991
}
]
}
How well the result matches your query. Higher is better.
403
Your organization is blocked or out of credits. Nothing is charged.
No
500Search could not run.Yes. The body says retryable: true, and the SDK retries it for you.
503The search could not complete or took too long.Yes. The SDK retries it for you.