Skip to content

Commit e8af3f1

Browse files
committed
Merge remote-tracking branch 'origin/next' into sam/run-helper
2 parents ad4da10 + 0e4a103 commit e8af3f1

File tree

10 files changed

+217
-68
lines changed

10 files changed

+217
-68
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.1.0"
2+
".": "0.2.1"
33
}

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 35
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-efbc8cc2d74644b213e161d3e11e0589d1cef181fb318ea02c8eb6b00f245713.yml
3-
openapi_spec_hash: 13da0c06c900b61cd98ab678e024987a
4-
config_hash: 8ef6787524fd12bfeb27f8c6acef3dca
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-88cf5fe1f5accb56ae9fbb31c0df00d1552762d4c558d16d8547894ae95e8ccb.yml
3+
openapi_spec_hash: 43283d20f335a04241cce165452ff50e
4+
config_hash: 84794ed69d841684ff08a8aa889ef103

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Changelog
22

3+
## 0.2.1 (2025-05-07)
4+
5+
Full Changelog: [v0.2.0...v0.2.1](https://github.com/replicate/replicate-python-stainless/compare/v0.2.0...v0.2.1)
6+
7+
### Documentation
8+
9+
* update example requests ([eb0ba44](https://github.com/replicate/replicate-python-stainless/commit/eb0ba44af5b5006e758c9d9e65312f88b52dc3f5))
10+
11+
## 0.2.0 (2025-05-07)
12+
13+
Full Changelog: [v0.1.0...v0.2.0](https://github.com/replicate/replicate-python-stainless/compare/v0.1.0...v0.2.0)
14+
15+
### Features
16+
17+
* **api:** add Files API methods ([3173e5f](https://github.com/replicate/replicate-python-stainless/commit/3173e5f61edd89ffe0b64b53fc8e8e9905e145e4))
18+
* **api:** fix bearer token which also regressed when guessing with AI ([13162be](https://github.com/replicate/replicate-python-stainless/commit/13162be9d367de29d222b86506fa921a10800665))
19+
20+
21+
### Bug Fixes
22+
23+
* **api:** fix client_settings.opts.api_key.read_env ([5a9b95c](https://github.com/replicate/replicate-python-stainless/commit/5a9b95ce89e536b539eefe0864a47784fdb0ec08))
24+
325
## 0.1.0 (2025-05-07)
426

527
Full Changelog: [v0.1.0-alpha.10...v0.1.0](https://github.com/replicate/replicate-python-stainless/compare/v0.1.0-alpha.10...v0.1.0)

README.md

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ client = Replicate(
3131
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
3232
)
3333

34-
account = client.account.get()
35-
print(account.type)
34+
prediction = client.predictions.get(
35+
prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
36+
)
37+
print(prediction.id)
3638
```
3739

3840
While you can provide a `bearer_token` keyword argument,
@@ -55,8 +57,10 @@ client = AsyncReplicate(
5557

5658

5759
async def main() -> None:
58-
account = await client.account.get()
59-
print(account.type)
60+
prediction = await client.predictions.get(
61+
prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
62+
)
63+
print(prediction.id)
6064

6165

6266
asyncio.run(main())
@@ -84,12 +88,12 @@ from replicate import Replicate
8488

8589
client = Replicate()
8690

87-
all_predictions = []
91+
all_models = []
8892
# Automatically fetches more pages as needed.
89-
for prediction in client.predictions.list():
90-
# Do something with prediction here
91-
all_predictions.append(prediction)
92-
print(all_predictions)
93+
for model in client.models.list():
94+
# Do something with model here
95+
all_models.append(model)
96+
print(all_models)
9397
```
9498

9599
Or, asynchronously:
@@ -102,11 +106,11 @@ client = AsyncReplicate()
102106

103107

104108
async def main() -> None:
105-
all_predictions = []
109+
all_models = []
106110
# Iterate through items across all pages, issuing requests as needed.
107-
async for prediction in client.predictions.list():
108-
all_predictions.append(prediction)
109-
print(all_predictions)
111+
async for model in client.models.list():
112+
all_models.append(model)
113+
print(all_models)
110114

111115

112116
asyncio.run(main())
@@ -115,7 +119,7 @@ asyncio.run(main())
115119
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
116120

117121
```python
118-
first_page = await client.predictions.list()
122+
first_page = await client.models.list()
119123
if first_page.has_next_page():
120124
print(f"will fetch next page using these details: {first_page.next_page_info()}")
121125
next_page = await first_page.get_next_page()
@@ -127,11 +131,11 @@ if first_page.has_next_page():
127131
Or just work directly with the returned data:
128132

129133
```python
130-
first_page = await client.predictions.list()
134+
first_page = await client.models.list()
131135

132136
print(f"next URL: {first_page.next}") # => "next URL: ..."
133-
for prediction in first_page.results:
134-
print(prediction.id)
137+
for model in first_page.results:
138+
print(model.cover_image_url)
135139

136140
# Remove `await` for non-async usage.
137141
```
@@ -170,7 +174,10 @@ from replicate import Replicate
170174
client = Replicate()
171175

172176
try:
173-
client.account.get()
177+
client.predictions.create(
178+
input={"text": "Alice"},
179+
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
180+
)
174181
except replicate.APIConnectionError as e:
175182
print("The server could not be reached")
176183
print(e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -213,7 +220,10 @@ client = Replicate(
213220
)
214221

215222
# Or, configure per-request:
216-
client.with_options(max_retries=5).account.get()
223+
client.with_options(max_retries=5).predictions.create(
224+
input={"text": "Alice"},
225+
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
226+
)
217227
```
218228

219229
### Timeouts
@@ -236,7 +246,10 @@ client = Replicate(
236246
)
237247

238248
# Override per-request:
239-
client.with_options(timeout=5.0).account.get()
249+
client.with_options(timeout=5.0).predictions.create(
250+
input={"text": "Alice"},
251+
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
252+
)
240253
```
241254

242255
On timeout, an `APITimeoutError` is thrown.
@@ -277,11 +290,16 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
277290
from replicate import Replicate
278291

279292
client = Replicate()
280-
response = client.account.with_raw_response.get()
293+
response = client.predictions.with_raw_response.create(
294+
input={
295+
"text": "Alice"
296+
},
297+
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
298+
)
281299
print(response.headers.get('X-My-Header'))
282300

283-
account = response.parse() # get the object that `account.get()` would have returned
284-
print(account.type)
301+
prediction = response.parse() # get the object that `predictions.create()` would have returned
302+
print(prediction.id)
285303
```
286304

287305
These methods return an [`APIResponse`](https://github.com/replicate/replicate-python-stainless/tree/main/src/replicate/_response.py) object.
@@ -295,7 +313,10 @@ The above interface eagerly reads the full response body when you make the reque
295313
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
296314

297315
```python
298-
with client.account.with_streaming_response.get() as response:
316+
with client.predictions.with_streaming_response.create(
317+
input={"text": "Alice"},
318+
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
319+
) as response:
299320
print(response.headers.get("X-My-Header"))
300321

301322
for line in response.iter_lines():

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Methods:
116116

117117
- <code title="post /predictions">client.predictions.<a href="./src/replicate/resources/predictions.py">create</a>(\*\*<a href="src/replicate/types/prediction_create_params.py">params</a>) -> <a href="./src/replicate/types/prediction.py">Prediction</a></code>
118118
- <code title="get /predictions">client.predictions.<a href="./src/replicate/resources/predictions.py">list</a>(\*\*<a href="src/replicate/types/prediction_list_params.py">params</a>) -> <a href="./src/replicate/types/prediction.py">SyncCursorURLPageWithCreatedFilters[Prediction]</a></code>
119-
- <code title="post /predictions/{prediction_id}/cancel">client.predictions.<a href="./src/replicate/resources/predictions.py">cancel</a>(\*, prediction_id) -> None</code>
119+
- <code title="post /predictions/{prediction_id}/cancel">client.predictions.<a href="./src/replicate/resources/predictions.py">cancel</a>(\*, prediction_id) -> <a href="./src/replicate/types/prediction.py">Prediction</a></code>
120120
- <code title="get /predictions/{prediction_id}">client.predictions.<a href="./src/replicate/resources/predictions.py">get</a>(\*, prediction_id) -> <a href="./src/replicate/types/prediction.py">Prediction</a></code>
121121

122122
# Trainings

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "replicate-stainless"
3-
version = "0.1.0"
3+
version = "0.2.1"
44
description = "The official Python library for the replicate API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/replicate/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "replicate"
4-
__version__ = "0.1.0" # x-release-please-version
4+
__version__ = "0.2.1" # x-release-please-version

src/replicate/resources/predictions.py

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from replicate.lib._files import FileEncodingStrategy, encode_json, async_encode_json
1212

1313
from ..types import prediction_list_params, prediction_create_params
14-
from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
14+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
1515
from .._utils import maybe_transform, strip_not_given, async_maybe_transform
1616
from .._compat import cached_property
1717
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -330,9 +330,32 @@ def cancel(
330330
extra_query: Query | None = None,
331331
extra_body: Body | None = None,
332332
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
333-
) -> None:
333+
) -> Prediction:
334334
"""
335-
Cancel a prediction
335+
Cancel a prediction that is currently running.
336+
337+
Example cURL request that creates a prediction and then cancels it:
338+
339+
```console
340+
# First, create a prediction
341+
PREDICTION_ID=$(curl -s -X POST \\
342+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
343+
-H "Content-Type: application/json" \\
344+
-d '{
345+
"input": {
346+
"prompt": "a video that may take a while to generate"
347+
}
348+
}' \\
349+
https://api.replicate.com/v1/models/minimax/video-01/predictions | jq -r '.id')
350+
351+
# Echo the prediction ID
352+
echo "Created prediction with ID: $PREDICTION_ID"
353+
354+
# Cancel the prediction
355+
curl -s -X POST \\
356+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
357+
https://api.replicate.com/v1/predictions/$PREDICTION_ID/cancel
358+
```
336359
337360
Args:
338361
extra_headers: Send extra headers
@@ -345,13 +368,12 @@ def cancel(
345368
"""
346369
if not prediction_id:
347370
raise ValueError(f"Expected a non-empty value for `prediction_id` but received {prediction_id!r}")
348-
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
349371
return self._post(
350372
f"/predictions/{prediction_id}/cancel",
351373
options=make_request_options(
352374
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
353375
),
354-
cast_to=NoneType,
376+
cast_to=Prediction,
355377
)
356378

357379
def get(
@@ -759,9 +781,32 @@ async def cancel(
759781
extra_query: Query | None = None,
760782
extra_body: Body | None = None,
761783
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
762-
) -> None:
784+
) -> Prediction:
763785
"""
764-
Cancel a prediction
786+
Cancel a prediction that is currently running.
787+
788+
Example cURL request that creates a prediction and then cancels it:
789+
790+
```console
791+
# First, create a prediction
792+
PREDICTION_ID=$(curl -s -X POST \\
793+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
794+
-H "Content-Type: application/json" \\
795+
-d '{
796+
"input": {
797+
"prompt": "a video that may take a while to generate"
798+
}
799+
}' \\
800+
https://api.replicate.com/v1/models/minimax/video-01/predictions | jq -r '.id')
801+
802+
# Echo the prediction ID
803+
echo "Created prediction with ID: $PREDICTION_ID"
804+
805+
# Cancel the prediction
806+
curl -s -X POST \\
807+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
808+
https://api.replicate.com/v1/predictions/$PREDICTION_ID/cancel
809+
```
765810
766811
Args:
767812
extra_headers: Send extra headers
@@ -774,13 +819,12 @@ async def cancel(
774819
"""
775820
if not prediction_id:
776821
raise ValueError(f"Expected a non-empty value for `prediction_id` but received {prediction_id!r}")
777-
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
778822
return await self._post(
779823
f"/predictions/{prediction_id}/cancel",
780824
options=make_request_options(
781825
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
782826
),
783-
cast_to=NoneType,
827+
cast_to=Prediction,
784828
)
785829

786830
async def get(

tests/api_resources/test_predictions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_method_cancel(self, client: Replicate) -> None:
112112
prediction = client.predictions.cancel(
113113
prediction_id="prediction_id",
114114
)
115-
assert prediction is None
115+
assert_matches_type(Prediction, prediction, path=["response"])
116116

117117
@pytest.mark.skip()
118118
@parametrize
@@ -124,7 +124,7 @@ def test_raw_response_cancel(self, client: Replicate) -> None:
124124
assert response.is_closed is True
125125
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
126126
prediction = response.parse()
127-
assert prediction is None
127+
assert_matches_type(Prediction, prediction, path=["response"])
128128

129129
@pytest.mark.skip()
130130
@parametrize
@@ -136,7 +136,7 @@ def test_streaming_response_cancel(self, client: Replicate) -> None:
136136
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
137137

138138
prediction = response.parse()
139-
assert prediction is None
139+
assert_matches_type(Prediction, prediction, path=["response"])
140140

141141
assert cast(Any, response.is_closed) is True
142142

@@ -287,7 +287,7 @@ async def test_method_cancel(self, async_client: AsyncReplicate) -> None:
287287
prediction = await async_client.predictions.cancel(
288288
prediction_id="prediction_id",
289289
)
290-
assert prediction is None
290+
assert_matches_type(Prediction, prediction, path=["response"])
291291

292292
@pytest.mark.skip()
293293
@parametrize
@@ -299,7 +299,7 @@ async def test_raw_response_cancel(self, async_client: AsyncReplicate) -> None:
299299
assert response.is_closed is True
300300
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
301301
prediction = await response.parse()
302-
assert prediction is None
302+
assert_matches_type(Prediction, prediction, path=["response"])
303303

304304
@pytest.mark.skip()
305305
@parametrize
@@ -311,7 +311,7 @@ async def test_streaming_response_cancel(self, async_client: AsyncReplicate) ->
311311
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
312312

313313
prediction = await response.parse()
314-
assert prediction is None
314+
assert_matches_type(Prediction, prediction, path=["response"])
315315

316316
assert cast(Any, response.is_closed) is True
317317

0 commit comments

Comments
 (0)