Picsart Change Background
Picsart · Image · Image → Image
Swap the background of a photo using a text prompt for the new scene.
picsart-change-bgWorkflow: v4/smart-backgroundOverview
Alongside the unified model APIs, we expose compatibility APIs that take each vendor's original parameters exactly as the vendor defines them — nothing renamed, nothing reshaped on the way through.
That makes them the shortest path onto Picsart if you already work with the vendor directly: the request bodies you've already written keep working as they are. You keep their parameter names and defaults, and you get the vendor's full parameter set rather than the subset that is shared across every model.
The cost is that a request is written for one vendor — switching models later means rewriting it, and results come back in the vendor's own shape. When you'd rather write once and change models freely, use the unified API.
Make a request
Call the workflow with ai.apis.run() in TypeScript, or hit /workflows/{workflow}/execute directly — params is passed through untouched either way.
These endpoints are addressed by workflow name rather than model id: the one in this model's header, since one model runs as one workflow. Authentication is unchanged — your Picsart API key as a bearer token (see Authentication).
import { createClient, ApiRunMode } from '@picsart/ai-sdk';
const ai = createClient({
apiKey: process.env.PICSART_API_KEY,
apiUrl: 'https://api.picsart.com',
});
// Calls the 'v4/smart-background' workflow directly — params are sent as-is.
const { result, usage } = await ai.apis.run('v4/smart-background', {
prompt: "modern office environment with soft lighting"
}, {
mode: ApiRunMode.SYNC,
});
console.log(result); // workflow-specific output
console.log(usage?.credits); // credits chargedParameters
14 parameters, sent inside params. These are the vendor's own names, so they line up one-for-one with the vendor's documentation. Required ones must be supplied; the rest fall back to their defaults.
| Parameter | Type | Required | Default | Details |
|---|---|---|---|---|
imageUrlThe original image with background. Provide this OR bgRemovedImageUrl | string | no | — | e.g. https://example.com/image.jpg |
bgRemovedImageUrlImage with background already removed. Provide this OR imageUrl | string | no | — | e.g. https://example.com/bg-removed.jpg |
maskUrlOptional mask URL for precise background control | string | no | — | e.g. https://example.com/mask.png |
maskedImageUrlOptional masked image URL. Required for models/configs that need client-provided masked image | string | no | — | e.g. https://example.com/masked-image.png |
promptCustom prompt for background generation. If not provided, smart prompts will be generated | string | no | — | e.g. modern office environment with soft lighting |
previewWhen true, the background generation is charged credits — but only when an input prompt is also provided. Defaults to false for backward compatibility, in which case no credits are charged. | boolean | no | false | e.g. false |
modelAI model to use for background generation | string | no | — | stable-diffusion-inpaintstable-diffusion-inpaint-pcpideogram-v2-turboflux-inpainterflux-v2gemini-v2qwen-image-2-editseedreamgrok-image-editflux-2-klein-4b |
countNumber of background variations to generate | number | no | — | 1–10 e.g. 3 |
promptInfoEnhanced prompt information for better generation control | object | no | — | — |
└ objectDescriptionPre-generated description of the main object in the image | string | no | — | e.g. A red sports car with chrome details |
└ stylePreferencePreferred style or theme for background generation | string | no | — | e.g. minimalist, professional, outdoor |
└ colorPreferenceColor palette preferences (comma-separated) | string | no | — | e.g. warm tones, earth colors, blue accents |
processingOptionsProcessing preferences and optimizations | object | no | — | — |
└ enableProgressiveResultsEnable progressive result publishing for real-time updates | boolean | no | true | — |
└ skipContentSafetySkip content safety checks (use with caution) | boolean | no | false | — |
└ inputModePreferred input processing mode | string | no | full_pipeline | full_pipelinebg_removedwith_mask |
versionModel version to use for background generation (e.g., v1.5.0) | string | no | — | e.g. v1.5.0 |
widthWidth of the input image in pixels. Used by models that require explicit dimensions (e.g., Flux V2) | number | no | — | e.g. 1024 |
heightHeight of the input image in pixels. Used by models that require explicit dimensions (e.g., Flux V2) | number | no | — | e.g. 768 |
optionsOptions controlling safety checks and drive integration | object | no | — | — |
└ safety_checksSafety check settings | object | no | — | — |
└ enabledWhether to run content moderation. Defaults to true. | boolean | no | — | — |
└ driveSave result to Picsart Drive | object | no | — | — |
└ nameFile name in Picsart Drive | string | yes | — | — |
└ attributesCustom attributes to attach to the file | object | no | — | — |
└ folderTarget folder in Picsart Drive | object | no | — | — |
Response
Over HTTP the output arrives inside a status envelope, at response.result. ai.apis.run() unwraps that envelope for you and resolves to { result, usage } instead. Either way the resultitself is the vendor's own shape.
{
"result": {
"originalImageUrl": "…",
"bgRemovedImageUrl": "…",
"maskUrl": "…",
"promptInfo": {
"objectDescription": "…",
"stylePreference": "…",
"colorPreference": "…"
},
"images": [
{
"id": "wf_abc123",
"url": "https://cdn.picsart.com/…/result.jpg",
"prompt": "…",
"model": "stable-diffusion-inpaint"
}
],
"metadata": {
"modelUsed": "stable-diffusion-inpaint",
"stagesCompleted": [
"completed"
],
"totalProcessingTime": 0,
"performance": {}
}
},
"usage": {
"credits": 1
}
}