Skip to content

Conversation

@zeke
Copy link
Contributor

@zeke zeke commented Jan 14, 2025

This PR updates the Replicate integration to support running both versioned and unversioned models via API.

Versioned models

The vast majority of models on Replicate are versioned. Each time a model author publishes changes to the model, a new version is created with a new 64-character SHA identifier. You have to specify a model's version by ID when running them with the API.

Versioned models use the following HTTP API endpoint:

POST /v1/predictions

☝🏼 This endpoint expects a version in the body of the request.

See https://replicate.com/docs/reference/http#predictions.create

Unversioned models

Some models on Replicate like black-forest-labs/flux-schnell are unversioned. Replicate staff maintains these as evergreen models, improving their performance and fixing bugs while maintaining API compatibility, so users know they're always running the latest and greatest.

Unversioned models have their own HTTP API endpoint:

POST /v1/models/{owner}/{model}/predictions

See https://replicate.com/docs/reference/http#models.predictions.create

@zeke zeke mentioned this pull request Jan 14, 2025
1 task
@zeke
Copy link
Contributor Author

zeke commented Jan 14, 2025

Note I haven't tested this change. Please advise if you want me to add some automated tests!

Copy link
Contributor

@SBrandeis SBrandeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!! Thank you

Comment on lines +2529 to +2580
"84b1cb6a9d1039df7c10ffb2c90832009f4399964368f18f9b621da494d6c591": {
"url": "https://api.replicate.com/v1/predictions",
"init": {
"headers": {
"Content-Type": "application/json",
"Prefer": "wait"
},
"method": "POST",
"body": "{\"input\":{\"prompt\":\"black forest gateau cake spelling out the words FLUX SCHNELL, tasty, food photography, dynamic shot\"},\"version\":\"5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637\"}"
},
"response": {
"body": "{\"id\":\"a0fyn914thrj00cmd6e8cd6e14\",\"model\":\"bytedance/sdxl-lightning-4step\",\"version\":\"5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637\",\"input\":{\"prompt\":\"black forest gateau cake spelling out the words FLUX SCHNELL, tasty, food photography, dynamic shot\"},\"logs\":\"\",\"output\":[\"https://replicate.delivery/yhqm/f8ALqF3E4myiHqr66Gg765nEhsco4pvr32ABQvZX3fdFaUFUA/out-0.png\"],\"data_removed\":false,\"error\":null,\"status\":\"processing\",\"created_at\":\"2025-01-15T10:57:08.308Z\",\"urls\":{\"cancel\":\"https://api.replicate.com/v1/predictions/a0fyn914thrj00cmd6e8cd6e14/cancel\",\"get\":\"https://api.replicate.com/v1/predictions/a0fyn914thrj00cmd6e8cd6e14\",\"stream\":\"https://stream.replicate.com/v1/files/qoxq-pku5oelao43fx5g5ny4qbdm2qqyf5fqwp5yv26jpxcslw5ufwrtq\"}}",
"status": 201,
"statusText": "Created",
"headers": {
"alt-svc": "h3=\":443\"; ma=86400",
"cf-cache-status": "DYNAMIC",
"cf-ray": "902557da19120198-CDG",
"connection": "keep-alive",
"content-type": "application/json; charset=UTF-8",
"nel": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}",
"preference-applied": "wait=60",
"ratelimit-remaining": "599",
"ratelimit-reset": "1",
"report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=dJWB5mgkALTqjarim6D5LybEWWkOtTzyTu4kxPRj%2FzVGVi%2BAmI0GsIe47bjsScWSZIIfuSe0XRTCtS3%2FW00TqVqiOT%2BmtKxvY903AZFVatuU2qx5IfRi1wE41l%2BlKyRMkjqs\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
"server": "cloudflare",
"server-timing": "cfL4;desc=\"?proto=TCP&rtt=4793&min_rtt=3728&rtt_var=2159&sent=4&recv=5&lost=0&retrans=0&sent_bytes=2847&recv_bytes=1013&delivery_rate=776824&cwnd=251&unsent_bytes=0&cid=c3db321825f7d0a3&ts=1415&x=0\"",
"strict-transport-security": "max-age=15552000",
"vary": "Accept-Encoding"
}
}
},
"a3b664767cd6d4e44d76a7b3870730f789f02f3d05af00a26f4418c59c6b6cbc": {
"url": "https://replicate.delivery/yhqm/f8ALqF3E4myiHqr66Gg765nEhsco4pvr32ABQvZX3fdFaUFUA/out-0.png",
"init": {},
"response": {
"body": "",
"status": 200,
"statusText": "OK",
"headers": {
"accept-ranges": "bytes",
"access-control-allow-origin": "*",
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
"cache-control": "public,max-age=3600",
"cache-id": "PAR-31976c84",
"cache-status": "miss",
"content-type": "image/png",
"etag": "\"0e4e24383e70701c57477916dbc681de\"",
"last-modified": "Wed, 15 Jan 2025 10:57:09 GMT",
"server": "UploadServer"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated with:

VCR_MODE=cache pnpm run test

@SBrandeis SBrandeis changed the title support versioned and unversioned Replicate models [Inference] [3rd party] Support versioned and unversioned Replicate models Jan 15, 2025
@SBrandeis SBrandeis merged commit f440c77 into huggingface:main Jan 15, 2025
4 checks passed
aykutkardas pushed a commit to gokayfem/huggingface.js that referenced this pull request Jan 20, 2025
…odels (huggingface#1106)

This PR updates the Replicate integration to support running both
versioned and unversioned models via API.

### Versioned models

The vast majority of models on Replicate are
[versioned](https://replicate.com/docs/topics/models/versions). Each
time a model author publishes changes to the model, a new version is
created with a new 64-character SHA identifier. You have to specify a
model's version by ID when running them with the API.

Versioned models use the following HTTP API endpoint:

```
POST /v1/predictions
```

☝🏼 This endpoint expects a `version` in the body of the request.

See https://replicate.com/docs/reference/http#predictions.create

### Unversioned models

Some models on Replicate like
[black-forest-labs/flux-schnell](https://replicate.com/black-forest-labs/flux-schnell)
are _unversioned_. Replicate staff maintains these as evergreen models,
improving their performance and fixing bugs while maintaining API
compatibility, so users know they're always running the latest and
greatest.

Unversioned models have their own HTTP API endpoint:

```
POST /v1/models/{owner}/{model}/predictions
```

See https://replicate.com/docs/reference/http#models.predictions.create

---------

Co-authored-by: SBrandeis <simon@huggingface.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants