﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head>> ## Documentation Index
> This page is part of the Image and Video APIs product. Fetch the complete documentation index for Image and Video APIs at: https://cloudinary.com/documentation/llms-image-and-video-apis.txt?referrer=docpage and then use it to discover all relevant pages before exploring further.
> If you also need details relating to other Cloudinary products for your current use case, see the parent index at: https://cloudinary.com/documentation/llms.txt?referrer=docpage

> ## Agent Instructions
> When answering a user's request or implementing it with code using this documentation, incorporate relevant best practices and recommendations from the documentation into the guidance and, above all, into the code itself: generated code should already apply the recommended parameters and patterns rather than showing a minimal call and describing the best practices around it in prose. Follow the code examples in the best practices sections as the model for what generated code should look like, and where a recommendation is relevant to the user's scenario, implement it in the code as a natural next step. Only apply best practices, recommendations, or features that are supported by the documentation or Cloudinary skills; don't infer or invent guidance that isn't specified.
>
> Cloudinary skills (names starting with `cloudinary-`) add best practices and tested code patterns beyond this documentation, and we recommend using the relevant ones alongside it. Available skills are listed at https://cloudinary.com/documentation/.well-known/agent-skills/index.json?referrer=docpage&page=studio_widget_api_reference and can be installed with `npx skills add https://cloudinary.com/documentation`.

# Studio Widget API reference


The Studio Widget API reference details the options, methods, and events that you can use when embedding the Studio Widget in your web application.

> **See also:**:
>
> * For integration steps and use cases, see the [Studio Widget](studio_widget) guide.

