> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generation

> Generate images on-device

`RunAnywhere.images` generates an image from a prompt.

```swift theme={null}
let result = try await RunAnywhere.images.generate(prompt: "A lighthouse at dusk")
```

## Signatures

```swift theme={null}
func generate(prompt: String, options: ImageOptions? = nil) async throws -> ImageResult
func generateStream(prompt: String, options: ImageOptions? = nil) async throws
    -> AsyncThrowingStream<ImageEvent, Error>
```

## Options

```swift theme={null}
let result = try await RunAnywhere.images.generate(
    prompt: "A lighthouse at dusk, oil painting",
    options: ImageOptions(
        negativePrompt: "blurry, text, watermark",
        width: 512,
        height: 512,
        steps: 20,
        guidanceScale: 7.5,
        seed: 42
    )
)
```

| Field            | Type        | Default       | Meaning                                            |
| ---------------- | ----------- | ------------- | -------------------------------------------------- |
| `negativePrompt` | `String?`   | none          | What to avoid                                      |
| `width`          | `Int?`      | model default | Output width                                       |
| `height`         | `Int?`      | model default | Output height                                      |
| `steps`          | `Int?`      | model default | Denoising steps; more is slower and usually better |
| `guidanceScale`  | `Float?`    | model default | How closely to follow the prompt                   |
| `seed`           | `Int?`      | random        | Fix it to reproduce an image                       |
| `mode`           | `ImageMode` | `.generate`   | `.generate` or inpainting                          |
| `reportPartials` | `Bool`      | `false`       | Emit intermediate images while streaming           |

## Watching it appear

With `reportPartials: true`, the stream emits intermediate images so you can show progress
rather than a spinner.

```swift theme={null}
let stream = try await RunAnywhere.images.generateStream(
    prompt: "A lighthouse at dusk",
    options: ImageOptions(steps: 20, reportPartials: true)
)

for try await event in stream {
    switch event {
    case .partial(let image):
        preview = image
    case .completed(let result):
        final = result
    default:
        break
    }
}
```

## Reproducing an image

Fix the seed and every other option, and the same prompt produces the same image.

```swift theme={null}
ImageOptions(seed: 42)
```

## Cost

Image generation is the heaviest thing in the SDK. A 512×512 image at 20 steps takes far
longer than a text completion and warms the device noticeably. Show progress, allow
cancellation by cancelling the enclosing `Task`, and do not run it on a timer.
