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.
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:
| Setting | Definition | Default |
|---|---|---|
query | What to search for, as a question or keywords, up to 2,000 characters. Spaces at either end are removed. | Required |
maxResults | The most results to return, from 1 to 10. You may get fewer. | 10 |
{
"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
},
| Field | Definition |
|---|---|
url | The page. |
title | The page's title. |
excerpt | The 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.
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.
stripe api key miss, try how do I rotate a Stripe API key.maxResults to read less, and raise it if the page you need is not there.score to order one search. It orders the results of one search.A search costs 2 credits. A search that fails, or finds nothing, costs nothing. See Pricing & Usage.
Search returns only the standard errors:
| Code | When | Retryable |
|---|---|---|
400 | The request is invalid, for example an empty query or a maxResults above 10. | No |
401 | The API key is missing or invalid. | No |
| How well the result matches your query. Higher is better. |
403 |
| Your organization is blocked or out of credits. Nothing is charged. |
| No |
500 | Search could not run. | Yes. The body says retryable: true, and the SDK retries it for you. |
503 | The search could not complete or took too long. | Yes. The SDK retries it for you. |