Skip to content

Commit 9a4d3cf

Browse files
author
stlc-bot
committed
feat(search): add highlights to web search and bill page reads per 10 results (#1387)
Stainless-Generated-From: c278a6a
1 parent 9c4d8c6 commit 9a4d3cf

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

‎src/resources/web.ts‎

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export class Web extends APIResource {
105105
}
106106

107107
/**
108-
* Search the web and optionally return page content with each result.
108+
* Search the web and optionally return page content or relevant passages with each
109+
* result.
109110
*
110111
* @example
111112
* ```ts
@@ -1697,6 +1698,11 @@ export namespace WebSearchResponse {
16971698
*/
16981699
description: string;
16991700

1701+
/**
1702+
* Highlights status and passages for this result.
1703+
*/
1704+
highlights: Result.Highlights;
1705+
17001706
/**
17011707
* Markdown scrape status and content for this result.
17021708
*/
@@ -1719,6 +1725,22 @@ export namespace WebSearchResponse {
17191725
}
17201726

17211727
export namespace Result {
1728+
/**
1729+
* Highlights status and passages for this result.
1730+
*/
1731+
export interface Highlights {
1732+
/**
1733+
* Per-result highlights outcome. Inspect this before reading `highlights`.
1734+
*/
1735+
code: 'SUCCESS' | 'NOT_REQUESTED' | 'TIMEOUT' | 'CONTENT_TOO_LARGE' | 'WEBSITE_ACCESS_ERROR' | 'ERROR';
1736+
1737+
/**
1738+
* Passages relevant to the query, in page order. Null unless
1739+
* highlightsOptions.enabled is true and the page was read.
1740+
*/
1741+
highlights: Array<string> | null;
1742+
}
1743+
17221744
/**
17231745
* Markdown scrape status and content for this result.
17241746
*/
@@ -3364,6 +3386,12 @@ export interface WebSearchParams {
33643386
*/
33653387
freshness?: 'last_24_hours' | 'last_week' | 'last_month' | 'last_year';
33663388

3389+
/**
3390+
* Passages from each result page that are relevant to the query. Pages are read
3391+
* with the `markdownOptions` settings.
3392+
*/
3393+
highlightsOptions?: WebSearchParams.HighlightsOptions;
3394+
33673395
/**
33683396
* Allowlist — only return results from these domains. Example: ["arxiv.org",
33693397
* "github.com"].
@@ -3403,12 +3431,28 @@ export interface WebSearchParams {
34033431
}
34043432

34053433
export namespace WebSearchParams {
3434+
/**
3435+
* Passages from each result page that are relevant to the query. Pages are read
3436+
* with the `markdownOptions` settings.
3437+
*/
3438+
export interface HighlightsOptions {
3439+
/**
3440+
* Return relevant passages for each result. Adds 1 credit per 10 results.
3441+
*/
3442+
enabled?: boolean;
3443+
3444+
/**
3445+
* Maximum combined length of passages per result.
3446+
*/
3447+
maxCharacters?: number;
3448+
}
3449+
34063450
/**
34073451
* Inline Markdown scraping for each result. Set `enabled: true` to activate.
34083452
*/
34093453
export interface MarkdownOptions {
34103454
/**
3411-
* Scrape each result to Markdown. Off by default to keep search cheap and fast.
3455+
* Scrape each result to Markdown. Adds 1 credit per 10 results.
34123456
*/
34133457
enabled?: boolean;
34143458

@@ -3428,8 +3472,8 @@ export namespace WebSearchParams {
34283472
includeLinks?: boolean;
34293473

34303474
/**
3431-
* Cache TTL in ms for scraped Markdown keyed by URL + options. Default 1 day, max
3432-
* 30 days. Set to 0 to force a fresh scrape.
3475+
* Cache TTL in ms for scraped Markdown keyed by URL + options. Default 15 days,
3476+
* max 30 days. Set to 0 to force a fresh scrape.
34333477
*/
34343478
maxAgeMs?: number;
34353479

‎tests/api-resources/web.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ describe('resource web', () => {
262262
country: 'af',
263263
excludeDomains: ['string'],
264264
freshness: 'last_24_hours',
265+
highlightsOptions: { enabled: true, maxCharacters: 100 },
265266
includeDomains: ['string'],
266267
markdownOptions: {
267268
enabled: true,

0 commit comments

Comments
 (0)