Attach typed, validated business fields (SKU, campaign, rights expiry) to assets, so applications can filter and route on a stable schema instead of free-form tags.
const cloudinary = require('cloudinary').v2; // reads CLOUDINARY_URL
await cloudinary.api.add_metadata_field({
external_id: 'sku',
label: 'SKU',
type: 'string',
mandatory: false
});Field types include string, integer, date, enum, and set (enum/set take a
datasource of allowed values).
// At upload time:
await cloudinary.uploader.upload('https://res.cloudinary.com/demo/image/upload/sample.jpg', {
public_id: 'examples/product-photo',
overwrite: true,
metadata: { sku: 'SKU-00042' }
});
// Or later:
await cloudinary.uploader.update_metadata({ sku: 'SKU-00042' }, ['examples/product-photo']);const result = await cloudinary.search
.expression('metadata.sku="SKU-00042"')
.execute();A common pattern for turning model output into data you can rely on:
- Run AI analysis on the asset (captioning, tagging — for example the Analyze API, subscription required).
- Normalize the output against your schema — map free-form values onto your allowed list, drop low-confidence results, apply business rules.
- Write the resulting values as structured metadata.
- Search, route, and deliver based on that metadata.
Step 2 is where the value is: structured metadata fields are typed and validated, so whatever you write has to conform. Automate it when the rules are clear and route to a person only for the cases your rules cannot decide.
external_id already exists— field definitions are per-environment and permanent; reuse the existing field instead of re-creating it.- Enum/set writes fail when the value is not in the datasource — update the datasource
first (
api.update_metadata_field_datasource).