# Generate Image — DreamStudio (Stable Diffusion)

> Generate a new image from a text prompt. See the documentation

- Key: `dreamstudio-generate-image`
- Type: Action (Read-only)
- Version: 0.0.4
- App: DreamStudio (Stable Diffusion) (`dreamstudio`) — https://pipedream.com/apps/dreamstudio.md
- This page (HTML): https://pipedream.com/apps/dreamstudio/actions/generate-image
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/dreamstudio/actions/generate-image/generate-image.mjs

## Description

Generate a new image from a text prompt. [See the documentation](https://platform.stability.ai/docs/api-reference#tag/v1generation/operation/textToImage)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `organizationId` | `string` | Yes | The id of the organization. Options are loaded from the connected account. |
| `engineId` | `string` | Yes | The id of the engine. Options are loaded from the connected account. |
| `textPrompts` | `string[]` | Yes | An array of valid JSON objects to use for generation. The JSON object must have the text and the weight. e.g.{"text": "A lighthouse on a cliff", "weight": 0.5} |
| `height` | `integer` | No | Height of the image in pixels. Must be in increments of 64 and pass the following validation: For 512 engines: 262,144 ≤ height * width ≤ 1,048,576. For 768 engines: 589,824 ≤ height * width ≤ 1,048,576. For SDXL Beta: can be as low as 128 and as high as 896 as long as width is not greater than 512. If width is greater than 512 then this can be at most 512. For SDXL v0.9: valid dimensions are 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, 640x1536, 768x1344, 832x1216, or 896x1152. For SDXL v1.0: valid dimensions are the same as SDXL v0.9 |
| `width` | `integer` | No | Width of the image in pixels. Must be in increments of 64 and pass the following validation: For 512 engines: 262,144 ≤ height * width ≤ 1,048,576. For 768 engines: 589,824 ≤ height * width ≤ 1,048,576. For SDXL Beta: can be as low as 128 and as high as 896 as long as height is not greater than 512. If height is greater than 512 then this can be at most 512. For SDXL v0.9: valid dimensions are 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, 640x1536, 768x1344, 832x1216, or 896x1152. For SDXL v1.0: valid dimensions are the same as SDXL v0.9 |
| `cfgScale` | `integer` | No | How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt). |
| `clipGuidancePreset` | `string` | No | Clip Guidance Preset |
| `sampler` | `string` | No | Which sampler to use for the diffusion process. If this value is omitted we'll automatically select an appropriate sampler for you. |
| `samples` | `integer` | No | Number of images to generate |
| `seed` | `integer` | No | Random noise seed (omit this option or use 0 for a random seed). |
| `steps` | `integer` | No | Number od diffusion steps to run. |
| `stylePreset` | `string` | No | Pass in a style preset to guide the image model towards a particular style. |
| `extras` | `object` | No | Extra parameters passed to the engine. These parameters are used for in-development or experimental features and may charge without werning, so please use with caution. |
| `syncDir` | `dir` | Yes | SyncDir |

## 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": "dreamstudio",
      },
    },
  },
)

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: "dreamstudio-generate-image",
  arguments: {
    organizationId: "Organization Id",
    engineId: "Engine Id",
  },
})
```

**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: "dreamstudio-generate-image",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    dreamstudio: { authProvisionId: "apn_xxxxxxx" },
    organizationId: "Organization Id",
    engineId: "Engine Id",
  },
})

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": "dreamstudio-generate-image",
    "configured_props": {
      "dreamstudio": { "authProvisionId": "apn_xxxxxxx" },
      "organizationId": "Organization Id",
      "engineId": "Engine Id"
    }
  }'
```

---

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