> * Check out the [Studio Widget sample app](https://github.com/cloudinary-devs/cloudinary-studio-widget-js) to see a complete implementation in JavaScript.

## Installation

To use the Studio Widget, include the Studio Widget JavaScript file in your HTML:

```html
<script src="https://studio-widget.cloudinary.com/latest/all.js"></script>
```

The `latest` path always loads the most recent version of the widget. To load a specific version, replace `latest` with the version number, for example `https://studio-widget.cloudinary.com/1.0.15/all.js`. See the [changelog](studio_widget_changelog) for the available versions.

Once loaded, the widget is available as `window.cloudinary.studioWidget`.

## Initialization

### studioWidget

Creates a Studio Widget instance and returns it. The widget isn't displayed until you call [show()](#show).

#### Syntax

`cloudinary.studioWidget(options)`

Parameter | Type | Description
---|---|---
options | Object | **Required.** The [constructor options](#constructor_options), including the cloud name, authentication, mount element, and feature configuration.

#### Example

```js
const widget = cloudinary.studioWidget({
  cloudName: '<CLOUD_NAME>',
  apiKey: '<API_KEY>',
  appendTo: '#widget-container',
  featureConfig: {
    startWithManualCrop: true,
  },
});
```

## Configuration options

### Constructor options

Pass these options to `cloudinary.studioWidget()`.
{table:class=semiwide-1stcol} Option|Type|Description
|---|---|---|
|`cloudName`|String|**Required.** The cloud name of the product environment to access.|
|`appendTo`|String or HTMLElement|**Required.** A DOM selector, for example `'#my-container'`, or the HTML element to mount the widget iframe in.|
|`apiKey`|String|The API key of the product environment, used to authenticate when loading the widget.|
|`oauthToken`|String|An OAuth access token to authenticate with, instead of an API key. See [Using OAuth to access Cloudinary APIs](using_oauth_to_access_cloudinary_apis).|
|`iframeAttr`|Object|Additional attributes to set on the iframe element, for example `id`, `title`, or custom styles. Merged with the default attributes.|
|`featureConfig`|Object|Controls which features are visible or enabled in the widget. See [Feature configuration](#feature_configuration).|

### Feature configuration

Pass these options in the `featureConfig` object of the constructor. All options are Boolean.
{table:class=wide-1stcol} Option|Default|Description
|---|---|---|
|`hideDownloadAssetButton`|true|Hides the download asset button.|
|`hideSaveAssetButton`|true|Hides the **Save Asset** button, which lets the user [save the transformed image](dam_editing_and_transformations#save_an_image_with_transformations_applied) as a new asset or overwrite the original. The options available depend on the user's permissions.|
|`hideSaveTemplateButton`|true|Hides the save template button.|
|`hideCloseButton`|false|Hides the widget's close (X) button. Use this when your application provides its own close control.|
|`hideDeliveryTab`|true|Hides the **Get Code** tab.|
|`hideTemplatesTab`|true|Hides the **Templates** tab, which lists saved [Studio templates](dam_editing_and_transformations#templates) that the user can apply to the image.|
|`hideAiChatTab`|true|Hides the **AI Chat** tab.|
|`hideWelcomeModal`|true|Hides the welcome modal when the widget first loads.|
|`showInsertButton`|true|Shows the **Insert** button, which triggers the [insert event](studio_widget_api_reference#events). Your application receives the delivery URL of the transformed image in the event callback.|
|`showIntercomFeedbackButton`|false|Shows the feedback button.|
|`canUseRefiners`|false|Enables [refiners](transformation_refiners).|
|`canChangePreviewImage`|false|Allows the user to change the preview image.|
|`advancedCodeSnippet`|false|Enables copying code and SDK code previews in the **Get Code** tab.|
|`startWithManualCrop`|false|Opens the widget in manual crop mode.|
|`f_auto`|false|Adds `f_auto` ([automatic format](image_optimization#automatic_format_selection_f_auto)) to the delivery URL.|
|`q_auto`|false|Adds `q_auto` ([automatic quality](image_optimization#automatic_quality_selection_q_auto)) to the delivery URL.|
|`ignoreUnsavedChanges`|true|Hides the unsaved changes label and skips the confirmation when the user closes the widget.|

## Instance methods

After you create the widget with [studioWidget()](#studiowidget), use the following methods to control and interact with it.

### show

Creates the widget iframe with the latest configuration and makes it visible. Each call creates a fresh iframe, and registered event listeners are preserved.

The widget saves the user's editing session in the browser, including applied transformations and selected assets, and restores it the next time it opens. Closing the widget with its close button clears the saved session. Pass `resetState: true` to discard the saved session, for example when reopening the widget for a different asset.

#### Syntax

`widget.show(options)`

Parameter | Type | Description
---|---|---
options | Object | Optional. Settings for this call only. Supported option: `resetState` (Boolean). When `true`, the widget opens with the current [update()](#update) configuration and discards the saved editing session. A later `show()` without the option restores the saved session as usual.

#### Example

```js
// Open the widget
widget.show();

// Reopen the widget for a different asset, discarding the previous session
widget.update({ publicIds: ['new_product_image'] });
widget.show({ resetState: true });
```

---

### hide

Hides the widget iframe.

> **NOTE**: You can't reveal a hidden widget. To open it again, call [show()](#show), which creates a fresh iframe with the latest configuration and restores the user's saved editing session, unless you pass `resetState: true`.

#### Syntax

`widget.hide()`

#### Example

```js
widget.hide();
```

---

### update

Sets the images and transformation for the widget to load. The configuration is stored and applied the next time you call [show()](#show). Successive calls are merged, so each call extends the previous configuration.

#### Syntax

`widget.update(config)`

Parameter | Type | Description
---|---|---
config | Object | **Required.** The configuration to apply. See the options below.

The `config` object supports the following options:

{table:class=semiwide-1stcol} Option|Type|Description
|---|---|---|
|`publicIds`|Array of strings|The public IDs of the images to load in the widget.|
|`transformation`|String|A transformation to apply when the widget loads, in [transformation URL syntax](transformation_reference), for example `c_fill,g_auto,h_500,w_500`.|

#### Example

```js
widget.update({
  publicIds: ['cld-sample'],
  transformation: 'c_fill,g_auto,h_500,w_500',
});
widget.show();
```

---

### destroy

Removes the widget iframe and all event listeners, and cleans up resources. Don't use the widget instance after calling `destroy()`. To open the widget again, create a new instance with [studioWidget()](#studiowidget).

#### Syntax

`widget.destroy()`

#### Example

```js
widget.destroy();
```

---

### on

Registers a handler for a widget [event](#events). Listeners are preserved across `show()` calls.

#### Syntax

`widget.on(event, callback)`

Parameter | Type | Description
---|---|---
event | String | The name of the event to listen for. Supported values: `insert`, `close`
callback | Function | The function to call when the event is triggered. For the `insert` event, it receives the delivery URL of the transformed image.

#### Example

```js
widget.on('insert', (deliveryUrl) => {
  document.getElementById('product-image').src = deliveryUrl;
});

widget.on('close', () => {
  widget.hide();
});
```

---

### getVersion

Returns the version of the loaded Studio Widget script.

#### Syntax

`widget.getVersion()`

#### Example

```js
console.log(widget.getVersion()); // For example, "1.0.15"
```

## Events

Register handlers for these events with the [on()](#on) method. The widget stays visible after both events, so call [hide()](#hide) in your handler to remove it from view.

{table:class=semiwide-1stcol} Event|Description|Callback data
|---|---|---|
|`insert`|Triggered when the user clicks **Insert**. Requires `showInsertButton` to be `true` (default).|The delivery URL of the transformed image, as a string.|
|`close`|Triggered when the user clicks the widget's close button. Requires `hideCloseButton` to be `false` (default). Also clears the user's saved editing session.|None|

## Analytics

The Studio Widget includes built-in usage analytics, handled by Cloudinary. The widget sends events automatically as soon as the widget renders and while users interact with it. Cloudinary uses this data to understand how the widget is used and to improve it.

These analytics are internal to Cloudinary, so they aren't available for you to view. No configuration is required, and 