Skip to content

Commit 63b8964

Browse files
feat(api): api update
1 parent 0f2943f commit 63b8964

12 files changed

Lines changed: 296 additions & 156 deletions

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 37
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-960cb623c7ec84bf4dc0f5945cbc19eec9cca48271071f400d96066eaa55dbd6.yml
3-
openapi_spec_hash: 84fd39e3f4dc964bf0c32d4e95da1b34
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-838f03b1c3584485eeded993459e6bbae058da9f6df16b7967980fbba98cc748.yml
3+
openapi_spec_hash: 4a9db9cd9eac4ae4e2694b3d835a772f
44
config_hash: 2bea1743c84d63bd61f8501a6ea63065

‎api.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ Types:
140140

141141
```python
142142
from context.dev.types import (
143-
ErrorCount,
144-
Error,
143+
PageErrorCount,
144+
Failure,
145+
CrawlControls,
146+
Intake,
145147
BatchRetrieveResponse,
146148
BatchListResponse,
147149
BatchCancelResponse,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def retrieve(
6161
"""Check progress and get download links when the batch finishes.
6262
6363
Also returns the
64-
rejected-URL list and webhook signing secret from submission, so nothing is lost
65-
if the submit response was dropped.
64+
rejected-URL list from submission. The webhook signing secret is not repeated
65+
here — it is returned once, by the submit response.
6666
6767
Args:
6868
batch_id: ID of the batch to retrieve or cancel.
@@ -326,8 +326,8 @@ async def retrieve(
326326
"""Check progress and get download links when the batch finishes.
327327
328328
Also returns the
329-
rejected-URL list and webhook signing secret from submission, so nothing is lost
330-
if the submit response was dropped.
329+
rejected-URL list from submission. The webhook signing secret is not repeated
330+
here — it is returned once, by the submit response.
331331
332332
Args:
333333
batch_id: ID of the batch to retrieve or cancel.

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

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

33
from __future__ import annotations
44

5-
from .error import Error as Error
6-
from .error_count import ErrorCount as ErrorCount
5+
from .intake import Intake as Intake
6+
from .failure import Failure as Failure
7+
from .crawl_controls import CrawlControls as CrawlControls
8+
from .page_error_count import PageErrorCount as PageErrorCount
79
from .webhook_delivery import WebhookDelivery as WebhookDelivery
810
from .batch_list_params import BatchListParams as BatchListParams
911
from .web_search_params import WebSearchParams as WebSearchParams

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

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,49 @@
33
from typing import List, Optional
44
from typing_extensions import Literal
55

6-
from .error import Error
6+
from .intake import Intake
7+
from .failure import Failure
78
from .._models import BaseModel
8-
from .error_count import ErrorCount
9+
from .crawl_controls import CrawlControls
10+
from .page_error_count import PageErrorCount
911

10-
__all__ = ["BatchCancelResponse", "Credits", "Input", "Progress", "Results", "ResultsFile", "Timing", "KeyMetadata"]
12+
__all__ = ["BatchCancelResponse", "Credits", "Progress", "Results", "ResultsFile", "Timing", "KeyMetadata"]
1113

1214

1315
class Credits(BaseModel):
14-
"""Reserved and used credits."""
16+
"""What this batch has done to your credit balance."""
1517

16-
charged: int
17-
"""Credits used by successful pages."""
18+
net: int
19+
"""`reserved` minus `refunded` — what the batch has cost so far.
1820
19-
estimated: int
20-
"""Credits reserved when the batch was accepted."""
21-
22-
23-
class Input(BaseModel):
24-
"""Submission counts."""
21+
Equal to `reserved` until the batch settles.
22+
"""
2523

26-
accepted: int
27-
"""Pages accepted, or the crawl page limit. Credits are reserved for this count."""
24+
refunded: int
25+
"""Credits returned for pages that did not succeed.
2826
29-
duplicates: int
30-
"""Duplicate URL and `itemId` pairs skipped. Always 0 for crawls."""
27+
Stays 0 until the batch reaches a final status, then settles in one movement.
28+
"""
3129

32-
invalid: int
33-
"""Pages rejected during validation."""
30+
reserved: int
31+
"""Credits debited from your balance the moment the batch was accepted.
3432
35-
submitted: int
36-
"""Pages submitted before validation. For a crawl, the page limit."""
33+
This is a charge, not a forecast — the whole amount leaves the balance up front.
34+
"""
3735

3836

3937
class Progress(BaseModel):
40-
"""Current processing counts. Use `status` to check completion."""
38+
"""Pages attempted so far. Use `status` to check completion."""
4139

4240
failed: int
4341
"""Pages that could not be scraped."""
4442

4543
pending: int
46-
"""Accepted pages not yet attempted.
44+
"""Reserved pages not yet attempted.
4745
48-
Always 0 once the batch completes; a crawl can finish under its page limit when
49-
the site has no more reachable pages.
46+
A cancelled batch keeps reporting the URLs it never reached; a crawl whose
47+
`input.reserved_is_ceiling` is true reports 0 once final, because its unspent
48+
budget was never real pages.
5049
"""
5150

5251
succeeded: int
@@ -65,9 +64,8 @@ class ResultsFile(BaseModel):
6564

6665

6766
class Results(BaseModel):
68-
"""Download links available when the batch finishes.
69-
70-
GET /batch/{batch_id}/results serves the same records as paginated JSON.
67+
"""
68+
Download links, available once the batch reaches a final status and null before then. GET /batch/{batch_id}/results serves the same records as paginated JSON.
7169
"""
7270

7371
expires_at: str
@@ -102,28 +100,46 @@ class BatchCancelResponse(BaseModel):
102100
id: str
103101
"""Batch ID used to retrieve or cancel the job."""
104102

103+
crawl: Optional[CrawlControls] = None
104+
"""
105+
The crawl controls as submitted, so the limits requested can be compared against
106+
what the crawl reached.
107+
"""
108+
105109
credits: Credits
106-
"""Reserved and used credits."""
110+
"""What this batch has done to your credit balance."""
107111

108-
error: Optional[Error] = None
109-
"""Why the batch failed."""
112+
failure: Optional[Failure] = None
113+
"""
114+
A failure of the batch as a whole, distinct from the per-page failures in
115+
`page_errors`.
116+
"""
110117

111-
errors: List[ErrorCount]
112-
"""Page failures grouped by error code."""
118+
format: Literal["markdown", "html"]
119+
"""What each page is returned as.
113120
114-
input: Input
115-
"""Submission counts."""
121+
Matches `input.data.format` on the submit request.
122+
"""
123+
124+
input: Intake
125+
"""What submission took in, and what it charged for."""
116126

117127
mode: Literal["scrape", "crawl"]
118-
"""How pages are selected."""
128+
"""How pages were selected. Matches `input.mode` on the submit request."""
129+
130+
page_errors: List[PageErrorCount]
131+
"""Individual page failures grouped by error code, sorted by count.
132+
133+
Unrelated to `failure`, which is the batch itself failing.
134+
"""
119135

120136
progress: Progress
121-
"""Current processing counts. Use `status` to check completion."""
137+
"""Pages attempted so far. Use `status` to check completion."""
122138

123139
results: Optional[Results] = None
124-
"""Download links available when the batch finishes.
125-
126-
GET /batch/{batch_id}/results serves the same records as paginated JSON.
140+
"""
141+
Download links, available once the batch reaches a final status and null before
142+
then. GET /batch/{batch_id}/results serves the same records as paginated JSON.
127143
"""
128144

129145
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"]
@@ -134,8 +150,5 @@ class BatchCancelResponse(BaseModel):
134150

135151
timing: Timing
136152

137-
type: Literal["markdown", "html"]
138-
"""Output format."""
139-
140153
key_metadata: Optional[KeyMetadata] = None
141154
"""API key usage for this request."""

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

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
from typing import List, Optional
44
from typing_extensions import Literal
55

6-
from .error import Error
6+
from .intake import Intake
7+
from .failure import Failure
78
from .._models import BaseModel
8-
from .error_count import ErrorCount
9+
from .crawl_controls import CrawlControls
10+
from .page_error_count import PageErrorCount
911

1012
__all__ = [
1113
"BatchListResponse",
1214
"Data",
1315
"DataCredits",
14-
"DataInput",
1516
"DataProgress",
1617
"DataResults",
1718
"DataResultsFile",
@@ -21,42 +22,39 @@
2122

2223

2324
class DataCredits(BaseModel):
24-
"""Reserved and used credits."""
25+
"""What this batch has done to your credit balance."""
2526

26-
charged: int
27-
"""Credits used by successful pages."""
27+
net: int
28+
"""`reserved` minus `refunded` — what the batch has cost so far.
2829
29-
estimated: int
30-
"""Credits reserved when the batch was accepted."""
31-
32-
33-
class DataInput(BaseModel):
34-
"""Submission counts."""
30+
Equal to `reserved` until the batch settles.
31+
"""
3532

36-
accepted: int
37-
"""Pages accepted, or the crawl page limit. Credits are reserved for this count."""
33+
refunded: int
34+
"""Credits returned for pages that did not succeed.
3835
39-
duplicates: int
40-
"""Duplicate URL and `itemId` pairs skipped. Always 0 for crawls."""
36+
Stays 0 until the batch reaches a final status, then settles in one movement.
37+
"""
4138

42-
invalid: int
43-
"""Pages rejected during validation."""
39+
reserved: int
40+
"""Credits debited from your balance the moment the batch was accepted.
4441
45-
submitted: int
46-
"""Pages submitted before validation. For a crawl, the page limit."""
42+
This is a charge, not a forecast — the whole amount leaves the balance up front.
43+
"""
4744

4845

4946
class DataProgress(BaseModel):
50-
"""Current processing counts. Use `status` to check completion."""
47+
"""Pages attempted so far. Use `status` to check completion."""
5148

5249
failed: int
5350
"""Pages that could not be scraped."""
5451

5552
pending: int
56-
"""Accepted pages not yet attempted.
53+
"""Reserved pages not yet attempted.
5754
58-
Always 0 once the batch completes; a crawl can finish under its page limit when
59-
the site has no more reachable pages.
55+
A cancelled batch keeps reporting the URLs it never reached; a crawl whose
56+
`input.reserved_is_ceiling` is true reports 0 once final, because its unspent
57+
budget was never real pages.
6058
"""
6159

6260
succeeded: int
@@ -75,9 +73,8 @@ class DataResultsFile(BaseModel):
7573

7674

7775
class DataResults(BaseModel):
78-
"""Download links available when the batch finishes.
79-
80-
GET /batch/{batch_id}/results serves the same records as paginated JSON.
76+
"""
77+
Download links, available once the batch reaches a final status and null before then. GET /batch/{batch_id}/results serves the same records as paginated JSON.
8178
"""
8279

8380
expires_at: str
@@ -104,28 +101,46 @@ class Data(BaseModel):
104101
id: str
105102
"""Batch ID used to retrieve or cancel the job."""
106103

104+
crawl: Optional[CrawlControls] = None
105+
"""
106+
The crawl controls as submitted, so the limits requested can be compared against
107+
what the crawl reached.
108+
"""
109+
107110
credits: DataCredits
108-
"""Reserved and used credits."""
111+
"""What this batch has done to your credit balance."""
109112

110-
error: Optional[Error] = None
111-
"""Why the batch failed."""
113+
failure: Optional[Failure] = None
114+
"""
115+
A failure of the batch as a whole, distinct from the per-page failures in
116+
`page_errors`.
117+
"""
112118

113-
errors: List[ErrorCount]
114-
"""Page failures grouped by error code."""
119+
format: Literal["markdown", "html"]
120+
"""What each page is returned as.
115121
116-
input: DataInput
117-
"""Submission counts."""
122+
Matches `input.data.format` on the submit request.
123+
"""
124+
125+
input: Intake
126+
"""What submission took in, and what it charged for."""
118127

119128
mode: Literal["scrape", "crawl"]
120-
"""How pages are selected."""
129+
"""How pages were selected. Matches `input.mode` on the submit request."""
130+
131+
page_errors: List[PageErrorCount]
132+
"""Individual page failures grouped by error code, sorted by count.
133+
134+
Unrelated to `failure`, which is the batch itself failing.
135+
"""
121136

122137
progress: DataProgress
123-
"""Current processing counts. Use `status` to check completion."""
138+
"""Pages attempted so far. Use `status` to check completion."""
124139

125140
results: Optional[DataResults] = None
126-
"""Download links available when the batch finishes.
127-
128-
GET /batch/{batch_id}/results serves the same records as paginated JSON.
141+
"""
142+
Download links, available once the batch reaches a final status and null before
143+
then. GET /batch/{batch_id}/results serves the same records as paginated JSON.
129144
"""
130145

131146
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"]
@@ -136,9 +151,6 @@ class Data(BaseModel):
136151

137152
timing: DataTiming
138153

139-
type: Literal["markdown", "html"]
140-
"""Output format."""
141-
142154

143155
class KeyMetadata(BaseModel):
144156
"""Metadata about the API key used for the request.

0 commit comments

Comments
 (0)