-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.py
More file actions
1296 lines (1065 loc) · 46.7 KB
/
models.py
File metadata and controls
1296 lines (1065 loc) · 46.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing_extensions import Literal
import httpx
from .readme import (
ReadmeResource,
AsyncReadmeResource,
ReadmeResourceWithRawResponse,
AsyncReadmeResourceWithRawResponse,
ReadmeResourceWithStreamingResponse,
AsyncReadmeResourceWithStreamingResponse,
)
from ...types import model_list_params, model_create_params, model_search_params, model_update_params
from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given
from ..._utils import maybe_transform, async_maybe_transform
from .examples import (
ExamplesResource,
AsyncExamplesResource,
ExamplesResourceWithRawResponse,
AsyncExamplesResourceWithRawResponse,
ExamplesResourceWithStreamingResponse,
AsyncExamplesResourceWithStreamingResponse,
)
from .versions import (
VersionsResource,
AsyncVersionsResource,
VersionsResourceWithRawResponse,
AsyncVersionsResourceWithRawResponse,
VersionsResourceWithStreamingResponse,
AsyncVersionsResourceWithStreamingResponse,
)
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from .predictions import (
PredictionsResource,
AsyncPredictionsResource,
PredictionsResourceWithRawResponse,
AsyncPredictionsResourceWithRawResponse,
PredictionsResourceWithStreamingResponse,
AsyncPredictionsResourceWithStreamingResponse,
)
from ...pagination import SyncCursorURLPage, AsyncCursorURLPage
from ..._base_client import AsyncPaginator, make_request_options
from ...types.model_get_response import ModelGetResponse
from ...types.model_list_response import ModelListResponse
from ...types.model_create_response import ModelCreateResponse
from ...types.model_search_response import ModelSearchResponse
from ...types.model_update_response import ModelUpdateResponse
__all__ = ["ModelsResource", "AsyncModelsResource"]
class ModelsResource(SyncAPIResource):
@cached_property
def examples(self) -> ExamplesResource:
return ExamplesResource(self._client)
@cached_property
def predictions(self) -> PredictionsResource:
return PredictionsResource(self._client)
@cached_property
def readme(self) -> ReadmeResource:
return ReadmeResource(self._client)
@cached_property
def versions(self) -> VersionsResource:
return VersionsResource(self._client)
@cached_property
def with_raw_response(self) -> ModelsResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/replicate/replicate-python-beta#accessing-raw-response-data-eg-headers
"""
return ModelsResourceWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> ModelsResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/replicate/replicate-python-beta#with_streaming_response
"""
return ModelsResourceWithStreamingResponse(self)
def create(
self,
*,
hardware: str,
name: str,
owner: str,
visibility: Literal["public", "private"],
cover_image_url: str | Omit = omit,
description: str | Omit = omit,
github_url: str | Omit = omit,
license_url: str | Omit = omit,
paper_url: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ModelCreateResponse:
"""
Create a model.
Example cURL request:
```console
curl -s -X POST \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
-H 'Content-Type: application/json' \\
-d '{"owner": "alice", "name": "hot-dog-detector", "description": "Detect hot dogs in images", "visibility": "public", "hardware": "cpu"}' \\
https://api.replicate.com/v1/models
```
The response will be a model object in the following format:
```json
{
"url": "https://replicate.com/alice/hot-dog-detector",
"owner": "alice",
"name": "hot-dog-detector",
"description": "Detect hot dogs in images",
"visibility": "public",
"github_url": null,
"paper_url": null,
"license_url": null,
"run_count": 0,
"cover_image_url": null,
"default_example": null,
"latest_version": null
}
```
Note that there is a limit of 1,000 models per account. For most purposes, we
recommend using a single model and pushing new
[versions](https://replicate.com/docs/how-does-replicate-work#versions) of the
model as you make changes to it.
Args:
hardware: The SKU for the hardware used to run the model. Possible values can be retrieved
from the `hardware.list` endpoint.
name: The name of the model. This must be unique among all models owned by the user or
organization.
owner: The name of the user or organization that will own the model. This must be the
same as the user or organization that is making the API request. In other words,
the API token used in the request must belong to this user or organization.
visibility: Whether the model should be public or private. A public model can be viewed and
run by anyone, whereas a private model can be viewed and run only by the user or
organization members that own the model.
cover_image_url: A URL for the model's cover image. This should be an image file.
description: A description of the model.
github_url: A URL for the model's source code on GitHub.
license_url: A URL for the model's license.
paper_url: A URL for the model's paper.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/models",
body=maybe_transform(
{
"hardware": hardware,
"name": name,
"owner": owner,
"visibility": visibility,
"cover_image_url": cover_image_url,
"description": description,
"github_url": github_url,
"license_url": license_url,
"paper_url": paper_url,
},
model_create_params.ModelCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=ModelCreateResponse,
)
def update(
self,
*,
model_owner: str,
model_name: str,
description: str | Omit = omit,
github_url: str | Omit = omit,
license_url: str | Omit = omit,
paper_url: str | Omit = omit,
readme: str | Omit = omit,
weights_url: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ModelUpdateResponse:
"""
Update select properties of an existing model.
You can update the following properties:
- `description` - Model description
- `readme` - Model README content
- `github_url` - GitHub repository URL
- `paper_url` - Research paper URL
- `weights_url` - Model weights URL
- `license_url` - License URL
Example cURL request:
```console
curl -X PATCH \\
https://api.replicate.com/v1/models/your-username/your-model-name \\
-H "Authorization: Token $REPLICATE_API_TOKEN" \\
-H "Content-Type: application/json" \\
-d '{
"description": "Detect hot dogs in images",
"readme": "# Hot Dog Detector\n\n🌭 Ketchup, mustard, and onions...",
"github_url": "https://github.com/alice/hot-dog-detector",
"paper_url": "https://arxiv.org/abs/2504.17639",
"weights_url": "https://huggingface.co/alice/hot-dog-detector",
"license_url": "https://choosealicense.com/licenses/mit/"
}'
```
The response will be the updated model object with all of its properties.
Args:
description: A description of the model.
github_url: A URL for the model's source code on GitHub.
license_url: A URL for the model's license.
paper_url: A URL for the model's paper.
readme: The README content of the model.
weights_url: A URL for the model's weights.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not model_owner:
raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}")
if not model_name:
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
return self._patch(
f"/models/{model_owner}/{model_name}",
body=maybe_transform(
{
"description": description,
"github_url": github_url,
"license_url": license_url,
"paper_url": paper_url,
"readme": readme,
"weights_url": weights_url,
},
model_update_params.ModelUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=ModelUpdateResponse,
)
def list(
self,
*,
sort_by: Literal["model_created_at", "latest_version_created_at"] | Omit = omit,
sort_direction: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncCursorURLPage[ModelListResponse]:
"""
Get a paginated list of public models.
Example cURL request:
```console
curl -s \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
https://api.replicate.com/v1/models
```
The response will be a pagination object containing a list of model objects.
See the [`models.get`](#models.get) docs for more details about the model
object.
## Sorting
You can sort the results using the `sort_by` and `sort_direction` query
parameters.
For example, to get the most recently created models:
```console
curl -s \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
"https://api.replicate.com/v1/models?sort_by=model_created_at&sort_direction=desc"
```
Available sorting options:
- `model_created_at`: Sort by when the model was first created
- `latest_version_created_at`: Sort by when the model's latest version was
created (default)
Sort direction can be `asc` (ascending) or `desc` (descending, default).
Args:
sort_by: Field to sort models by. Defaults to `latest_version_created_at`.
sort_direction: Sort direction. Defaults to `desc` (descending, newest first).
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/models",
page=SyncCursorURLPage[ModelListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"sort_by": sort_by,
"sort_direction": sort_direction,
},
model_list_params.ModelListParams,
),
),
model=ModelListResponse,
)
def delete(
self,
*,
model_owner: str,
model_name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> None:
"""
Delete a model
Model deletion has some restrictions:
- You can only delete models you own.
- You can only delete private models.
- You can only delete models that have no versions associated with them.
Currently you'll need to
[delete the model's versions](#models.versions.delete) before you can delete
the model itself.
Example cURL request:
```command
curl -s -X DELETE \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
https://api.replicate.com/v1/models/replicate/hello-world
```
The response will be an empty 204, indicating the model has been deleted.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not model_owner:
raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}")
if not model_name:
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return self._delete(
f"/models/{model_owner}/{model_name}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=NoneType,
)
def get(
self,
*,
model_owner: str,
model_name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ModelGetResponse:
"""
Example cURL request:
```console
curl -s \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
https://api.replicate.com/v1/models/replicate/hello-world
```
The response will be a model object in the following format:
```json
{
"url": "https://replicate.com/replicate/hello-world",
"owner": "replicate",
"name": "hello-world",
"description": "A tiny model that says hello",
"visibility": "public",
"github_url": "https://github.com/replicate/cog-examples",
"paper_url": null,
"license_url": null,
"run_count": 5681081,
"cover_image_url": "...",
"default_example": {...},
"latest_version": {...},
}
```
The model object includes the
[input and output schema](https://replicate.com/docs/reference/openapi#model-schemas)
for the latest version of the model.
Here's an example showing how to fetch the model with cURL and display its input
schema with [jq](https://stedolan.github.io/jq/):
```console
curl -s \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
https://api.replicate.com/v1/models/replicate/hello-world \\
| jq ".latest_version.openapi_schema.components.schemas.Input"
```
This will return the following JSON object:
```json
{
"type": "object",
"title": "Input",
"required": ["text"],
"properties": {
"text": {
"type": "string",
"title": "Text",
"x-order": 0,
"description": "Text to prefix with 'hello '"
}
}
}
```
The `cover_image_url` string is an HTTPS URL for an image file. This can be:
- An image uploaded by the model author.
- The output file of the example prediction, if the model author has not set a
cover image.
- The input file of the example prediction, if the model author has not set a
cover image and the example prediction has no output file.
- A generic fallback image.
The `default_example` object is a [prediction](#predictions.get) created with
this model.
The `latest_version` object is the model's most recently pushed
[version](#models.versions.get).
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not model_owner:
raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}")
if not model_name:
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
return self._get(
f"/models/{model_owner}/{model_name}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=ModelGetResponse,
)
def search(
self,
*,
body: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncCursorURLPage[ModelSearchResponse]:
"""
Get a list of public models matching a search query.
Example cURL request:
```console
curl -s -X QUERY \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
-H "Content-Type: text/plain" \\
-d "hello" \\
https://api.replicate.com/v1/models
```
The response will be a paginated JSON object containing an array of model
objects.
See the [`models.get`](#models.get) docs for more details about the model
object.
Args:
body: The search query
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/models",
page=SyncCursorURLPage[ModelSearchResponse],
body=maybe_transform(body, model_search_params.ModelSearchParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
model=ModelSearchResponse,
method="query",
)
class AsyncModelsResource(AsyncAPIResource):
@cached_property
def examples(self) -> AsyncExamplesResource:
return AsyncExamplesResource(self._client)
@cached_property
def predictions(self) -> AsyncPredictionsResource:
return AsyncPredictionsResource(self._client)
@cached_property
def readme(self) -> AsyncReadmeResource:
return AsyncReadmeResource(self._client)
@cached_property
def versions(self) -> AsyncVersionsResource:
return AsyncVersionsResource(self._client)
@cached_property
def with_raw_response(self) -> AsyncModelsResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/replicate/replicate-python-beta#accessing-raw-response-data-eg-headers
"""
return AsyncModelsResourceWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncModelsResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/replicate/replicate-python-beta#with_streaming_response
"""
return AsyncModelsResourceWithStreamingResponse(self)
async def create(
self,
*,
hardware: str,
name: str,
owner: str,
visibility: Literal["public", "private"],
cover_image_url: str | Omit = omit,
description: str | Omit = omit,
github_url: str | Omit = omit,
license_url: str | Omit = omit,
paper_url: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ModelCreateResponse:
"""
Create a model.
Example cURL request:
```console
curl -s -X POST \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
-H 'Content-Type: application/json' \\
-d '{"owner": "alice", "name": "hot-dog-detector", "description": "Detect hot dogs in images", "visibility": "public", "hardware": "cpu"}' \\
https://api.replicate.com/v1/models
```
The response will be a model object in the following format:
```json
{
"url": "https://replicate.com/alice/hot-dog-detector",
"owner": "alice",
"name": "hot-dog-detector",
"description": "Detect hot dogs in images",
"visibility": "public",
"github_url": null,
"paper_url": null,
"license_url": null,
"run_count": 0,
"cover_image_url": null,
"default_example": null,
"latest_version": null
}
```
Note that there is a limit of 1,000 models per account. For most purposes, we
recommend using a single model and pushing new
[versions](https://replicate.com/docs/how-does-replicate-work#versions) of the
model as you make changes to it.
Args:
hardware: The SKU for the hardware used to run the model. Possible values can be retrieved
from the `hardware.list` endpoint.
name: The name of the model. This must be unique among all models owned by the user or
organization.
owner: The name of the user or organization that will own the model. This must be the
same as the user or organization that is making the API request. In other words,
the API token used in the request must belong to this user or organization.
visibility: Whether the model should be public or private. A public model can be viewed and
run by anyone, whereas a private model can be viewed and run only by the user or
organization members that own the model.
cover_image_url: A URL for the model's cover image. This should be an image file.
description: A description of the model.
github_url: A URL for the model's source code on GitHub.
license_url: A URL for the model's license.
paper_url: A URL for the model's paper.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/models",
body=await async_maybe_transform(
{
"hardware": hardware,
"name": name,
"owner": owner,
"visibility": visibility,
"cover_image_url": cover_image_url,
"description": description,
"github_url": github_url,
"license_url": license_url,
"paper_url": paper_url,
},
model_create_params.ModelCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=ModelCreateResponse,
)
async def update(
self,
*,
model_owner: str,
model_name: str,
description: str | Omit = omit,
github_url: str | Omit = omit,
license_url: str | Omit = omit,
paper_url: str | Omit = omit,
readme: str | Omit = omit,
weights_url: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ModelUpdateResponse:
"""
Update select properties of an existing model.
You can update the following properties:
- `description` - Model description
- `readme` - Model README content
- `github_url` - GitHub repository URL
- `paper_url` - Research paper URL
- `weights_url` - Model weights URL
- `license_url` - License URL
Example cURL request:
```console
curl -X PATCH \\
https://api.replicate.com/v1/models/your-username/your-model-name \\
-H "Authorization: Token $REPLICATE_API_TOKEN" \\
-H "Content-Type: application/json" \\
-d '{
"description": "Detect hot dogs in images",
"readme": "# Hot Dog Detector\n\n🌭 Ketchup, mustard, and onions...",
"github_url": "https://github.com/alice/hot-dog-detector",
"paper_url": "https://arxiv.org/abs/2504.17639",
"weights_url": "https://huggingface.co/alice/hot-dog-detector",
"license_url": "https://choosealicense.com/licenses/mit/"
}'
```
The response will be the updated model object with all of its properties.
Args:
description: A description of the model.
github_url: A URL for the model's source code on GitHub.
license_url: A URL for the model's license.
paper_url: A URL for the model's paper.
readme: The README content of the model.
weights_url: A URL for the model's weights.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not model_owner:
raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}")
if not model_name:
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
return await self._patch(
f"/models/{model_owner}/{model_name}",
body=await async_maybe_transform(
{
"description": description,
"github_url": github_url,
"license_url": license_url,
"paper_url": paper_url,
"readme": readme,
"weights_url": weights_url,
},
model_update_params.ModelUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=ModelUpdateResponse,
)
def list(
self,
*,
sort_by: Literal["model_created_at", "latest_version_created_at"] | Omit = omit,
sort_direction: Literal["asc", "desc"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[ModelListResponse, AsyncCursorURLPage[ModelListResponse]]:
"""
Get a paginated list of public models.
Example cURL request:
```console
curl -s \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
https://api.replicate.com/v1/models
```
The response will be a pagination object containing a list of model objects.
See the [`models.get`](#models.get) docs for more details about the model
object.
## Sorting
You can sort the results using the `sort_by` and `sort_direction` query
parameters.
For example, to get the most recently created models:
```console
curl -s \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
"https://api.replicate.com/v1/models?sort_by=model_created_at&sort_direction=desc"
```
Available sorting options:
- `model_created_at`: Sort by when the model was first created
- `latest_version_created_at`: Sort by when the model's latest version was
created (default)
Sort direction can be `asc` (ascending) or `desc` (descending, default).
Args:
sort_by: Field to sort models by. Defaults to `latest_version_created_at`.
sort_direction: Sort direction. Defaults to `desc` (descending, newest first).
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/models",
page=AsyncCursorURLPage[ModelListResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"sort_by": sort_by,
"sort_direction": sort_direction,
},
model_list_params.ModelListParams,
),
),
model=ModelListResponse,
)
async def delete(
self,
*,
model_owner: str,
model_name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> None:
"""
Delete a model
Model deletion has some restrictions:
- You can only delete models you own.
- You can only delete private models.
- You can only delete models that have no versions associated with them.
Currently you'll need to
[delete the model's versions](#models.versions.delete) before you can delete
the model itself.
Example cURL request:
```command
curl -s -X DELETE \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
https://api.replicate.com/v1/models/replicate/hello-world
```
The response will be an empty 204, indicating the model has been deleted.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not model_owner:
raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}")
if not model_name:
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return await self._delete(
f"/models/{model_owner}/{model_name}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=NoneType,
)
async def get(
self,
*,
model_owner: str,
model_name: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> ModelGetResponse:
"""
Example cURL request:
```console
curl -s \\
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
https://api.replicate.com/v1/models/replicate/hello-world
```
The response will be a model object in the following format: