Skip to content

Commit 334f2f8

Browse files
author
stlc-bot
committed
feat(batch): accept lightweight submissions and queue pending work (#2683)
Stainless-Generated-From: 0b0a550f5865353a417dcc96713281f46d01979d
1 parent 6c4ec9a commit 334f2f8

6 files changed

Lines changed: 55 additions & 20 deletions

File tree

‎src/context/dev/resources/batch.py‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def list(
9696
q: str | Omit = omit,
9797
search_type: Literal["exact", "prefix"] | Omit = omit,
9898
should_include_unified: bool | Omit = omit,
99-
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"] | Omit = omit,
99+
status: Literal["pending", "queued", "running", "cancelling", "completed", "cancelled", "failed"] | Omit = omit,
100100
tags: Union[str, SequenceNotStr[str]] | Omit = omit,
101101
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
102102
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -305,8 +305,15 @@ def submit(
305305
"""
306306
Scrape up to 100,000 URLs, or crawl a site, asynchronously using the same
307307
formats and scrape parameters as POST /web/scrape. Choose Markdown, HTML,
308-
screenshots, images, bytes, parsed fields, products, highlights, and JSON. Poll
309-
the batch ID or receive a webhook when it finishes.
308+
screenshots, images, bytes, parsed fields, products, highlights, and JSON.
309+
Submission persists the input and returns immediately with status pending.
310+
Organizations with fewer than 10 available credits and no overage are rejected
311+
with 402 up front. Each organization can submit up to 1,000 batches per minute,
312+
independently of its polling budget. Batches wait pending when execution
313+
capacity is full. Validation, sitemap discovery, the full credit quote, and
314+
shard scheduling happen afterward. Poll the batch ID or receive a webhook when
315+
it finishes. Deferred rejections appear as status failed with a failure code and
316+
message.
310317
311318
Args:
312319
input: Choose a URL list or a site crawl.
@@ -419,7 +426,7 @@ async def list(
419426
q: str | Omit = omit,
420427
search_type: Literal["exact", "prefix"] | Omit = omit,
421428
should_include_unified: bool | Omit = omit,
422-
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"] | Omit = omit,
429+
status: Literal["pending", "queued", "running", "cancelling", "completed", "cancelled", "failed"] | Omit = omit,
423430
tags: Union[str, SequenceNotStr[str]] | Omit = omit,
424431
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
425432
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -628,8 +635,15 @@ async def submit(
628635
"""
629636
Scrape up to 100,000 URLs, or crawl a site, asynchronously using the same
630637
formats and scrape parameters as POST /web/scrape. Choose Markdown, HTML,
631-
screenshots, images, bytes, parsed fields, products, highlights, and JSON. Poll
632-
the batch ID or receive a webhook when it finishes.
638+
screenshots, images, bytes, parsed fields, products, highlights, and JSON.
639+
Submission persists the input and returns immediately with status pending.
640+
Organizations with fewer than 10 available credits and no overage are rejected
641+
with 402 up front. Each organization can submit up to 1,000 batches per minute,
642+
independently of its polling budget. Batches wait pending when execution
643+
capacity is full. Validation, sitemap discovery, the full credit quote, and
644+
shard scheduling happen afterward. Poll the batch ID or receive a webhook when
645+
it finishes. Deferred rejections appear as status failed with a failure code and
646+
message.
633647
634648
Args:
635649
input: Choose a URL list or a site crawl.

‎src/context/dev/types/batch_list_params.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BatchListParams(TypedDict, total=False):
3333
should_include_unified: Annotated[bool, PropertyInfo(alias="shouldIncludeUnified")]
3434
"""Include batches submitted with Scrape Anything formats. Defaults to false."""
3535

36-
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"]
36+
status: Literal["pending", "queued", "running", "cancelling", "completed", "cancelled", "failed"]
3737
"""Filter by status."""
3838

3939
tags: Union[str, SequenceNotStr[str]]

‎src/context/dev/types/batch_list_response.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ class DataCredits(BaseModel):
3737
"""Credits returned for unsuccessful pages when the batch settles."""
3838

3939
reserved: int
40-
"""Credits held when the batch was accepted."""
40+
"""Credits held by background preparation before scraping starts.
41+
42+
Zero while pending.
43+
"""
4144

4245

4346
class DataFormats(BaseModel):
@@ -167,8 +170,13 @@ class Data(BaseModel):
167170
Files are deleted 180 days after the batch finishes.
168171
"""
169172

170-
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"]
171-
"""Current state. `completed`, `cancelled`, and `failed` are final."""
173+
status: Literal["pending", "queued", "running", "cancelling", "completed", "cancelled", "failed"]
174+
"""Current state.
175+
176+
`pending` means waiting for execution capacity or background validation.
177+
Capacity-limited batches remain pending until a slot opens. `completed`,
178+
`cancelled`, and `failed` are final.
179+
"""
172180

173181
tags: List[str]
174182
"""Tags stored on the batch at submission."""

‎src/context/dev/types/batch_retrieve_response.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ class Credits(BaseModel):
3737
"""Credits returned for unsuccessful pages when the batch settles."""
3838

3939
reserved: int
40-
"""Credits held when the batch was accepted."""
40+
"""Credits held by background preparation before scraping starts.
41+
42+
Zero while pending.
43+
"""
4144

4245

4346
class Formats(BaseModel):
@@ -192,8 +195,13 @@ class BatchRetrieveResponse(BaseModel):
192195
Files are deleted 180 days after the batch finishes.
193196
"""
194197

195-
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"]
196-
"""Current state. `completed`, `cancelled`, and `failed` are final."""
198+
status: Literal["pending", "queued", "running", "cancelling", "completed", "cancelled", "failed"]
199+
"""Current state.
200+
201+
`pending` means waiting for execution capacity or background validation.
202+
Capacity-limited batches remain pending until a slot opens. `completed`,
203+
`cancelled`, and `failed` are final.
204+
"""
197205

198206
tags: List[str]
199207
"""Tags stored on the batch at submission."""

‎src/context/dev/types/batch_submit_response.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class CacheMetadata(BaseModel):
2626

2727

2828
class Credits(BaseModel):
29-
"""What accepting this batch cost."""
29+
"""Credits are reserved after background validation, before scraping starts."""
3030

3131
reserved: int
32-
"""Credits held at submission."""
32+
"""Credits reserved by background preparation. Zero while pending."""
3333

3434

3535
class Formats(BaseModel):
@@ -98,7 +98,7 @@ class BatchSubmitResponse(BaseModel):
9898
"""When the batch was created."""
9999

100100
credits: Credits
101-
"""What accepting this batch cost."""
101+
"""Credits are reserved after background validation, before scraping starts."""
102102

103103
formats: Formats
104104
"""Outputs requested for each page. Matches input.data.formats on submission."""
@@ -118,8 +118,13 @@ class BatchSubmitResponse(BaseModel):
118118
Include it when contacting support.
119119
"""
120120

121-
status: Literal["queued"]
122-
"""Always `queued`. An accepted batch has not started yet."""
121+
status: Literal["pending", "queued", "running", "cancelling", "completed", "cancelled", "failed"]
122+
"""Current state.
123+
124+
`pending` means waiting for execution capacity or background validation.
125+
Capacity-limited batches remain pending until a slot opens. `completed`,
126+
`cancelled`, and `failed` are final.
127+
"""
123128

124129
tags: List[str]
125130
"""Tags stored on the batch."""

‎tests/api_resources/test_batch.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_method_list_with_all_params(self, client: ContextDev) -> None:
8181
q="batch_1a2b",
8282
search_type="exact",
8383
should_include_unified=True,
84-
status="queued",
84+
status="pending",
8585
tags="docs,competitor",
8686
)
8787
assert_matches_type(BatchListResponse, batch, path=["response"])
@@ -495,7 +495,7 @@ async def test_method_list_with_all_params(self, async_client: AsyncContextDev)
495495
q="batch_1a2b",
496496
search_type="exact",
497497
should_include_unified=True,
498-
status="queued",
498+
status="pending",
499499
tags="docs,competitor",
500500
)
501501
assert_matches_type(BatchListResponse, batch, path=["response"])

0 commit comments

Comments
 (0)