Assets API reference
Upload images and files to Content Lake, and link Media Library assets to your dataset.
Use the Assets API to upload and manage assets in your Content Lake datasets. For assets stored in Media Library, use the Media Library API.
Authentication
- All requests must be authenticated.
Base API server URL
Assets API base URL
https://{projectId}.api.sanity.io/{apiVersion}/assetsVariables
- apiVersionstringdefault:
"v2024-06-24"API version
- projectIdstringdefault:
"your-project-id"Sanity project ID
Endpoints
Upload an image asset
/images/{dataset}Upload an image asset to Content Lake.
This uploads an image and creates a linked sanity.imageAsset document containing the image metadata.
Path parameters
Query parameters
- filenamestring
Filename for this file (optional)
- titlestring
Optional title for the asset
- descriptionstring
Optional description for the asset
Array of metadata to extract from asset
items
- itemsstring
- labelstring
Optional freeform label for the asset.
- tagstring
Optional request tag for the upload. Learn more in the request tag documentation.
- creditLinestring
The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published.
- sourceNamestring
The name of the source if asset is from an external service.
- sourceIdstring
Use with sourceName. The id of the asset within the external source.
- sourceUrlstring
Use with sourceName. The url of the asset within the external source.
Request body image/*
- string (binary)
The image file to upload.
Responses
Upload successful
- documentobject
Show child attributes
- _idstring
- _typestringExample:
sanity.imageAsset - _revstring
- _createdAtstring (date-time)
- _updatedAtstring (date-time)
- urlstring (uri)
The CDN URL of the asset
Example:https://cdn.sanity.io/images/myproject/mydataset/image-1234567890-500x400.jpg - pathstring
- sizenumber
Size of the asset in bytes.
Example:202546 - mimeTypestring
MIME type of the asset.
Example:image/jpeg - assetIdstring
- extensionstringExample:
jpg - originalFilenamestringExample:
my-image.jpg - sha1hashstringExample:
cd6b7eaf68c33e65ee6866873b9c0e48be84bb01 - metadataobject
Metadata extracted from the asset. Learn more in the metadata documentation.
Show child attributes
- _typestringExample:
sanity.imageMetadata - dimensionsobject
Show child attributes
- _typestringExample:
sanity.imageDimensions - widthnumberExample:
500 - heightnumberExample:
400 - aspectRationumberExample:
1.25
Upload a file asset
/files/{dataset}Upload an file asset to Content Lake.
This uploads an file and creates a linked sanity.fileAsset document containing the file metadata.
Path parameters
Query parameters
- filenamestring
Filename for this file (optional)
- titlestring
Optional title for the asset
- descriptionstring
Optional description for the asset
- labelstring
Optional freeform label for the asset.
- tagstring
Optional request tag for the upload. Learn more in the request tag documentation.
- creditLinestring
The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published.
- sourceNamestring
The name of the source if asset is from an external service.
- sourceIdstring
Use with sourceName. The id of the asset within the external source.
- sourceUrlstring
Use with sourceName. The url of the asset within the external source.
Request body image/*
- string (binary)
The file binary to upload.
Responses
Upload successful
- documentobject
Show child attributes
- _idstring
- _typestringExample:
sanity.fileAsset - _revstring
- _createdAtstring (date-time)
- _updatedAtstring (date-time)
- urlstring (uri)Example:
https://cdn.sanity.io/files/myproject/mydataset/openAPISpec.yaml - pathstring
- sizenumber
Size of the asset in bytes.
Example:202546 - mimeTypestring
MIME type of the asset.
Example:image/jpeg - assetIdstring
- extensionstringExample:
jpg - originalFilenamestringExample:
my-image.jpg - sha1hashstringExample:
cd6b7eaf68c33e65ee6866873b9c0e48be84bb01
Upload an image asset from a URL
/images/{dataset}/from-urlUpload an image asset from a public or preauthorized HTTPS URL and create a sanity.imageAsset document in Content Lake.
Sanity fetches the source without forwarding your API token, cookies, or request headers. The source and each redirect destination must use HTTPS without embedded credentials and pass the source policy. Up to three redirects are followed. The source is limited to 50 MiB (52,428,800 bytes), and fetching may take up to 300 seconds. The JSON request body is limited to 4 KiB.
Provide filename in the JSON body; the filename query parameter is not accepted. The other upload metadata parameters work as on the ordinary upload endpoint. Provide sourceName and sourceId together; sourceUrl is attribution metadata, not the URL to fetch.
Allow more than 300 seconds for the client request. If the connection closes or the request times out, check the dataset before retrying: the asset may already have been created. Use the returned document._id as the asset reference in an image or file field.
Path parameters
Query parameters
- titlestring
Optional title for the asset
- descriptionstring
Optional description for the asset
Image metadata to extract. Repeat the parameter for multiple values, such as meta=palette&meta=lqip.
items
- itemsstring
- labelstring
Optional freeform label for the asset.
- tagstring
Optional request tag for the upload. Learn more in the request tag documentation.
- creditLinestring
The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published.
- sourceNamestring
The name of the source if asset is from an external service.
- sourceIdstring
Use with sourceName. The id of the asset within the external source.
- sourceUrlstring
Use with sourceName. The url of the asset within the external source.
Request body application/json
Public or preauthorized HTTPS URL returning the asset bytes. URLs with embedded usernames or passwords are not supported.
- filenamestring
Optional original filename, including the extension. Must not contain path separators or a null character.
application/json{
"url": "https://example.com/chair.jpg",
"filename": "chair.jpg"
}Responses
Upload successful
- documentobject
Show child attributes
- _idstring
- _typestringExample:
sanity.imageAsset - _revstring
- _createdAtstring (date-time)
- _updatedAtstring (date-time)
- urlstring (uri)
The CDN URL of the asset
Example:https://cdn.sanity.io/images/myproject/mydataset/image-1234567890-500x400.jpg - pathstring
- sizenumber
Size of the asset in bytes.
Example:202546 - mimeTypestring
MIME type of the asset.
Example:image/jpeg - assetIdstring
- extensionstringExample:
jpg - originalFilenamestringExample:
my-image.jpg - sha1hashstringExample:
cd6b7eaf68c33e65ee6866873b9c0e48be84bb01 - metadataobject
Metadata extracted from the asset. Learn more in the metadata documentation.
Show child attributes
- _typestringExample:
sanity.imageMetadata - dimensionsobject
Show child attributes
- _typestringExample:
sanity.imageDimensions - widthnumberExample:
500 - heightnumberExample:
400 - aspectRationumberExample:
1.25
Upload a file asset from a URL
/files/{dataset}/from-urlUpload a file asset from a public or preauthorized HTTPS URL and create a sanity.fileAsset document in Content Lake.
Sanity fetches the source without forwarding your API token, cookies, or request headers. The source and each redirect destination must use HTTPS without embedded credentials and pass the source policy. Up to three redirects are followed. The source is limited to 50 MiB (52,428,800 bytes), and fetching may take up to 300 seconds. The JSON request body is limited to 4 KiB.
Provide filename in the JSON body; the filename query parameter is not accepted. The other upload metadata parameters work as on the ordinary upload endpoint. Provide sourceName and sourceId together; sourceUrl is attribution metadata, not the URL to fetch.
Allow more than 300 seconds for the client request. If the connection closes or the request times out, check the dataset before retrying: the asset may already have been created. Use the returned document._id as the asset reference in an image or file field.
Path parameters
Query parameters
- titlestring
Optional title for the asset
- descriptionstring
Optional description for the asset
- labelstring
Optional freeform label for the asset.
- tagstring
Optional request tag for the upload. Learn more in the request tag documentation.
- creditLinestring
The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published.
- sourceNamestring
The name of the source if asset is from an external service.
- sourceIdstring
Use with sourceName. The id of the asset within the external source.
- sourceUrlstring
Use with sourceName. The url of the asset within the external source.
Request body application/json
Public or preauthorized HTTPS URL returning the asset bytes. URLs with embedded usernames or passwords are not supported.
- filenamestring
Optional original filename, including the extension. Must not contain path separators or a null character.
application/json{
"url": "https://example.com/manual.pdf",
"filename": "manual.pdf"
}Responses
Upload successful
- documentobject
Show child attributes
- _idstring
- _typestringExample:
sanity.fileAsset - _revstring
- _createdAtstring (date-time)
- _updatedAtstring (date-time)
- urlstring (uri)Example:
https://cdn.sanity.io/files/myproject/mydataset/openAPISpec.yaml - pathstring
- sizenumber
Size of the asset in bytes.
Example:202546 - mimeTypestring
MIME type of the asset.
Example:image/jpeg - assetIdstring
- extensionstringExample:
jpg - originalFilenamestringExample:
my-image.jpg - sha1hashstringExample:
cd6b7eaf68c33e65ee6866873b9c0e48be84bb01
Link a Media Library asset to a document
/media-library-link/{dataset}Creates a linked Media Library asset in your dataset. To support features like preview, Media Library assets need to be linked to a local asset document. Pair with mutate to attach linked Media Library assets to documents.
Path parameters
Request body application/json
- assetIdstring
The asset ID of the Media Library asset. This comes from the
asset._idfield returned as part of the response when uploading an asset to the library. - mediaLibraryIdstring
The id of the Media Library.
- assetInstanceIdstring
The asset instance ID of the Media Library asset. This comes from the
assetInstance._idfield returned as part of the response when uploading an asset to the library.
Responses
Link created successfully