Skip to content

Commit 1d7200a

Browse files
feat(api): add fetch_policy and mode to /v1beta/search
1 parent fd8a351 commit 1d7200a

19 files changed

+204
-115
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 13
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/parallel-web%2Fparallel-sdk-9ec04ca53245a774513f3e178c29a560d6ecb3f88f936859e6311bf0d4ad1fb2.yml
3-
openapi_spec_hash: 022ed0f0e4ad23fd88f8d3a8fe003e14
4-
config_hash: 5c1316cf65d52fe3b23d4fe7acbb4baf
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/parallel-web%2Fparallel-sdk-40c12295a3f32ed93d58b523bb28f33ceabe8e6bfa8c44d5f863ed9c77feff58.yml
3+
openapi_spec_hash: 9f3cd99867507ada834db61c6d8391b9
4+
config_hash: 677d555754b79eb922f6bf64bccd9559

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ from parallel.types.beta import (
4747
ExtractResult,
4848
FetchPolicy,
4949
SearchResult,
50+
UsageItem,
5051
WebSearchResult,
5152
)
5253
```

src/parallel/resources/beta/beta.py

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from ...types.beta.extract_response import ExtractResponse
4141
from ...types.beta.fetch_policy_param import FetchPolicyParam
4242
from ...types.beta.parallel_beta_param import ParallelBetaParam
43+
from ...types.beta.excerpt_settings_param import ExcerptSettingsParam
4344
from ...types.shared_params.source_policy import SourcePolicy
4445

4546
__all__ = ["BetaResource", "AsyncBetaResource"]
@@ -77,12 +78,12 @@ def extract(
7778
self,
7879
*,
7980
urls: SequenceNotStr[str],
81+
betas: List[ParallelBetaParam],
8082
excerpts: beta_extract_params.Excerpts | Omit = omit,
8183
fetch_policy: Optional[FetchPolicyParam] | Omit = omit,
8284
full_content: beta_extract_params.FullContent | Omit = omit,
8385
objective: Optional[str] | Omit = omit,
8486
search_queries: Optional[SequenceNotStr[str]] | Omit = omit,
85-
betas: List[ParallelBetaParam] | Omit = omit,
8687
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
8788
# The extra values given here take precedence over values defined on the client or passed to this method.
8889
extra_headers: Headers | None = None,
@@ -97,14 +98,17 @@ def extract(
9798
`search-extract-2025-10-10`.
9899
99100
Args:
101+
betas: Optional header to specify the beta version(s) to enable.
102+
100103
excerpts: Include excerpts from each URL relevant to the search objective and queries.
101104
Note that if neither objective nor search_queries is provided, excerpts are
102105
redundant with full content.
103106
104-
fetch_policy: Fetch policy.
107+
fetch_policy: Policy for live fetching web results.
105108
106-
Determines when to return content from the cache (faster) vs fetching live
107-
content (fresher).
109+
Determines when to return cached content from the index (faster) vs fetching
110+
live content (fresher). The default policy for search uses cached results only,
111+
while extract uses a dynamic policy based on the search objective and url.
108112
109113
full_content: Include full content from each URL. Note that if neither objective nor
110114
search_queries is provided, excerpts are redundant with full content.
@@ -113,8 +117,6 @@ def extract(
113117
114118
search_queries: If provided, focuses extracted content on the specified keyword search queries.
115119
116-
betas: Optional header to specify the beta version(s) to enable.
117-
118120
extra_headers: Send extra headers
119121
120122
extra_query: Add additional query parameters to the request
@@ -124,16 +126,10 @@ def extract(
124126
timeout: Override the client-level default timeout for this request, in seconds
125127
"""
126128
extra_headers = {
127-
**strip_not_given(
128-
{
129-
"parallel-beta": ",".join(chain((str(e) for e in betas), ["search-extract-2025-10-10"]))
130-
if is_given(betas)
131-
else not_given
132-
}
133-
),
129+
"parallel-beta": ",".join(chain((str(e) for e in betas), ["search-extract-2025-10-10"])),
134130
**(extra_headers or {}),
135131
}
136-
extra_headers = {"parallel-beta": "search-extract-2025-10-10", **(extra_headers or {})}
132+
extra_headers.update({"parallel-beta": "search-extract-2025-10-10"})
137133
return self._post(
138134
"/v1beta/extract",
139135
body=maybe_transform(
@@ -156,10 +152,11 @@ def extract(
156152
def search(
157153
self,
158154
*,
159-
max_chars_per_result: Optional[int] | Omit = omit,
155+
excerpts: ExcerptSettingsParam | Omit = omit,
156+
fetch_policy: Optional[FetchPolicyParam] | Omit = omit,
160157
max_results: Optional[int] | Omit = omit,
158+
mode: Optional[Literal["one-shot", "agentic"]] | Omit = omit,
161159
objective: Optional[str] | Omit = omit,
162-
processor: Optional[Literal["base", "pro"]] | Omit = omit,
163160
search_queries: Optional[SequenceNotStr[str]] | Omit = omit,
164161
source_policy: Optional[SourcePolicy] | Omit = omit,
165162
betas: List[ParallelBetaParam] | Omit = omit,
@@ -173,19 +170,30 @@ def search(
173170
"""
174171
Searches the web.
175172
173+
To access this endpoint, pass the `parallel-beta` header with the value
174+
`search-extract-2025-10-10`.
175+
176176
Args:
177-
max_chars_per_result: Upper bound on the number of characters to include in excerpts for each search
178-
result.
177+
excerpts: Optional settings for returning relevant excerpts.
178+
179+
fetch_policy: Policy for live fetching web results.
180+
181+
Determines when to return cached content from the index (faster) vs fetching
182+
live content (fresher). The default policy for search uses cached results only,
183+
while extract uses a dynamic policy based on the search objective and url.
179184
180185
max_results: Upper bound on the number of results to return. May be limited by the processor.
181186
Defaults to 10 if not provided.
182187
188+
mode: Presets default values for parameters for different use cases. `one-shot`
189+
returns more comprehensive results and longer excerpts to answer questions from
190+
a single response, while `agentic` returns more concise, token-efficient results
191+
for use in an agentic loop.
192+
183193
objective: Natural-language description of what the web search is trying to find. May
184194
include guidance about preferred sources or freshness. At least one of objective
185195
or search_queries must be provided.
186196
187-
processor: Search processor.
188-
189197
search_queries: Optional list of traditional keyword search queries to guide the search. May
190198
contain search operators. At least one of objective or search_queries must be
191199
provided.
@@ -219,10 +227,11 @@ def search(
219227
"/v1beta/search",
220228
body=maybe_transform(
221229
{
222-
"max_chars_per_result": max_chars_per_result,
230+
"excerpts": excerpts,
231+
"fetch_policy": fetch_policy,
223232
"max_results": max_results,
233+
"mode": mode,
224234
"objective": objective,
225-
"processor": processor,
226235
"search_queries": search_queries,
227236
"source_policy": source_policy,
228237
},
@@ -267,12 +276,12 @@ async def extract(
267276
self,
268277
*,
269278
urls: SequenceNotStr[str],
279+
betas: List[ParallelBetaParam],
270280
excerpts: beta_extract_params.Excerpts | Omit = omit,
271281
fetch_policy: Optional[FetchPolicyParam] | Omit = omit,
272282
full_content: beta_extract_params.FullContent | Omit = omit,
273283
objective: Optional[str] | Omit = omit,
274284
search_queries: Optional[SequenceNotStr[str]] | Omit = omit,
275-
betas: List[ParallelBetaParam] | Omit = omit,
276285
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
277286
# The extra values given here take precedence over values defined on the client or passed to this method.
278287
extra_headers: Headers | None = None,
@@ -287,14 +296,17 @@ async def extract(
287296
`search-extract-2025-10-10`.
288297
289298
Args:
299+
betas: Optional header to specify the beta version(s) to enable.
300+
290301
excerpts: Include excerpts from each URL relevant to the search objective and queries.
291302
Note that if neither objective nor search_queries is provided, excerpts are
292303
redundant with full content.
293304
294-
fetch_policy: Fetch policy.
305+
fetch_policy: Policy for live fetching web results.
295306
296-
Determines when to return content from the cache (faster) vs fetching live
297-
content (fresher).
307+
Determines when to return cached content from the index (faster) vs fetching
308+
live content (fresher). The default policy for search uses cached results only,
309+
while extract uses a dynamic policy based on the search objective and url.
298310
299311
full_content: Include full content from each URL. Note that if neither objective nor
300312
search_queries is provided, excerpts are redundant with full content.
@@ -303,8 +315,6 @@ async def extract(
303315
304316
search_queries: If provided, focuses extracted content on the specified keyword search queries.
305317
306-
betas: Optional header to specify the beta version(s) to enable.
307-
308318
extra_headers: Send extra headers
309319
310320
extra_query: Add additional query parameters to the request
@@ -314,16 +324,10 @@ async def extract(
314324
timeout: Override the client-level default timeout for this request, in seconds
315325
"""
316326
extra_headers = {
317-
**strip_not_given(
318-
{
319-
"parallel-beta": ",".join(chain((str(e) for e in betas), ["search-extract-2025-10-10"]))
320-
if is_given(betas)
321-
else not_given
322-
}
323-
),
327+
"parallel-beta": ",".join(chain((str(e) for e in betas), ["search-extract-2025-10-10"])),
324328
**(extra_headers or {}),
325329
}
326-
extra_headers = {"parallel-beta": "search-extract-2025-10-10", **(extra_headers or {})}
330+
extra_headers.update({"parallel-beta": "search-extract-2025-10-10"})
327331
return await self._post(
328332
"/v1beta/extract",
329333
body=await async_maybe_transform(
@@ -346,10 +350,11 @@ async def extract(
346350
async def search(
347351
self,
348352
*,
349-
max_chars_per_result: Optional[int] | Omit = omit,
353+
excerpts: ExcerptSettingsParam | Omit = omit,
354+
fetch_policy: Optional[FetchPolicyParam] | Omit = omit,
350355
max_results: Optional[int] | Omit = omit,
356+
mode: Optional[Literal["one-shot", "agentic"]] | Omit = omit,
351357
objective: Optional[str] | Omit = omit,
352-
processor: Optional[Literal["base", "pro"]] | Omit = omit,
353358
search_queries: Optional[SequenceNotStr[str]] | Omit = omit,
354359
source_policy: Optional[SourcePolicy] | Omit = omit,
355360
betas: List[ParallelBetaParam] | Omit = omit,
@@ -363,19 +368,30 @@ async def search(
363368
"""
364369
Searches the web.
365370
371+
To access this endpoint, pass the `parallel-beta` header with the value
372+
`search-extract-2025-10-10`.
373+
366374
Args:
367-
max_chars_per_result: Upper bound on the number of characters to include in excerpts for each search
368-
result.
375+
excerpts: Optional settings for returning relevant excerpts.
376+
377+
fetch_policy: Policy for live fetching web results.
378+
379+
Determines when to return cached content from the index (faster) vs fetching
380+
live content (fresher). The default policy for search uses cached results only,
381+
while extract uses a dynamic policy based on the search objective and url.
369382
370383
max_results: Upper bound on the number of results to return. May be limited by the processor.
371384
Defaults to 10 if not provided.
372385
386+
mode: Presets default values for parameters for different use cases. `one-shot`
387+
returns more comprehensive results and longer excerpts to answer questions from
388+
a single response, while `agentic` returns more concise, token-efficient results
389+
for use in an agentic loop.
390+
373391
objective: Natural-language description of what the web search is trying to find. May
374392
include guidance about preferred sources or freshness. At least one of objective
375393
or search_queries must be provided.
376394
377-
processor: Search processor.
378-
379395
search_queries: Optional list of traditional keyword search queries to guide the search. May
380396
contain search operators. At least one of objective or search_queries must be
381397
provided.
@@ -409,10 +425,11 @@ async def search(
409425
"/v1beta/search",
410426
body=await async_maybe_transform(
411427
{
412-
"max_chars_per_result": max_chars_per_result,
428+
"excerpts": excerpts,
429+
"fetch_policy": fetch_policy,
413430
"max_results": max_results,
431+
"mode": mode,
414432
"objective": objective,
415-
"processor": processor,
416433
"search_queries": search_queries,
417434
"source_policy": source_policy,
418435
},

src/parallel/types/beta/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .webhook import Webhook as Webhook
66
from .mcp_server import McpServer as McpServer
77
from .task_group import TaskGroup as TaskGroup
8+
from .usage_item import UsageItem as UsageItem
89
from .error_event import ErrorEvent as ErrorEvent
910
from .extract_error import ExtractError as ExtractError
1011
from .mcp_tool_call import McpToolCall as McpToolCall

src/parallel/types/beta/beta_extract_params.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
class BetaExtractParams(TypedDict, total=False):
1818
urls: Required[SequenceNotStr[str]]
1919

20+
betas: Required[Annotated[List[ParallelBetaParam], PropertyInfo(alias="parallel-beta")]]
21+
"""Optional header to specify the beta version(s) to enable."""
22+
2023
excerpts: Excerpts
2124
"""Include excerpts from each URL relevant to the search objective and queries.
2225
@@ -25,10 +28,11 @@ class BetaExtractParams(TypedDict, total=False):
2528
"""
2629

2730
fetch_policy: Optional[FetchPolicyParam]
28-
"""Fetch policy.
31+
"""Policy for live fetching web results.
2932
30-
Determines when to return content from the cache (faster) vs fetching live
31-
content (fresher).
33+
Determines when to return cached content from the index (faster) vs fetching
34+
live content (fresher). The default policy for search uses cached results only,
35+
while extract uses a dynamic policy based on the search objective and url.
3236
"""
3337

3438
full_content: FullContent
@@ -44,9 +48,6 @@ class BetaExtractParams(TypedDict, total=False):
4448
search_queries: Optional[SequenceNotStr[str]]
4549
"""If provided, focuses extracted content on the specified keyword search queries."""
4650

47-
betas: Annotated[List[ParallelBetaParam], PropertyInfo(alias="parallel-beta")]
48-
"""Optional header to specify the beta version(s) to enable."""
49-
5051

5152
Excerpts: TypeAlias = Union[bool, ExcerptSettingsParam]
5253

src/parallel/types/beta/beta_search_params.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77

88
from ..._types import SequenceNotStr
99
from ..._utils import PropertyInfo
10+
from .fetch_policy_param import FetchPolicyParam
1011
from .parallel_beta_param import ParallelBetaParam
12+
from .excerpt_settings_param import ExcerptSettingsParam
1113
from ..shared_params.source_policy import SourcePolicy
1214

1315
__all__ = ["BetaSearchParams"]
1416

1517

1618
class BetaSearchParams(TypedDict, total=False):
17-
max_chars_per_result: Optional[int]
18-
"""
19-
Upper bound on the number of characters to include in excerpts for each search
20-
result.
19+
excerpts: ExcerptSettingsParam
20+
"""Optional settings for returning relevant excerpts."""
21+
22+
fetch_policy: Optional[FetchPolicyParam]
23+
"""Policy for live fetching web results.
24+
25+
Determines when to return cached content from the index (faster) vs fetching
26+
live content (fresher). The default policy for search uses cached results only,
27+
while extract uses a dynamic policy based on the search objective and url.
2128
"""
2229

2330
max_results: Optional[int]
@@ -26,16 +33,21 @@ class BetaSearchParams(TypedDict, total=False):
2633
May be limited by the processor. Defaults to 10 if not provided.
2734
"""
2835

36+
mode: Optional[Literal["one-shot", "agentic"]]
37+
"""Presets default values for parameters for different use cases.
38+
39+
`one-shot` returns more comprehensive results and longer excerpts to answer
40+
questions from a single response, while `agentic` returns more concise,
41+
token-efficient results for use in an agentic loop.
42+
"""
43+
2944
objective: Optional[str]
3045
"""Natural-language description of what the web search is trying to find.
3146
3247
May include guidance about preferred sources or freshness. At least one of
3348
objective or search_queries must be provided.
3449
"""
3550

36-
processor: Optional[Literal["base", "pro"]]
37-
"""Search processor."""
38-
3951
search_queries: Optional[SequenceNotStr[str]]
4052
"""Optional list of traditional keyword search queries to guide the search.
4153

src/parallel/types/beta/excerpt_settings_param.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class ExcerptSettingsParam(TypedDict, total=False):
1212
max_chars_per_result: Optional[int]
13-
"""
14-
Optional upper bound on the total number of characters to include across all
15-
excerpts for each url. Excerpts may contain fewer characters than this limit to
16-
maximize relevance and token efficiency.
13+
"""Optional upper bound on the total number of characters to include per url.
14+
15+
Excerpts may contain fewer characters than this limit to maximize relevance and
16+
token efficiency.
1717
"""

0 commit comments

Comments
 (0)