( model: string, size: string | undefined, )
| 239 | * Throws an error if the size is invalid |
| 240 | */ |
| 241 | export function validateImageSize( |
| 242 | model: string, |
| 243 | size: string | undefined, |
| 244 | ): void { |
| 245 | if (!size) return |
| 246 | |
| 247 | const aspectRatio = sizeToAspectRatio(size) |
| 248 | if (!aspectRatio) { |
| 249 | const validSizes = Object.keys(GEMINI_SIZE_TO_ASPECT_RATIO) |
| 250 | throw new Error( |
| 251 | `Invalid size "${size}" for model "${model}". ` + |
| 252 | `Gemini Imagen uses aspect ratios. Valid sizes that map to aspect ratios: ${validSizes.join(', ')}. ` + |
| 253 | `Alternatively, use providerOptions.aspectRatio directly with values: 1:1, 3:4, 4:3, 9:16, 16:9, 9:21, 21:9`, |
| 254 | ) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Per-model caps on images per request. |
no test coverage detected