Skip to main content

Assets

Overview

Assets are files that contain data that is too big to be sent as part of a request body or returned as part of a response. Examples include media types, such as images, videos, and audio, and binary data, such as model weights and serialized objects.

Assets are passed to and from the Snapper API via an asset id. Clients upload and download assets via signed URLs that they receive from the API.

The Snapper API is not a CDN, and should not be used as such. Instead, clients are expected to download their desired assets and re-host them on their own infrastructure. To enforce this, assets have a maximum number of signed URLs you can fetch. Once the maximum is reached, the asset is no longer accessible, and trying to fetch the asset will result in 404s.

Downloading an Asset

Downloading an asset is a two-step process. First, fetch a signed URL for the asset via a GET request to /assets/<asset_id>. Then, download the asset from the signed URL.

Download an asset
DOWNLOAD_URL=`curl <API_URL>/assets/<asset_id> -H 'Authorization: Bearer <YOUR_API_KEY>' | jq .download_url`
curl $DOWNLOAD_URL

Creating an Asset

Creating an asset is also two-step process. First, create the asset via a POST request to /assets, which will return a signed URL for uploading the asset. Then, upload the asset to the signed URL.

Create an asset
UPLOAD_URL=`curl -X POST <API_URL>/assets | jq .upload_url`
curl -X PUT $UPLOAD_URL --data-binary @<PATH_TO_ASSET>

API Reference

GET /assets/<asset_id>

Fetches a signed URL for downloading an asset.

Path Parameters

FieldTypeDescription
asset_idstringThe ID of the asset to fetch.

Response Object

FieldTypeDescription
download_urlstringA signed URL for downloading the asset.

POST /assets

Creates an asset and returns a signed URL for uploading the asset.

Request Body Object

None

Response Object

FieldTypeDescription
asset_idstringThe ID of the asset that was created.
upload_urlstringA signed URL for uploading the asset.