media
npx skills add https://github.com/crystallizeapi/ai --skill mediaCrystallize Media Skill
Get images, video and files into the media library, onto items, and into Discovery. Every step is asynchronous, and most failures are silent: a key is handed back before the file exists, renditions arrive minutes to an hour later, and Discovery keeps whatever it saw when the item was published. Media import was the second most frequent problem across twelve builds.
Rendering what you imported (srcset, sizes, WebP vs AVIF, LCP, share images) is [[responsive-images]]. Modelling the components that hold media is [[content-model]]. All mutations here are on the Core API, from scripts or your server.
Consultation Approach
- Where do the files come from? A URL Crystallize can fetch, bytes you hold, or a browser page (user uploads)?
- Images, video or files? Video and files take the upload path only.
- How many? Hundreds need throttling, task checks and a verification pass; thousands need a resumable script.
- Which languages? Alt text, captions and image topics are written once per language.
- When will the items be published? After the renditions exist, or Discovery serves them without renditions.
Choose the way in
| You have | Use |
|---|---|
| A URL Crystallize can fetch | copyRemoteAsset(sourceUrl:, type: image): Crystallize pulls it, as a bulk task |
| Bytes you hold, or a URL it can’t fetch | generatePresignedUploadRequest(type: MEDIA) → form POST (it registers the image) |
| A file uploaded from a browser page | Presign on the server, POST from the browser, no Core token in the page |
| Video, whatever the source | The upload path: copyRemoteAsset takes images only |
| Files (PDF, CAD) | Upload with type: STATIC, then { key, title } in a files component |
| Many images in a mass operation | image/register with {{ upload url }} ([[mass-operations]]) |
copyRemoteAsset can’t fetch a source that:
- takes more than 30 s to answer (the task ends in
error:Request timed out after 30 seconds); - has a URL longer than 256 characters (
InvalidLengthError, before any fetch; signed CDN URLs hit this); - sends no
Content-Length(streamed or chunked resizers, and Cloudflare when it compresses onAccept-Encoding); - sits behind bot protection (Akamai, Imperva): the mutation succeeds and only the task says
error; - answers a compressed body or a
content-typeother thanimage/jpeg,jpg,png,webp,tiff,tiforavif.
For those, download the file yourself and use the upload path. Don’t work around a block a site has put up. Prefer a resized source where the manufacturer offers one: 3-17 MB CMYK originals copied slowly and failed often, while the same CDN’s 1600 px WebP (0.5-1 MB) went in as is.
Details, code and every error: Importing images.
The pipeline that works
- Import with bounded concurrency (8-12). Keep a local
source URL → keycache, so reruns are free and no image is registered twice. - Check every copy task.
copyRemoteAssetanswers with atargetKeyand a task id before the copy runs. ReadbulkTasks(filter: { type: copyRemoteAsset, status: error })(orbulkTask(id:)per task) until no task ispendingorstarted;info.errorhas the reason,targetKeywhat to retry. - Verify that the file landed:
image(key) { key }plus a HEAD on the CDN URL. The record existing proves nothing: a key can be registered whose file never arrives, andimage(key)isnullwhile a copy is pending or failed. - Wait for processing:
image(key) { width variants { url } }.widthandvariantsstayednullfor 15 minutes to over an hour on large imports, while the CDN already served the file. Don’t re-copy becausewidthis stillnull; one build did, and got 320 duplicate records. - Write metadata (alt text, caption, topics, showcases) per language with
updateImage, before publishing:updateImagere-indexes every item that uses the image. - Write the keys onto the items (
imagescomponents, variant images). A key can be referenced as soon as it is registered. - Publish the items only after
variantsexist for every key. Discovery snapshots image metadata at publish time: an item published earlier keepswidth: nullandvariants: []until it is published again (Discovery Indexing).
Check the content of what you imported, too. Manufacturer CDNs serve “missing image” placeholders, logos and blank
images with HTTP 200, a redirect to a login page uploads HTML, and an extension-less URL gives a key that is never
processed. A size and content-hash check catches most of it, and one picture re-encoded per colour variant is
de-duplicated by hash (resourceIdentifier: img-<sha1> in a mass operation).
Presigned uploads
mutation Presign($filename: String!, $contentType: String!) { generatePresignedUploadRequest(filename: $filename, contentType: $contentType, type: MEDIA) { ... on PresignedUploadRequest { url fields { name value } maxSize lifetime } ... on BasicError { errorName message } }}Build a multipart form from fields in the order given, append the file last, and POST it to url. The key is
the key field.
- The POST registers the image by itself. A
registerImageafterwards answersImageAlreadyExistsError: treat it as success. It is still worth calling right after the POST, because it makes the key usable at once. - So a browser page can upload directly: the server makes the presign (Core token), the page POSTs the form, and no Core credential reaches the browser. This is the one Core-related call a storefront page makes, and it goes to the storage URL, not to Core.
- A
400 RequestTimeoutfrom the POST is retried with a fresh presign (the failed try may leave an orphan key). - Check the
content-typeyou are uploading: a 302 to a login page uploaded HTML thatregisterImageaccepted and that never got a size. maxSizewas 10 GiB for images and video. The decoded policy lasts a year, so presigns can be made in bulk.
Metadata per language
updateImage(key:, language:, input:) writes altText, caption ({ html: [...] }), focalPoint, meta,
topicIds and showcase on the library asset:
- Alt text, caption and image topics are per language. Two languages means two writes per image (652 writes for 326 images ran in about two minutes at concurrency 8, with no rate limiting).
- Item images point at the asset, so there is no per-item alt text to keep in sync: Discovery’s
images { altText }comes from the asset, after the next publish. updateImagere-indexes every item that uses the image (17k updates touched all 787 products in one build). Write metadata before publishing products, not after.- Variant attributes are not per language: an
enupdate overwrote thenocolour values. Variant images are written per language. targetFilenameoncopyRemoteAssetsets the public file name (…/<hash>/helsingin-heikas-a1-floor-plan.jpg): name files for people and search engines.- Image topics in Discovery come back as a flat hash of every ancestor path, not leaf paths.
- Classifying images with a vision model (image type, alt text in each language) worked on 697 images; cache by URL.
Showcases (hotspots)
A showcase links a point on an image to products, SKUs or documents: “shop the look”. Core writes showcase
(singular) on updateImage and on every ImageInput; Discovery reads showcases (plural). Coordinates are
fractions 0-1, skus is required (send []), and labels go in meta. See
Showcases.
Video
Upload with generatePresignedUploadRequest(contentType: "video/mp4" | "video/quicktime", type: MEDIA), then write
{ key, title } into a videos component or a variant’s videos. The video is registered when an item first uses it,
transcoded to HLS and DASH in about a minute for a short clip, and an item published before playlists exist keeps
playlists: [] in Discovery. See Video.
Replacing and deleting
- Replace: upload the new file, then
registerImageRevision(imageKey:, revisionKey:)right after the POST. Core and the Catalogue API show the revision at once and the ladder rebuilds in about 25 s, but Discovery keeps the file each item was indexed with. Republishing the items fixed it on one tenant and did not on another, so the reliable way is a new image: upload, write the new key onto the items, publish. - Delete:
deleteImage(key:, force:)refuses while any item version references the image, old versions included (AssetInUseError … referenced in 3 places). Check the current versions, thenforce: true.deleteVideorefuses while an item uses it; once the item is gone the video stays registered and can be reused.
Failure modes
| Symptom | Cause | Fix |
|---|---|---|
| Broken tiles in the library, broken images on items | copyRemoteAsset gave a key, the copy never landed |
Read failed tasks; HEAD-check keys; re-import with requestHeaders, or upload |
image(key) is null after a copy |
Copy pending, or failed (timeout, length, no Content-Length) | Wait for the task; read info.error |
ImageNotFoundError from updateImage right after a copy |
The key exists before the file does | Wait for every copy task; retry “not found” after a delay |
ImageAlreadyExistsError from registerImage |
The copy or the presigned POST registered it already | Treat as success |
width: null, variants: null for a long time |
Renditions are queued (minutes to an hour) | Wait; verify by key + HEAD, not width; don’t re-copy |
variants: [] in Discovery, renditions fine in Core |
The item was published before the renditions existed | Publish the items again |
playlists: [] in Discovery |
Published before transcoding finished | Wait for Core video(key) { playlists }, then publish |
| Alt text shows in one language only | Metadata is per language | updateImage once per language |
| A replaced image still shows the old file | Discovery keeps what it indexed | Republish, or register a new image and write its key |
AssetInUseError on an image nothing current uses |
Old item versions still reference it | deleteImage(force: true) after checking current versions |
copyRemoteAsset rejects a video URL |
RemoteAssetType is image only |
Use the presigned upload path |
References
- Importing images -
copyRemoteAssetand its limits, task checks, presigned uploads, mass operation registration, verification, renditions - Video - Upload, registration on first use, transcoding, thumbnails, publishing order
- Showcases - Hotspot input and output, coordinates, labels per language, variant images
Related skills
[[responsive-images]] renders the ladder. [[mutation]] covers the item writes that reference media keys, and
[[mass-operations]] the image/register path. [[content-model]] decides which components hold media and whether they
are discoverable (an images component left non-discoverable is absent from Discovery). Indexing behaviour is in
Discovery Indexing.
Reference Details
Importing images (Core API)
You have a list of image URLs from a supplier, or files on disk, and they need to end up on products. There are two ways in, and the one you pick decides what can go wrong afterwards.
Signatures were read from the live Core API schema (2026-09-29, rechecked 2026-11-12). The behaviours, what arrives late and what fails silently, are attributed to the builds that hit them.
| You have | Use |
|---|---|
| A URL Crystallize can fetch | copyRemoteAsset: Crystallize pulls it, as a bulk task |
| Bytes you hold, or a URL it cannot fetch | generatePresignedUploadRequest → form POST (→ registerImage) |
| Video, whatever the source | The upload path (Video) |
Copying from a supplier URL
mutation Copy($sourceUrl: String!, $filename: String) { copyRemoteAsset(sourceUrl: $sourceUrl, type: image, targetFilename: $filename) { __typename ... on BulkTaskCopyRemoteAsset { id targetKey status } ... on BasicError { errorName message } }}type is RemoteAssetType, and today its only value is image. requestHeaders: [HttpHeaderInput!] ({ name, value }) is there for sources that will not serve a bare request; a wrong input type name fails the whole mutation
as a validation error. targetFilename sets the public file name.
Each call took 10-15 s to answer for 1 MB sources. Concurrency 12 copied about 2,900 images in 25 minutes on one tenant and 10,743 in 547 s on another.
It is a bulk task, so the key comes back before the file does
targetKey is handed to you immediately; the copy happens afterwards. The consequences, all found the hard way:
- A failed copy only shows on the task.
bulkTask(id:) { ... on BulkTask { status info } }ends inerror, with the reason ininfo.error. List every failure at once withbulkTasks(filter: { type: copyRemoteAsset, status: error }); each carries thetargetKey, which is how a rerun finds what to copy again. - The source has to answer within 30 s. A slow on-the-fly resizer failed 2,897 of 3,056 copies with
Request timed out after 30 seconds; an origin taking up to 107 s for 4-13 MB originals lost 5,677 of 10,563. Copy from the manufacturer’s CDN or resizer instead, and throttle. sourceUrlis at most 256 characters (InvalidLengthError: sourceUrl length must be between 1 and 256 characters), checked before the fetch. Signed CDN URLs of about 300 characters all failed.- The response needs a
Content-Length: chunked resizers fail withNo content length in response, and so does Cloudflare when it compresses onAccept-Encoding. The body must be uncompressed (content-encodingother thanidentityis refused), within the upload limit, with acontent-typeof exactlyimage/jpeg,jpg,png,webp,tiff,tiforavif. - Bot protection fails only in the task. Akamai and Imperva sources returned a key and a task id, and only
bulkTask(id).statussaiderrorlater. A CDN that serves a normal browser but not Crystallize’s fetcher gave every image of one brand a key whose file 404s forever. - Do not call
registerImageafterwards.copyRemoteAssetalready registers the image, and the second call answersImageAlreadyExistsError. updateImageon a fresh key answersImageNotFoundErrorfor a while, andimage(key)isnullwhile a copy is pending or failed. Retry “not found” after a delay, or wait for every copy task rather than the last few.
So after the copy tasks finish, HEAD-check the keys: all of them if the import is small, a sample if it is not.
For the ones that 404, try requestHeaders if you suspect the CDN is refusing the fetch, and otherwise download the
file yourself, convert it if needed (JPEG worked), and take the upload path below. Never work around a block a site
has put up on purpose.
WebP sources work (some manufacturers publish nothing else), and PNG transparency is preserved. (Tools Universe.)
Uploading bytes yourself
Ask for a presigned target, POST the file to it, register what landed.
mutation Upload($filename: String!, $contentType: String!) { generatePresignedUploadRequest(filename: $filename, contentType: $contentType, type: MEDIA) { __typename ... on PresignedUploadRequest { url fields { name value } maxSize lifetime } ... on BasicError { errorName message } }}type is FileUploadType: MEDIA for images and video, STATIC for files, MASS_OPERATIONS for an operations
file. Build a multipart form from fields in the order given, append the file last, and POST it to url.
The key is the key form field, of the form <tenant>/<yy>/<m>/<d>/<hash>/<filename>.
const form = new FormData();for (const { name, value } of presign.fields) form.append(name, value);form.append("file", await fs.openAsBlob(path, { type: contentType }), filename); // Node 20+, streams the fileconst res = await fetch(presign.url, { method: "POST", body: form }); // 201 on successThen:
mutation Register($imageKey: String!) { registerImage(imageKey: $imageKey) { __typename ... on Image { key url width height } ... on BasicError { errorName message } }}- The upload registers the image by itself, in the background.
registerImageright after the POST makes the key usable at once; when it answersImageAlreadyExistsError, the upload got there first. Treat that as success. - Right after
registerImage,width/heightarenulland the media URL answers 404 for 5-20 s. It is fine to reference the key in item writes immediately; poll the HEAD before anything reads the file. - A
400 RequestTimeoutfrom S3 is retried with a fresh presign. - Check the content type before uploading: a URL that 302s to a login page uploads HTML, which registers and never gets a size.
maxSizeis 10 GiB andlifetime3,600 s, while the decoded POST policy is valid for a year, so presigns can be made in bulk ahead of time.- Throughput: download (3 concurrent) + presign + POST +
registerImage(8 concurrent) ran at about 34 images/s. - In JS,
createBinaryFileManager(client).uploadImage(path)does all three steps, and needstenantIdin the client config ([[js-api-client]]).
From a browser page (user content): make the presign on the server, hand the page url and fields, and let the
page POST the form. The POST registers the image, so the page needs no Core token, and your server records the key.
In a mass operation
image/register with {{ upload url rid }} is the fast path: 691 images in five 150-operation files, about 10 s
each. The register log’s input.value.operation.key is the key; cache it. Three traps:
{{ upload }}names the file after the URL’s basename, so an extension-less URL (…/product-images/4846/default) gives a key that registers but is never processed. Append a query whose last segment is a file name (…/default?name=/product-4846.jpg).image/registerwith a resourceIdentifier that is already registered is skipped silently: no log, no key.- Registered images get language
enand no alt text: write metadata afterwards withupdateImageper language.
See [[mass-operations]].
Verifying an import
| Check | Proves |
|---|---|
The task’s status is complete |
The copy ran |
image(key) { key } answers |
The record exists, not that the file arrived |
| A HEAD on the CDN URL answers 200 | The file landed |
image(key) { width variants { url } } |
Processing finished: renditions exist |
Verify the import by key + HEAD. Then, before the final publish, wait for variants: 45 minutes after one
import, 58 of 400 images still had variants: null, and it took about 70 minutes. After 326 copies, all had
width: null for 15 minutes while the CDN served them. A seed that waits for width right after the copy, and
re-copies what lacks it, makes duplicates (320 in one build).
Renditions and Discovery
Image.variants is the generated ladder that [[responsive-images]] builds a srcset from, produced in a queue.
Discovery stores each item with the image metadata it saw when that item was indexed. Content published within
minutes of a bulk upload was served with width/height: null and variants: [] for 280 of 614 images, while Core
had the full ladder shortly after. Re-writing the image components and republishing fixed all of them about 2 minutes
later.
So: a storefront falls back to the original url when variants is empty, and an import publishes only after every
key has variants, or publishes again once they exist (Discovery Indexing).
Replacing an image
registerImageRevision(imageKey:, revisionKey:) points the library entry at a new file: Core image(key) returns the
new url and size, and the ladder rebuilds in about 25 seconds. revisionKey is a file you have just uploaded;
call it right after the POST and skip registerImage, because once the upload has registered itself as an image the
revision is refused.
It reaches the read APIs at different times. The Catalogue API serves the latest revision at once. Discovery stores the file with each indexed document, so every item using the image keeps the original until it is indexed again. One build fixed that by republishing; another (Tools Universe) still saw the old file after rewriting the image component and republishing. The way that worked everywhere: upload the new file as a new image, write the new key onto the items, and publish.
Deleting
mutation Delete($key: String!) { deleteImage(key: $key, force: true) { __typename ... on DeleteCount { removed } ... on AssetInUseError { key referrerCount } }}deleteImage refuses an image that any item version references, old ones included: AssetInUseError … referenced in 3 places came back for an image every current draft and published version had moved away from.
force: true removes it anyway. Check the current versions yourself before forcing. (Car Parts Universe.)
Clearing a variant’s images with Core updateProductVariant(sku, language, input: { images: [] }) leaves its
components alone, unlike the mass operation’s product/variant/update.
Showcases (hotspots)
A showcase links a point on an image to products, SKUs or documents: the “shop the look” feature. (Fashion Universe and four other builds, September to November 2026.)
Writing them (Core)
ImageShowcaseInput (introspected 2026-11-12):
input ImageShowcaseInput { hotspot: FocalPointInput # { x: Float!, y: Float! } itemIds: [ID!] skus: [String!]! # required: send [] for a showcase of items only meta: [KeyValuePairInput!]}It is accepted as showcase (singular, a list) in two places:
updateImage(key:, language:, input: { showcase }), on the library asset, per language;- every
ImageInput:imagescomponents, paragraph images, and variant images throughupdateProductVariant(sku:, input: { images }).
{ "images": [ { "key": "<image key>", "showcase": [ { "hotspot": { "x": 0.42, "y": 0.63 }, "skus": ["SKU-1"], "itemIds": ["<product item id>"], "meta": [{ "key": "label_en", "value": "Basin mixer" }] } ] } ]}- Coordinates are fractions of the image, 0-1: not percent, not pixels. Keep percent in your source data for review if you like, and divide by 100 when writing.
- Labels are not part of a showcase: put them in
meta. On animagescomponent that isn’t multilingual, the showcase list is stored once for all languages and keeps the meta of the last language written, so writelabel_<lang>keys and readmeta(key: "label_<lang>"). On library images (updateImageper language), a plainlabelis per language. - A product’s images are variant images, so a showcase on a product image is written onto every variant that
carries that key, with the full
imageslist (it replaces the list). - Errors:
ImageShowcaseInvalidSkuError(a SKU that doesn’t exist yet: create the products first, or retry without SKUs) andImageShowcaseInvalidIdError. A just-registered key can answerImageNotFoundErrorfor a while. - The mass-operation schema spells the hotspot
hotpost(@crystallize/schema6.17, image content →showcase[].hotpost { x, y }). Write showcases with CoreupdateImageor component content instead.
Core reads them back as Image.showcase ({ hotspot itemIds skus meta }).
Reading them (Discovery)
Discovery serves showcases (plural):
{ search(language: en, filters: { path: { equals: "/inspiration/bathroom" } }) { hits { ... on document { hero { url showcases { hotspot meta items { name path } variants { sku name defaultPrice } } } } } }}hotspot(key:) and meta(key:) are Hash fields ({ x, y }). items resolves to full documents and products, and
variants to full variants, so one hotspot can carry a product (for the path) and a SKU (for the price) at once.
New page-builder pieces that render showcases can need two ignites before Discovery serves them (Discovery Indexing).
Video (Core API)
copyRemoteAsset takes images only, so video always goes through the upload path. (Fashion Universe and Screen
Universe, September 2026.)
Upload and attach
- Download the file. MP4 and MOV upload as they are; an HLS-only source is remuxed first (
ffmpeg -i x.m3u8 -c copy out.mp4). generatePresignedUploadRequest(filename:, contentType: "video/mp4" | "video/quicktime", type: MEDIA).maxSizeis 10 GiB (S3’s own limit for a single POST is 5 GB); 500 MB to 1 GB films are well within it.- POST the form:
fieldsin order, the file last. Stream it (fs.openAsBlob(path, { type: "video/mp4" }), Node 20+): 11 MB uploaded in 1.2 s, 62 MB in 9.5 s. - Write
{ key, title }into avideoscomponent, or a variant’s videos:
mutation Attach($itemId: ID!, $language: String!) { updateComponent( itemId: $itemId language: $language component: { componentId: "trailer" videos: [{ key: "<key>", title: "Trailer", thumbnails: [{ key: "<image key>", altText: "…" }] }] } ) { __typename ... on BasicError { errorName message } }}There is no registerVideo. A video is registered when an item first uses it: video(key) is null after the
upload until { key, title } is written into a component. A videos component’s max is enforced on create
(Cannot provide more than 2 videos for component hero-video).
Transcoding
- A 32 s trailer had Core
video(key) { playlists }within 32 s; a 10-minute, 62 MB file took 114 s. The output is CMAF onmedia.crystallize.com:…/cmaf/<name>.m3u8and.mpd. - The ladder goes up to 1080p, upscaling: 480p and 360p sources both got 234p, 360p, 432p, 720p and 1080p renditions (H.264). One earlier build saw the ladder capped at the source; check on your tenant.
- Every rendition is 29.97 fps: a 25 fps clip came back converted, which judders slightly. It isn’t configurable from the API.
- An audio group is always added: the source’s audio when it has one, otherwise an
engprogram audio group. Keep a silent stereo AAC track on silent sources if you want every file to have the same shape.
Thumbnails
thumbnails stays null unless you write one. Upload a poster image and attach it, either with the video
(VideoInput.thumbnails: [ImageInput], as above) or later with updateVideo. Discovery returns
<component> { thumbnails { url } }.
Publishing order
Discovery doesn’t pick up the playlists by itself. An item published before transcoding finished kept
playlists: [] in Discovery (checked for over four minutes) while Core had them, and publishing the item again fixed
it within 10 s. So: upload, attach, wait for Core video(key) { playlists }, then publish.
Deleting
deleteVideo answers AssetInUseError while an item uses the video, so delete or change the item first. Once the
item is gone, video(key) still answers with its playlists, so a cached key can be attached to a new item and is
ready at once.
Files
Files work the same way: upload with type: STATIC, then write { key, title } into a files component. There is no
register step for them either.
Crystallize AI