|
| 1 | +--- |
| 2 | +title: Luma |
| 3 | +description: Learn how to use Luma AI models with the AI SDK. |
| 4 | +--- |
| 5 | + |
| 6 | +# Luma Provider |
| 7 | + |
| 8 | +[Luma AI](https://lumalabs.ai/) provides state-of-the-art image generation models through their Dream Machine platform. Their models offer ultra-high quality image generation with superior prompt understanding and unique capabilities like character consistency and multi-image reference support. |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +The Luma provider is available via the `@ai-sdk/luma` module. You can install it with |
| 13 | + |
| 14 | +<Tabs items={['pnpm', 'npm', 'yarn']}> |
| 15 | + <Tab> |
| 16 | + <Snippet text="pnpm add @ai-sdk/luma" dark /> |
| 17 | + </Tab> |
| 18 | + <Tab> |
| 19 | + <Snippet text="npm install @ai-sdk/luma" dark /> |
| 20 | + </Tab> |
| 21 | + <Tab> |
| 22 | + <Snippet text="yarn add @ai-sdk/luma" dark /> |
| 23 | + </Tab> |
| 24 | +</Tabs> |
| 25 | + |
| 26 | +## Provider Instance |
| 27 | + |
| 28 | +You can import the default provider instance `luma` from `@ai-sdk/luma`: |
| 29 | + |
| 30 | +```ts |
| 31 | +import { luma } from '@ai-sdk/luma'; |
| 32 | +``` |
| 33 | + |
| 34 | +If you need a customized setup, you can import `createLuma` and create a provider instance with your settings: |
| 35 | + |
| 36 | +```ts |
| 37 | +import { createLuma } from '@ai-sdk/luma'; |
| 38 | + |
| 39 | +const luma = createLuma({ |
| 40 | + apiKey: 'your-api-key', // optional, defaults to LUMA_API_KEY environment variable |
| 41 | + baseURL: 'custom-url', // optional |
| 42 | + headers: { |
| 43 | + /* custom headers */ |
| 44 | + }, // optional |
| 45 | +}); |
| 46 | +``` |
| 47 | + |
| 48 | +You can use the following optional settings to customize the Luma provider instance: |
| 49 | + |
| 50 | +- **baseURL** _string_ |
| 51 | + |
| 52 | + Use a different URL prefix for API calls, e.g. to use proxy servers. |
| 53 | + The default prefix is `https://api.lumalabs.ai`. |
| 54 | + |
| 55 | +- **apiKey** _string_ |
| 56 | + |
| 57 | + API key that is being sent using the `Authorization` header. |
| 58 | + It defaults to the `LUMA_API_KEY` environment variable. |
| 59 | + |
| 60 | +- **headers** _Record<string,string>_ |
| 61 | + |
| 62 | + Custom headers to include in the requests. |
| 63 | + |
| 64 | +- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_ |
| 65 | + |
| 66 | + Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation. |
| 67 | + You can use it as a middleware to intercept requests, |
| 68 | + or to provide a custom fetch implementation for e.g. testing. |
| 69 | + |
| 70 | +## Image Models |
| 71 | + |
| 72 | +You can create Luma image models using the `.image()` factory method. |
| 73 | +For more on image generation with the AI SDK see [generateImage()](/docs/reference/ai-sdk-core/generate-image). |
| 74 | + |
| 75 | +### Basic Usage |
| 76 | + |
| 77 | +```ts |
| 78 | +import { luma } from '@ai-sdk/luma'; |
| 79 | +import { experimental_generateImage as generateImage } from 'ai'; |
| 80 | +import fs from 'fs'; |
| 81 | + |
| 82 | +const { image } = await generateImage({ |
| 83 | + model: luma.image('photon-1'), |
| 84 | + prompt: 'A serene mountain landscape at sunset', |
| 85 | + aspectRatio: '16:9', |
| 86 | +}); |
| 87 | + |
| 88 | +const filename = `image-${Date.now()}.png`; |
| 89 | +fs.writeFileSync(filename, image.uint8Array); |
| 90 | +console.log(`Image saved to ${filename}`); |
| 91 | +``` |
| 92 | + |
| 93 | +### Image Model Settings |
| 94 | + |
| 95 | +When creating an image model, you can customize the generation behavior with optional settings: |
| 96 | + |
| 97 | +```ts |
| 98 | +const model = luma.image('photon-1', { |
| 99 | + maxImagesPerCall: 1, // Maximum number of images to generate per API call |
| 100 | + pollIntervalMillis: 5000, // How often to check for completed images (in ms) |
| 101 | + maxPollAttempts: 10, // Maximum number of polling attempts before timeout |
| 102 | +}); |
| 103 | +``` |
| 104 | + |
| 105 | +Since Luma processes images through an asynchronous queue system, these settings allow you to tune the polling behavior: |
| 106 | + |
| 107 | +- **maxImagesPerCall** _number_ |
| 108 | + |
| 109 | + Override the maximum number of images generated per API call. Defaults to 1. |
| 110 | + |
| 111 | +- **pollIntervalMillis** _number_ |
| 112 | + |
| 113 | + Control how frequently the API is checked for completed images while they are |
| 114 | + being processed. Defaults to 500ms. |
| 115 | + |
| 116 | +- **maxPollAttempts** _number_ |
| 117 | + |
| 118 | + Limit how long to wait for results before timing out, since image generation |
| 119 | + is queued asynchronously. Defaults to 120 attempts. |
| 120 | + |
| 121 | +### Model Capabilities |
| 122 | + |
| 123 | +Luma offers two main models: |
| 124 | + |
| 125 | +| Model | Description | |
| 126 | +| ---------------- | ---------------------------------------------------------------- | |
| 127 | +| `photon-1` | High-quality image generation with superior prompt understanding | |
| 128 | +| `photon-flash-1` | Faster generation optimized for speed while maintaining quality | |
| 129 | + |
| 130 | +Both models support the following aspect ratios: |
| 131 | + |
| 132 | +- 1:1 |
| 133 | +- 3:4 |
| 134 | +- 4:3 |
| 135 | +- 9:16 |
| 136 | +- 16:9 (default) |
| 137 | +- 9:21 |
| 138 | +- 21:9 |
| 139 | + |
| 140 | +For more details about supported aspect ratios, see the [Luma Image Generation documentation](https://docs.lumalabs.ai/docs/image-generation). |
| 141 | + |
| 142 | +Key features of Luma models include: |
| 143 | + |
| 144 | +- Ultra-high quality image generation |
| 145 | +- 10x higher cost efficiency compared to similar models |
| 146 | +- Superior prompt understanding and adherence |
| 147 | +- Unique character consistency capabilities from single reference images |
| 148 | +- Multi-image reference support for precise style matching |
| 149 | + |
| 150 | +### Advanced Options |
| 151 | + |
| 152 | +Luma models support several advanced features through the `providerOptions.luma` parameter. |
| 153 | + |
| 154 | +#### Image Reference |
| 155 | + |
| 156 | +Use up to 4 reference images to guide your generation. Useful for creating variations or visualizing complex concepts. Adjust the `weight` (0-1) to control the influence of reference images. |
| 157 | + |
| 158 | +```ts |
| 159 | +// Example: Generate a salamander with reference |
| 160 | +await generateImage({ |
| 161 | + model: luma.image('photon-1'), |
| 162 | + prompt: 'A salamander at dusk in a forest pond, in the style of ukiyo-e', |
| 163 | + providerOptions: { |
| 164 | + luma: { |
| 165 | + image_ref: [ |
| 166 | + { |
| 167 | + url: 'https://example.com/reference.jpg', |
| 168 | + weight: 0.85, |
| 169 | + }, |
| 170 | + ], |
| 171 | + }, |
| 172 | + }, |
| 173 | +}); |
| 174 | +``` |
| 175 | + |
| 176 | +#### Style Reference |
| 177 | + |
| 178 | +Apply specific visual styles to your generations using reference images. Control the style influence using the `weight` parameter. |
| 179 | + |
| 180 | +```ts |
| 181 | +// Example: Generate with style reference |
| 182 | +await generateImage({ |
| 183 | + model: luma.image('photon-1'), |
| 184 | + prompt: 'A blue cream Persian cat launching its website on Vercel', |
| 185 | + providerOptions: { |
| 186 | + luma: { |
| 187 | + style_ref: [ |
| 188 | + { |
| 189 | + url: 'https://example.com/style.jpg', |
| 190 | + weight: 0.8, |
| 191 | + }, |
| 192 | + ], |
| 193 | + }, |
| 194 | + }, |
| 195 | +}); |
| 196 | +``` |
| 197 | + |
| 198 | +#### Character Reference |
| 199 | + |
| 200 | +Create consistent and personalized characters using up to 4 reference images of the same subject. More reference images improve character representation. |
| 201 | + |
| 202 | +```ts |
| 203 | +// Example: Generate character-based image |
| 204 | +await generateImage({ |
| 205 | + model: luma.image('photon-1'), |
| 206 | + prompt: 'A woman with a cat riding a broomstick in a forest', |
| 207 | + providerOptions: { |
| 208 | + luma: { |
| 209 | + character_ref: { |
| 210 | + identity0: { |
| 211 | + images: ['https://example.com/character.jpg'], |
| 212 | + }, |
| 213 | + }, |
| 214 | + }, |
| 215 | + }, |
| 216 | +}); |
| 217 | +``` |
| 218 | + |
| 219 | +#### Modify Image |
| 220 | + |
| 221 | +Transform existing images using text prompts. Use the `weight` parameter to control how closely the result matches the input image (higher weight = closer to input but less creative). |
| 222 | + |
| 223 | +<Note> |
| 224 | + For color changes, it's recommended to use a lower weight value (0.0-0.1). |
| 225 | +</Note> |
| 226 | + |
| 227 | +```ts |
| 228 | +// Example: Modify existing image |
| 229 | +await generateImage({ |
| 230 | + model: luma.image('photon-1'), |
| 231 | + prompt: 'transform the bike to a boat', |
| 232 | + providerOptions: { |
| 233 | + luma: { |
| 234 | + modify_image_ref: { |
| 235 | + url: 'https://example.com/image.jpg', |
| 236 | + weight: 1.0, |
| 237 | + }, |
| 238 | + }, |
| 239 | + }, |
| 240 | +}); |
| 241 | +``` |
| 242 | + |
| 243 | +For more details about Luma's capabilities and features, visit the [Luma Image Generation documentation](https://docs.lumalabs.ai/docs/image-generation). |
0 commit comments