# Image Background Removal — Runware

> Request an image background removal task to be processed by the Runware API. See the documentation.

- Key: `runware-image-background-removal`
- Type: Action (Write)
- Version: 0.0.2
- App: Runware (`runware`) — https://pipedream.com/apps/runware.md
- This page (HTML): https://pipedream.com/apps/runware/actions/image-background-removal
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/runware/actions/image-background-removal/image-background-removal.mjs

## Description

Request an image background removal task to be processed by the Runware API. [See the documentation](https://docs.runware.ai/en/image-editing/background-removal).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `inputImage` | `string` | Yes | Specifies the input image to be processed. The image can be specified in one of the following formats: An UUID v4 string of a previously uploaded image or a generated image. A data URI string representing the image. The data URI must be in the format data:<mediaType>;base64, followed by the base64-encoded image. For example: data:image/png;base64,iVBORw0KGgo.... A base64 encoded image without the data URI prefix. For example: iVBORw0KGgo.... A URL pointing to the image. The image must be accessible publicly. Supported formats are: PNG, JPG and WEBP. |
| `outputType` | `string` | No | Specifies the output type in which the image is returned. |
| `outputFormat` | `string` | No | Specifies the format of the output image. |
| `includeCost` | `boolean` | No | If set to true, the cost to perform the task will be included in the response object. Defaults to false. |
| `rgb` | `string[]` | No | An array representing the [red, green, blue] values that define the color of the removed background. Eg. [255, 255, 255]. |
| `postProcessMask` | `boolean` | No | Flag indicating whether to post-process the mask. Controls whether the mask should undergo additional post-processing. This step can improve the accuracy and quality of the background removal mask. |
| `returnOnlyMask` | `boolean` | No | Flag indicating whether to return only the mask. The mask is the opposite of the image background removal. |
| `alphaMatting` | `boolean` | No | Flag indicating whether to use alpha matting. Alpha matting is a post-processing technique that enhances the quality of the output by refining the edges of the foreground object. |
| `alphaMattingForegroundThreshold` | `integer` | No | Threshold value used in alpha matting to distinguish the foreground from the background. Adjusting this parameter affects the sharpness and accuracy of the foreground object edges. Eg. 240. |
| `alphaMattingBackgroundThreshold` | `integer` | No | Threshold value used in alpha matting to refine the background areas. It influences how aggressively the algorithm removes the background while preserving image details. The higher the value, the more computation is needed and therefore the more expensive the operation is. Eg. 10. |
| `alphaMattingErodeSize` | `integer` | No | Specifies the size of the erosion operation used in alpha matting. Erosion helps in smoothing the edges of the foreground object for a cleaner removal of the background. Eg. 10. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "runware",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "runware-image-background-removal",
  arguments: {
    inputImage: "Input Image",
    outputType: "Output Type",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "runware-image-background-removal",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    runware: { authProvisionId: "apn_xxxxxxx" },
    inputImage: "Input Image",
    outputType: "Output Type",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "runware-image-background-removal",
    "configured_props": {
      "runware": { "authProvisionId": "apn_xxxxxxx" },
      "inputImage": "Input Image",
      "outputType": "Output Type"
    }
  }'
```

---

- App: https://pipedream.com/apps/runware.md · All apps: https://pipedream.com/apps
