Media Library API reference
HTTP endpoints reference for the Media Library API
The Media Library API lets you programmatically interact with assets in your organization’s Media Library.
Authentication
- All requests to private data must be authenticated. Requests to public information, like public assets, are available without an authentication token.
- Manipulating documents requires read+write access permission for Media Library.
Base API server URL
Media Library API base URL
https://api.sanity.io/{apiVersion}Variables
- apiVersionstringdefault:
"v2025-02-19"API version
Media Library API with projectId subdomain base URL
https://{projectId}.api.sanity.io/{apiVersion}Variables
- projectIdstringdefault:
"your-project-id"Your Sanity project ID. This can be found in your project settings or in the URL when accessing your project in the Sanity management interface.
- apiVersionstringdefault:
"v2025-02-19"API version
Endpoints
Mutate media in the Media Library
/media-libraries/{libraryId}/mutateYou can use this endpoint to create, update, or delete documents in the Media Library. This uses the same mutation syntax as Content Lake's Mutation API.
Query media in the Media Library
/media-libraries/{libraryId}/queryUse GROQ to query the Media Library.
See the GROQ documentation for more information on writing GROQ queries.
Path parameters
Media library identifier
Example:my-media-library
Query parameters
Responses
OK
- querystring
The GROQ query and projection executed against the Media Library.
- resultstring|number|boolean|array|object|null
The result of the query. The type of the result depends on the query response.
For example, if the query returns a single document, the result will be an object. If it returns a list of documents, the result will be an array.
- syncTagsarray
A list of sync tags. Sync tags are used with the Live Content API to track document changes.
Show child attributes
items
- string
List references to an asset.
/media-libraries/{libraryId}/references/documents/{assetId}/toGet references to an asset document from other documents and datasets. At this time, this does not support draft or version documents.
Note: this endpoint is currently only available on version vX of the API.
Path parameters
Media library identifier
Example:my-media-libraryThe ID of the asset to get references for.
Query parameters
- cursorstring
A cursor to paginate through the results. The cursor is returned in the
nextCursorfield of the response.
Responses
OK
- referencesarray
Show child attributes
items
- sourceDocumentRefstring
The global document reference ID of the document that references the asset.
This is made up of the {resourceName}:{resourceId}.{dataset}:{documentId}.
Example:dataset:y3d2bw.production:document-id1234 - sourceFieldPathsarray
A list of field path locations in the document that reference the asset.
Example["mainImage.media._ref","body[4].media._ref"]Show child attributes
items
- string
- totalCountinteger
Total number of references found
- nextCursorstring
Cursor for paginating to next set of results
application/json{
"references": [
{
"sourceDocumentRef": "dataset:y856rro4.production:196167ef-8c0b-4d7c-ae18-71179e424c19",
"sourceFieldPaths": [
"mainImage.media._ref"
]
},
{
"sourceDocumentRef": "dataset:y856rro4.production:503cceed-a1b5-4552-9cc1-c6fddf28de59",
"sourceFieldPaths": [
"body[4].media._ref"
]
},
{
"sourceDocumentRef": "dataset:y856rro4.production:drafts.196167ef-8c0b-4d7c-ae18-71179e424c19",
"sourceFieldPaths": [
"gdrImage._ref",
"mainImage.media._ref"
]
}
],
"totalCount": 3,
"nextCursor": "gdr1:eyJucyI6Ink4NTZycm80LnByb2R1Y3Rpb24uS2RSS2c4Z0tJQVFhIiwiaWQiOiJkcmFmdHMuMTk2MTY3ZWYtOGMwYi00ZDdjLWFlMTgtNzExNzllNDI0YzE5In0"
}Upload an asset to the media library
/media-libraries/{libraryId}/uploadPath parameters
Media library identifier
Example:my-media-library
Query parameters
Type of asset being uploaded
Original filename
- titlestring
Asset title
- autoGenerateTitleboolean
Auto-generate title from filename
- assetIdstring
Specific asset ID for updates
- sessionIdstring
Upload session identifier
- cdnAccessPolicystring
CDN access policy
- sha1string
SHA1 hash for validation
Request body multipart/form-data
- filestring (binary)
The asset file to upload
Responses
Asset uploaded successfully
Show child attributes
Asset container ID
Document type
Type of asset
CDN access policy for the asset
- _revstring
- _createdAtstring (date-time)
- _updatedAtstring (date-time)
Asset instance with metadata
Upload session information
Search for assets and references
/media-libraries/{libraryId}/refsearchPath parameters
Media library identifier
Example:my-media-library
Query parameters
Search term
- filterstring
Search filter query
- projectionstring
Fields to return
Data perspective
- cursorstring
Pagination cursor
Results limit
Responses
Search results
- object
Search results from refsearch service
Create a new signing key
/media-libraries/{libraryId}/signing-keysPath parameters
Media library identifier
Example:my-media-library
Responses
Signing key created successfully
Signing key ID
Signing key name
Public key
Private key (returned only once)
Creation timestamp
List all signing keys
/media-libraries/{libraryId}/signing-keysPath parameters
Media library identifier
Example:my-media-library
Responses
List of signing keys
Get a specific signing key
/media-libraries/{libraryId}/signing-keys/{keyId}Path parameters
Media library identifier
Example:my-media-librarySigning key identifier
Responses
Signing key details
Delete a signing key
/media-libraries/{libraryId}/signing-keys/{keyId}Get video playback information
/media-libraries/{libraryId}/video/{videoId}/playback-infoPath parameters
Media library identifier
Example:my-media-libraryVideo asset instance ID or asset container ID. If a container ID is provided, resolves to the current version.
Query parameters
- thumbnailWidthinteger
Thumbnail width
- thumbnailHeightinteger
Thumbnail height
- thumbnailTimenumber
Thumbnail time position
- thumbnailFitstring
Thumbnail fit mode
- thumbnailFormatstring
Thumbnail format
- animatedWidthinteger
Animated GIF width
- animatedHeightinteger
Animated GIF height
- animatedStartnumber
Animated GIF start time
- animatedEndnumber
Animated GIF end time
- animatedFpsinteger
Animated GIF FPS
- animatedFormatstring
Animated format
- storyboardFormatstring
Storyboard format
- expirationstring
URL expiration duration
Responses
Video playback information
Video instance ID
- thumbnailobject
Show child attributes
Playback URL
- tokenstring
Access token if required
- expires_atstring (date-time)
Expiration timestamp
- animatedobject
Show child attributes
Playback URL
- tokenstring
Access token if required
- expires_atstring (date-time)
Expiration timestamp
- storyboardobject
Show child attributes
Playback URL
- tokenstring
Access token if required
- expires_atstring (date-time)
Expiration timestamp
- streamobject
Show child attributes
Playback URL
- tokenstring
Access token if required
- expires_atstring (date-time)
Expiration timestamp
Video duration in seconds
- aspectRationumber
Video aspect ratio
Get video playback information headers
/media-libraries/{libraryId}/video/{videoId}/playback-infoRedirect to video playback URL
/media-libraries/{libraryId}/video/{videoId}/playback/{type}Get playback redirect headers
/media-libraries/{libraryId}/video/{videoId}/playback/{type}Redirect to video rendition URL
/media-libraries/{libraryId}/video/{videoId}/renditions/{name}Returns a redirect to the rendition (downloadable MP4) for the specified video
Path parameters
Media library identifier
Example:my-media-libraryVideo asset instance ID or asset container ID. If a container ID is provided, resolves to the current version.
Rendition name (e.g., "720p.mp4", "1080p.mp4")
Responses
Redirect to rendition URL
Get video rendition redirect headers
/media-libraries/{libraryId}/video/{videoId}/renditions/{name}Path parameters
Media library identifier
Example:my-media-libraryVideo asset instance ID or asset container ID. If a container ID is provided, resolves to the current version.
Rendition name (e.g., "720p.mp4", "1080p.mp4")
Responses
Redirect headers