> ## 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.

# Vision Language Models

> Ask a model about an image

`RunAnywhere.vlm` takes an image and a prompt.

```swift theme={"theme":"css-variables"}
import RunAnywhereLlamaCPP
LlamaCPP.register()

let result = try await RunAnywhere.vlm.generate(
    image: ImageInput.file(path),
    prompt: "What is in this photo?"
)

print(result.text)
```

## Signatures

```swift theme={"theme":"css-variables"}
func generate(image: ImageInput, prompt: String, options: LlmOptions? = nil) async throws
    -> GenerationResult
func generateStream(image: ImageInput, prompt: String, options: LlmOptions? = nil) async throws
    -> AsyncThrowingStream<GenerationEvent, Error>
```

## Building an ImageInput

```swift theme={"theme":"css-variables"}
ImageInput.file(_ path: String)
ImageInput.bytes(_ data: Data)
ImageInput.rawRgb(_ data: Data, width: Int, height: Int)
ImageInput.cgImage(_ image: CGImage) throws
ImageInput.uiImage(_ image: UIImage) throws        // iOS
ImageInput.nsImage(_ image: NSImage) throws        // macOS
ImageInput.pixelBuffer(_ buffer: CVPixelBuffer) throws
```

The last four are the ones you want in an app. `pixelBuffer` is the camera path.

## From the photo library

```swift theme={"theme":"css-variables"}
import PhotosUI

func describe(_ item: PhotosPickerItem) async throws -> String {
    guard let data = try await item.loadTransferable(type: Data.self),
          let image = UIImage(data: data) else { return "" }

    let result = try await RunAnywhere.vlm.generate(
        image: try ImageInput.uiImage(image),
        prompt: "Describe this image in one sentence."
    )
    return result.text
}
```

## From the camera

`CVPixelBuffer` comes straight off a capture output, so live analysis needs no conversion:

```swift theme={"theme":"css-variables"}
func captureOutput(_ output: AVCaptureOutput,
                   didOutput sampleBuffer: CMSampleBuffer,
                   from connection: AVCaptureConnection) {
    guard let buffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }

    Task {
        let result = try await RunAnywhere.vlm.generate(
            image: try ImageInput.pixelBuffer(buffer),
            prompt: "What do you see?"
        )
        await MainActor.run { self.caption = result.text }
    }
}
```

Throttle this. A VLM pass costs far more than a camera frame interval, so run one at a time
and drop frames that arrive while a pass is in flight.

## Streaming

```swift theme={"theme":"css-variables"}
let stream = try await RunAnywhere.vlm.generateStream(
    image: try ImageInput.uiImage(photo),
    prompt: "Describe this in detail."
)

for try await event in stream {
    if case .token(let token) = event { caption += token.text }
}
```

## Options

`vlm` takes the same `LlmOptions` as `llm`, so `maxOutputTokens`, `temperature`, and
`systemPrompt` all apply.

## Models

VLM runs on the llama.cpp backend, so the model needs to be a GGUF vision model with its
projector. Register `RunAnywhereLlamaCPP` and pick a VLM entry from the catalog.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.