Skip to content

Commit 0784f70

Browse files
feat(api): api update
1 parent aca74e7 commit 0784f70

6 files changed

Lines changed: 62 additions & 7 deletions

File tree

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 22
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-44904c513baa439f294b23964ea368ad52863e13328980f9cac5a8e78cbb58cb.yml
3-
openapi_spec_hash: 9bb50ca838166fb474d28009a7edbd49
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d880c25aee159e1260e23dfa3685b1bb9e35b02a1927adecbff32664ba8e11a4.yml
3+
openapi_spec_hash: aa96a6030390bca0b4cdfa2363961807
44
config_hash: 70354330f92ce169beabc98696ebb9a3

‎README.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ from context.dev import ContextDev
130130

131131
client = ContextDev()
132132

133-
response = client.web.web_scrape_images(
134-
url="https://example.com",
135-
enrichment={},
133+
response = client.web.screenshot(
134+
viewport={},
136135
)
137-
print(response.enrichment)
136+
print(response.viewport)
138137
```
139138

140139
## Handling errors

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ def screenshot(
180180
direct_url: str | Omit = omit,
181181
domain: str | Omit = omit,
182182
full_screenshot: Literal["true", "false"] | Omit = omit,
183+
max_age_ms: int | Omit = omit,
183184
page: Literal["login", "signup", "blog", "careers", "pricing", "terms", "privacy", "contact"] | Omit = omit,
184185
prioritize: Literal["speed", "quality"] | Omit = omit,
186+
viewport: web_screenshot_params.Viewport | Omit = omit,
185187
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
186188
# The extra values given here take precedence over values defined on the client or passed to this method.
187189
extra_headers: Headers | None = None,
@@ -205,6 +207,10 @@ def screenshot(
205207
screenshot capturing all content. If 'false' or not provided, takes a viewport
206208
screenshot (standard browser view).
207209
210+
max_age_ms: Return a cached screenshot if a prior screenshot for the same parameters exists
211+
and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
212+
omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
213+
208214
page: Optional parameter to specify which page type to screenshot. If provided, the
209215
system will scrape the domain's links and use heuristics to find the most
210216
appropriate URL for the specified page type (30 supported languages). If not
@@ -215,6 +221,8 @@ def screenshot(
215221
faster capture with basic quality. If 'quality', optimizes for higher quality
216222
with longer wait times. Defaults to 'quality' if not provided.
217223
224+
viewport: Optional browser viewport dimensions for the screenshot. Defaults to 1920x1080.
225+
218226
extra_headers: Send extra headers
219227
220228
extra_query: Add additional query parameters to the request
@@ -235,8 +243,10 @@ def screenshot(
235243
"direct_url": direct_url,
236244
"domain": domain,
237245
"full_screenshot": full_screenshot,
246+
"max_age_ms": max_age_ms,
238247
"page": page,
239248
"prioritize": prioritize,
249+
"viewport": viewport,
240250
},
241251
web_screenshot_params.WebScreenshotParams,
242252
),
@@ -719,8 +729,10 @@ async def screenshot(
719729
direct_url: str | Omit = omit,
720730
domain: str | Omit = omit,
721731
full_screenshot: Literal["true", "false"] | Omit = omit,
732+
max_age_ms: int | Omit = omit,
722733
page: Literal["login", "signup", "blog", "careers", "pricing", "terms", "privacy", "contact"] | Omit = omit,
723734
prioritize: Literal["speed", "quality"] | Omit = omit,
735+
viewport: web_screenshot_params.Viewport | Omit = omit,
724736
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
725737
# The extra values given here take precedence over values defined on the client or passed to this method.
726738
extra_headers: Headers | None = None,
@@ -744,6 +756,10 @@ async def screenshot(
744756
screenshot capturing all content. If 'false' or not provided, takes a viewport
745757
screenshot (standard browser view).
746758
759+
max_age_ms: Return a cached screenshot if a prior screenshot for the same parameters exists
760+
and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
761+
omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
762+
747763
page: Optional parameter to specify which page type to screenshot. If provided, the
748764
system will scrape the domain's links and use heuristics to find the most
749765
appropriate URL for the specified page type (30 supported languages). If not
@@ -754,6 +770,8 @@ async def screenshot(
754770
faster capture with basic quality. If 'quality', optimizes for higher quality
755771
with longer wait times. Defaults to 'quality' if not provided.
756772
773+
viewport: Optional browser viewport dimensions for the screenshot. Defaults to 1920x1080.
774+
757775
extra_headers: Send extra headers
758776
759777
extra_query: Add additional query parameters to the request
@@ -774,8 +792,10 @@ async def screenshot(
774792
"direct_url": direct_url,
775793
"domain": domain,
776794
"full_screenshot": full_screenshot,
795+
"max_age_ms": max_age_ms,
777796
"page": page,
778797
"prioritize": prioritize,
798+
"viewport": viewport,
779799
},
780800
web_screenshot_params.WebScreenshotParams,
781801
),

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .._utils import PropertyInfo
88

9-
__all__ = ["WebScreenshotParams"]
9+
__all__ = ["WebScreenshotParams", "Viewport"]
1010

1111

1212
class WebScreenshotParams(TypedDict, total=False):
@@ -31,6 +31,13 @@ class WebScreenshotParams(TypedDict, total=False):
3131
provided, takes a viewport screenshot (standard browser view).
3232
"""
3333

34+
max_age_ms: Annotated[int, PropertyInfo(alias="maxAgeMs")]
35+
"""
36+
Return a cached screenshot if a prior screenshot for the same parameters exists
37+
and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
38+
omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
39+
"""
40+
3441
page: Literal["login", "signup", "blog", "careers", "pricing", "terms", "privacy", "contact"]
3542
"""Optional parameter to specify which page type to screenshot.
3643
@@ -47,3 +54,16 @@ class WebScreenshotParams(TypedDict, total=False):
4754
optimizes for higher quality with longer wait times. Defaults to 'quality' if
4855
not provided.
4956
"""
57+
58+
viewport: Viewport
59+
"""Optional browser viewport dimensions for the screenshot. Defaults to 1920x1080."""
60+
61+
62+
class Viewport(TypedDict, total=False):
63+
"""Optional browser viewport dimensions for the screenshot. Defaults to 1920x1080."""
64+
65+
height: int
66+
"""Viewport height in pixels."""
67+
68+
width: int
69+
"""Viewport width in pixels."""

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class WebScreenshotResponse(BaseModel):
1717
domain: Optional[str] = None
1818
"""The normalized domain that was processed"""
1919

20+
height: Optional[int] = None
21+
"""Height in pixels of the returned screenshot image"""
22+
2023
screenshot: Optional[str] = None
2124
"""Public URL of the uploaded screenshot image"""
2225

@@ -25,3 +28,6 @@ class WebScreenshotResponse(BaseModel):
2528

2629
status: Optional[str] = None
2730
"""Status of the response, e.g., 'ok'"""
31+
32+
width: Optional[int] = None
33+
"""Width in pixels of the returned screenshot image"""

‎tests/api_resources/test_web.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,13 @@ def test_method_screenshot_with_all_params(self, client: ContextDev) -> None:
115115
direct_url="https://example.com",
116116
domain="domain",
117117
full_screenshot="true",
118+
max_age_ms=0,
118119
page="login",
119120
prioritize="speed",
121+
viewport={
122+
"height": 240,
123+
"width": 240,
124+
},
120125
)
121126
assert_matches_type(WebScreenshotResponse, web, path=["response"])
122127

@@ -477,8 +482,13 @@ async def test_method_screenshot_with_all_params(self, async_client: AsyncContex
477482
direct_url="https://example.com",
478483
domain="domain",
479484
full_screenshot="true",
485+
max_age_ms=0,
480486
page="login",
481487
prioritize="speed",
488+
viewport={
489+
"height": 240,
490+
"width": 240,
491+
},
482492
)
483493
assert_matches_type(WebScreenshotResponse, web, path=["response"])
484494

0 commit comments

Comments
 (0)