@ai-sdk/luma 2.0.8 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/luma
2
2
 
3
+ ## 2.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 2b8369d: chore: add docs to package dist
8
+
9
+ ## 2.0.9
10
+
11
+ ### Patch Changes
12
+
13
+ - 8dc54db: chore: add src folders to package bundle
14
+
3
15
  ## 2.0.8
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -356,7 +356,7 @@ var lumaImageProviderOptionsSchema = (0, import_provider_utils.lazySchema)(
356
356
  );
357
357
 
358
358
  // src/version.ts
359
- var VERSION = true ? "2.0.8" : "0.0.0-test";
359
+ var VERSION = true ? "2.0.10" : "0.0.0-test";
360
360
 
361
361
  // src/luma-provider.ts
362
362
  var defaultBaseURL = "https://api.lumalabs.ai";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["export { createLuma, luma } from './luma-provider';\nexport type { LumaProvider, LumaProviderSettings } from './luma-provider';\nexport type {\n LumaErrorData,\n LumaImageProviderOptions,\n} from './luma-image-model';\nexport { VERSION } from './version';\n","import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n ImageModelV3File,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n InferSchema,\n lazySchema,\n parseProviderOptions,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings, LumaReferenceType } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Parse and validate provider options\n const lumaOptions = await parseProviderOptions({\n provider: 'luma',\n providerOptions,\n schema: lumaImageProviderOptionsSchema,\n });\n\n // Extract non-request options\n const {\n pollIntervalMillis,\n maxPollAttempts,\n referenceType,\n images: imageConfigs,\n ...providerRequestOptions\n } = lumaOptions ?? {};\n\n // Handle image editing via files with reference type support\n const editingOptions = this.getEditingOptions(\n files,\n mask,\n referenceType ?? undefined,\n imageConfigs ?? [],\n );\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...editingOptions,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n {\n pollIntervalMillis: pollIntervalMillis ?? undefined,\n maxPollAttempts: maxPollAttempts ?? undefined,\n },\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n pollSettings?: { pollIntervalMillis?: number; maxPollAttempts?: number },\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n pollSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n pollSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getEditingOptions(\n files: ImageModelV3File[] | undefined,\n mask: ImageModelV3File | undefined,\n referenceType: LumaReferenceType = 'image',\n imageConfigs: Array<{ weight?: number | null; id?: string | null }> = [],\n ): Record<string, unknown> {\n const options: Record<string, unknown> = {};\n\n // Luma does not support mask-based inpainting\n if (mask != null) {\n throw new Error(\n 'Luma AI does not support mask-based image editing. ' +\n 'Use the prompt to describe the changes you want to make, along with ' +\n '`prompt.images` containing the source image URL.',\n );\n }\n\n if (files == null || files.length === 0) {\n return options;\n }\n\n // Validate all files are URL-based\n for (const file of files) {\n if (file.type !== 'url') {\n throw new Error(\n 'Luma AI only supports URL-based images. ' +\n 'Please provide image URLs using `prompt.images` with publicly accessible URLs. ' +\n 'Base64 and Uint8Array data are not supported.',\n );\n }\n }\n\n // Default weights per reference type\n const defaultWeights: Record<LumaReferenceType, number> = {\n image: 0.85,\n style: 0.8,\n character: 1.0, // Not used, but defined for completeness\n modify_image: 1.0,\n };\n\n switch (referenceType) {\n case 'image': {\n // Supports up to 4 images\n if (files.length > 4) {\n throw new Error(\n 'Luma AI image supports up to 4 reference images. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.image = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.image,\n }));\n break;\n }\n\n case 'style': {\n // Style ref accepts an array but typically uses one style image\n options.style = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.style,\n }));\n break;\n }\n\n case 'character': {\n // Group images by identity id\n const identities: Record<string, string[]> = {};\n for (let i = 0; i < files.length; i++) {\n const file = files[i] as { type: 'url'; url: string };\n const identityId = imageConfigs[i]?.id ?? 'identity0';\n if (!identities[identityId]) {\n identities[identityId] = [];\n }\n identities[identityId].push(file.url);\n }\n\n // Validate each identity has at most 4 images\n for (const [identityId, images] of Object.entries(identities)) {\n if (images.length > 4) {\n throw new Error(\n `Luma AI character supports up to 4 images per identity. ` +\n `Identity '${identityId}' has ${images.length} images.`,\n );\n }\n }\n\n options.character = Object.fromEntries(\n Object.entries(identities).map(([id, images]) => [id, { images }]),\n );\n break;\n }\n\n case 'modify_image': {\n // Only supports a single image\n if (files.length > 1) {\n throw new Error(\n 'Luma AI modify_image only supports a single input image. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.modify_image = {\n url: (files[0] as { type: 'url'; url: string }).url,\n weight: imageConfigs[0]?.weight ?? defaultWeights.modify_image,\n };\n break;\n }\n }\n\n return options;\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n }),\n ),\n);\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n\n/**\n * Provider options schema for Luma image generation.\n *\n * @see https://docs.lumalabs.ai/docs/image-generation\n */\nexport const lumaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n /**\n * The type of image reference to use when providing input images.\n * - `image`: Guide generation using reference images (up to 4). Default.\n * - `style`: Apply a specific style from reference image(s).\n * - `character`: Create consistent characters from reference images (up to 4).\n * - `modify_image`: Transform a single input image with prompt guidance.\n */\n referenceType: z\n .enum(['image', 'style', 'character', 'modify_image'])\n .nullish(),\n\n /**\n * Per-image configuration array. Each entry corresponds to an image in `prompt.images`.\n * Allows setting individual weights for each reference image.\n */\n images: z\n .array(\n z.object({\n /**\n * The weight of this image's influence on the generation.\n * - For `image`: Higher weight = closer to reference (default: 0.85)\n * - For `style`: Higher weight = stronger style influence (default: 0.8)\n * - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)\n */\n weight: z.number().min(0).max(1).nullish(),\n\n /**\n * The identity name for character references.\n * Used with `character` to specify which identity group the image belongs to.\n * Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating\n * images with multiple consistent characters.\n * Default: 'identity0'\n */\n id: z.string().nullish(),\n }),\n )\n .nullish(),\n\n /**\n * Override the polling interval in milliseconds (default 500).\n */\n pollIntervalMillis: z.number().nullish(),\n\n /**\n * Override the maximum number of polling attempts (default 120).\n */\n maxPollAttempts: z.number().nullish(),\n })\n .passthrough(),\n ),\n);\n\nexport type LumaImageProviderOptions = InferSchema<\n typeof lumaImageProviderOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAA2D;AAC3D,IAAAC,yBAKO;;;ACNP,sBAKO;AACP,4BAcO;AAEP,gBAAkB;A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AiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,sBAAsB;AAAA,IACtB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe,CAAC,YAAoB;AAClC,YAAM,IAAI,kCAAiB;AAAA,QACzB;AAAA,QACA,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,OAAO,WAAW;","names":["import_provider","import_provider_utils","_a","_b"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["export { createLuma, luma } from './luma-provider';\nexport type { LumaProvider, LumaProviderSettings } from './luma-provider';\nexport type {\n LumaErrorData,\n LumaImageProviderOptions,\n} from './luma-image-model';\nexport { VERSION } from './version';\n","import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n ImageModelV3File,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n InferSchema,\n lazySchema,\n parseProviderOptions,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings, LumaReferenceType } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Parse and validate provider options\n const lumaOptions = await parseProviderOptions({\n provider: 'luma',\n providerOptions,\n schema: lumaImageProviderOptionsSchema,\n });\n\n // Extract non-request options\n const {\n pollIntervalMillis,\n maxPollAttempts,\n referenceType,\n images: imageConfigs,\n ...providerRequestOptions\n } = lumaOptions ?? {};\n\n // Handle image editing via files with reference type support\n const editingOptions = this.getEditingOptions(\n files,\n mask,\n referenceType ?? undefined,\n imageConfigs ?? [],\n );\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...editingOptions,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n {\n pollIntervalMillis: pollIntervalMillis ?? undefined,\n maxPollAttempts: maxPollAttempts ?? undefined,\n },\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n pollSettings?: { pollIntervalMillis?: number; maxPollAttempts?: number },\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n pollSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n pollSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getEditingOptions(\n files: ImageModelV3File[] | undefined,\n mask: ImageModelV3File | undefined,\n referenceType: LumaReferenceType = 'image',\n imageConfigs: Array<{ weight?: number | null; id?: string | null }> = [],\n ): Record<string, unknown> {\n const options: Record<string, unknown> = {};\n\n // Luma does not support mask-based inpainting\n if (mask != null) {\n throw new Error(\n 'Luma AI does not support mask-based image editing. ' +\n 'Use the prompt to describe the changes you want to make, along with ' +\n '`prompt.images` containing the source image URL.',\n );\n }\n\n if (files == null || files.length === 0) {\n return options;\n }\n\n // Validate all files are URL-based\n for (const file of files) {\n if (file.type !== 'url') {\n throw new Error(\n 'Luma AI only supports URL-based images. ' +\n 'Please provide image URLs using `prompt.images` with publicly accessible URLs. ' +\n 'Base64 and Uint8Array data are not supported.',\n );\n }\n }\n\n // Default weights per reference type\n const defaultWeights: Record<LumaReferenceType, number> = {\n image: 0.85,\n style: 0.8,\n character: 1.0, // Not used, but defined for completeness\n modify_image: 1.0,\n };\n\n switch (referenceType) {\n case 'image': {\n // Supports up to 4 images\n if (files.length > 4) {\n throw new Error(\n 'Luma AI image supports up to 4 reference images. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.image = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.image,\n }));\n break;\n }\n\n case 'style': {\n // Style ref accepts an array but typically uses one style image\n options.style = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.style,\n }));\n break;\n }\n\n case 'character': {\n // Group images by identity id\n const identities: Record<string, string[]> = {};\n for (let i = 0; i < files.length; i++) {\n const file = files[i] as { type: 'url'; url: string };\n const identityId = imageConfigs[i]?.id ?? 'identity0';\n if (!identities[identityId]) {\n identities[identityId] = [];\n }\n identities[identityId].push(file.url);\n }\n\n // Validate each identity has at most 4 images\n for (const [identityId, images] of Object.entries(identities)) {\n if (images.length > 4) {\n throw new Error(\n `Luma AI character supports up to 4 images per identity. ` +\n `Identity '${identityId}' has ${images.length} images.`,\n );\n }\n }\n\n options.character = Object.fromEntries(\n Object.entries(identities).map(([id, images]) => [id, { images }]),\n );\n break;\n }\n\n case 'modify_image': {\n // Only supports a single image\n if (files.length > 1) {\n throw new Error(\n 'Luma AI modify_image only supports a single input image. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.modify_image = {\n url: (files[0] as { type: 'url'; url: string }).url,\n weight: imageConfigs[0]?.weight ?? defaultWeights.modify_image,\n };\n break;\n }\n }\n\n return options;\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n }),\n ),\n);\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n\n/**\n * Provider options schema for Luma image generation.\n *\n * @see https://docs.lumalabs.ai/docs/image-generation\n */\nexport const lumaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n /**\n * The type of image reference to use when providing input images.\n * - `image`: Guide generation using reference images (up to 4). Default.\n * - `style`: Apply a specific style from reference image(s).\n * - `character`: Create consistent characters from reference images (up to 4).\n * - `modify_image`: Transform a single input image with prompt guidance.\n */\n referenceType: z\n .enum(['image', 'style', 'character', 'modify_image'])\n .nullish(),\n\n /**\n * Per-image configuration array. Each entry corresponds to an image in `prompt.images`.\n * Allows setting individual weights for each reference image.\n */\n images: z\n .array(\n z.object({\n /**\n * The weight of this image's influence on the generation.\n * - For `image`: Higher weight = closer to reference (default: 0.85)\n * - For `style`: Higher weight = stronger style influence (default: 0.8)\n * - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)\n */\n weight: z.number().min(0).max(1).nullish(),\n\n /**\n * The identity name for character references.\n * Used with `character` to specify which identity group the image belongs to.\n * Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating\n * images with multiple consistent characters.\n * Default: 'identity0'\n */\n id: z.string().nullish(),\n }),\n )\n .nullish(),\n\n /**\n * Override the polling interval in milliseconds (default 500).\n */\n pollIntervalMillis: z.number().nullish(),\n\n /**\n * Override the maximum number of polling attempts (default 120).\n */\n maxPollAttempts: z.number().nullish(),\n })\n .passthrough(),\n ),\n);\n\nexport type LumaImageProviderOptions = InferSchema<\n typeof lumaImageProviderOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAA2D;AAC3D,IAAAC,yBAKO;;;ACNP,sBAKO;AACP,4BAcO;AAEP,gBAAkB;AAElB,IAAM,+BAA+B;AACrC,IAAM,4BAA4B,MAAQ;AAYnC,IAAM,iBAAN,MAA6C;AAAA,EAUlD,YACW,SACQ,QACjB;AAFS;AACQ;AAXnB,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAAA,EASxB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAM,WAAW;AAAA,I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WAAW;","names":["import_provider","import_provider_utils","_a","_b"]}
package/dist/index.mjs CHANGED
@@ -346,7 +346,7 @@ var lumaImageProviderOptionsSchema = lazySchema(
346
346
  );
347
347
 
348
348
  // src/version.ts
349
- var VERSION = true ? "2.0.8" : "0.0.0-test";
349
+ var VERSION = true ? "2.0.10" : "0.0.0-test";
350
350
 
351
351
  // src/luma-provider.ts
352
352
  var defaultBaseURL = "https://api.lumalabs.ai";
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n ImageModelV3File,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n InferSchema,\n lazySchema,\n parseProviderOptions,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings, LumaReferenceType } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Parse and validate provider options\n const lumaOptions = await parseProviderOptions({\n provider: 'luma',\n providerOptions,\n schema: lumaImageProviderOptionsSchema,\n });\n\n // Extract non-request options\n const {\n pollIntervalMillis,\n maxPollAttempts,\n referenceType,\n images: imageConfigs,\n ...providerRequestOptions\n } = lumaOptions ?? {};\n\n // Handle image editing via files with reference type support\n const editingOptions = this.getEditingOptions(\n files,\n mask,\n referenceType ?? undefined,\n imageConfigs ?? [],\n );\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...editingOptions,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n {\n pollIntervalMillis: pollIntervalMillis ?? undefined,\n maxPollAttempts: maxPollAttempts ?? undefined,\n },\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n pollSettings?: { pollIntervalMillis?: number; maxPollAttempts?: number },\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n pollSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n pollSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getEditingOptions(\n files: ImageModelV3File[] | undefined,\n mask: ImageModelV3File | undefined,\n referenceType: LumaReferenceType = 'image',\n imageConfigs: Array<{ weight?: number | null; id?: string | null }> = [],\n ): Record<string, unknown> {\n const options: Record<string, unknown> = {};\n\n // Luma does not support mask-based inpainting\n if (mask != null) {\n throw new Error(\n 'Luma AI does not support mask-based image editing. ' +\n 'Use the prompt to describe the changes you want to make, along with ' +\n '`prompt.images` containing the source image URL.',\n );\n }\n\n if (files == null || files.length === 0) {\n return options;\n }\n\n // Validate all files are URL-based\n for (const file of files) {\n if (file.type !== 'url') {\n throw new Error(\n 'Luma AI only supports URL-based images. ' +\n 'Please provide image URLs using `prompt.images` with publicly accessible URLs. ' +\n 'Base64 and Uint8Array data are not supported.',\n );\n }\n }\n\n // Default weights per reference type\n const defaultWeights: Record<LumaReferenceType, number> = {\n image: 0.85,\n style: 0.8,\n character: 1.0, // Not used, but defined for completeness\n modify_image: 1.0,\n };\n\n switch (referenceType) {\n case 'image': {\n // Supports up to 4 images\n if (files.length > 4) {\n throw new Error(\n 'Luma AI image supports up to 4 reference images. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.image = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.image,\n }));\n break;\n }\n\n case 'style': {\n // Style ref accepts an array but typically uses one style image\n options.style = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.style,\n }));\n break;\n }\n\n case 'character': {\n // Group images by identity id\n const identities: Record<string, string[]> = {};\n for (let i = 0; i < files.length; i++) {\n const file = files[i] as { type: 'url'; url: string };\n const identityId = imageConfigs[i]?.id ?? 'identity0';\n if (!identities[identityId]) {\n identities[identityId] = [];\n }\n identities[identityId].push(file.url);\n }\n\n // Validate each identity has at most 4 images\n for (const [identityId, images] of Object.entries(identities)) {\n if (images.length > 4) {\n throw new Error(\n `Luma AI character supports up to 4 images per identity. ` +\n `Identity '${identityId}' has ${images.length} images.`,\n );\n }\n }\n\n options.character = Object.fromEntries(\n Object.entries(identities).map(([id, images]) => [id, { images }]),\n );\n break;\n }\n\n case 'modify_image': {\n // Only supports a single image\n if (files.length > 1) {\n throw new Error(\n 'Luma AI modify_image only supports a single input image. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.modify_image = {\n url: (files[0] as { type: 'url'; url: string }).url,\n weight: imageConfigs[0]?.weight ?? defaultWeights.modify_image,\n };\n break;\n }\n }\n\n return options;\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n }),\n ),\n);\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n\n/**\n * Provider options schema for Luma image generation.\n *\n * @see https://docs.lumalabs.ai/docs/image-generation\n */\nexport const lumaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n /**\n * The type of image reference to use when providing input images.\n * - `image`: Guide generation using reference images (up to 4). Default.\n * - `style`: Apply a specific style from reference image(s).\n * - `character`: Create consistent characters from reference images (up to 4).\n * - `modify_image`: Transform a single input image with prompt guidance.\n */\n referenceType: z\n .enum(['image', 'style', 'character', 'modify_image'])\n .nullish(),\n\n /**\n * Per-image configuration array. Each entry corresponds to an image in `prompt.images`.\n * Allows setting individual weights for each reference image.\n */\n images: z\n .array(\n z.object({\n /**\n * The weight of this image's influence on the generation.\n * - For `image`: Higher weight = closer to reference (default: 0.85)\n * - For `style`: Higher weight = stronger style influence (default: 0.8)\n * - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)\n */\n weight: z.number().min(0).max(1).nullish(),\n\n /**\n * The identity name for character references.\n * Used with `character` to specify which identity group the image belongs to.\n * Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating\n * images with multiple consistent characters.\n * Default: 'identity0'\n */\n id: z.string().nullish(),\n }),\n )\n .nullish(),\n\n /**\n * Override the polling interval in milliseconds (default 500).\n */\n pollIntervalMillis: z.number().nullish(),\n\n /**\n * Override the maximum number of polling attempts (default 120).\n */\n maxPollAttempts: z.number().nullish(),\n })\n .passthrough(),\n ),\n);\n\nexport type LumaImageProviderOptions = InferSchema<\n typeof lumaImageProviderOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA,SAAuB,wBAAoC;AAC3D;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACNP;AAAA,EAIE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,SAAS;AAElB,IAAM,+BAA+B;AACrC,IAAM,4BAA4B,MAAQ;AAYnC,IAAM,iBAAN,MAA6C;AAAA,EAUlD,YACW,SACQ,QACjB;AAFS;AACQ;AAXnB,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAAA,EASxB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;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AE,OAAO,EAAE,QAAQ;AAAA,QACzB,CAAC;AAAA,MACH,EACC,QAAQ;AAAA;AAAA;AAAA;AAAA,MAKX,oBAAoB,EAAE,OAAO,EAAE,QAAQ;AAAA;AAAA;AAAA;AAAA,MAKvC,iBAAiB,EAAE,OAAO,EAAE,QAAQ;AAAA,IACtC,CAAC,EACA,YAAY;AAAA,EACjB;AACF;;;AClbO,IAAM,UACX,OACI,UACA;;;AF4CN,IAAM,iBAAiB;AAEhB,SAAS,WAAW,UAAgC,CAAC,GAAiB;AAnD7E;AAoDE,QAAM,UAAU,sBAAqB,aAAQ,YAAR,YAAmB,cAAc;AACtE,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,eAAe,OAAO;AAAA,EACxB;AAEF,QAAM,mBAAmB,CAAC,YACxB,IAAI,eAAe,SAAS;AAAA,IAC1B,UAAU;AAAA,IACV,SAAS,4BAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,iBAAiB,CAAC,YAAoB;AAC1C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,sBAAsB;AAAA,IACtB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe,CAAC,YAAoB;AAClC,YAAM,IAAI,iBAAiB;AAAA,QACzB;AAAA,QACA,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,OAAO,WAAW;","names":["_a","_b"]}
1
+ {"version":3,"sources":["../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n ImageModelV3File,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n InferSchema,\n lazySchema,\n parseProviderOptions,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings, LumaReferenceType } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Parse and validate provider options\n const lumaOptions = await parseProviderOptions({\n provider: 'luma',\n providerOptions,\n schema: lumaImageProviderOptionsSchema,\n });\n\n // Extract non-request options\n const {\n pollIntervalMillis,\n maxPollAttempts,\n referenceType,\n images: imageConfigs,\n ...providerRequestOptions\n } = lumaOptions ?? {};\n\n // Handle image editing via files with reference type support\n const editingOptions = this.getEditingOptions(\n files,\n mask,\n referenceType ?? undefined,\n imageConfigs ?? [],\n );\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...editingOptions,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n {\n pollIntervalMillis: pollIntervalMillis ?? undefined,\n maxPollAttempts: maxPollAttempts ?? undefined,\n },\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n pollSettings?: { pollIntervalMillis?: number; maxPollAttempts?: number },\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n pollSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n pollSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getEditingOptions(\n files: ImageModelV3File[] | undefined,\n mask: ImageModelV3File | undefined,\n referenceType: LumaReferenceType = 'image',\n imageConfigs: Array<{ weight?: number | null; id?: string | null }> = [],\n ): Record<string, unknown> {\n const options: Record<string, unknown> = {};\n\n // Luma does not support mask-based inpainting\n if (mask != null) {\n throw new Error(\n 'Luma AI does not support mask-based image editing. ' +\n 'Use the prompt to describe the changes you want to make, along with ' +\n '`prompt.images` containing the source image URL.',\n );\n }\n\n if (files == null || files.length === 0) {\n return options;\n }\n\n // Validate all files are URL-based\n for (const file of files) {\n if (file.type !== 'url') {\n throw new Error(\n 'Luma AI only supports URL-based images. ' +\n 'Please provide image URLs using `prompt.images` with publicly accessible URLs. ' +\n 'Base64 and Uint8Array data are not supported.',\n );\n }\n }\n\n // Default weights per reference type\n const defaultWeights: Record<LumaReferenceType, number> = {\n image: 0.85,\n style: 0.8,\n character: 1.0, // Not used, but defined for completeness\n modify_image: 1.0,\n };\n\n switch (referenceType) {\n case 'image': {\n // Supports up to 4 images\n if (files.length > 4) {\n throw new Error(\n 'Luma AI image supports up to 4 reference images. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.image = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.image,\n }));\n break;\n }\n\n case 'style': {\n // Style ref accepts an array but typically uses one style image\n options.style = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.style,\n }));\n break;\n }\n\n case 'character': {\n // Group images by identity id\n const identities: Record<string, string[]> = {};\n for (let i = 0; i < files.length; i++) {\n const file = files[i] as { type: 'url'; url: string };\n const identityId = imageConfigs[i]?.id ?? 'identity0';\n if (!identities[identityId]) {\n identities[identityId] = [];\n }\n identities[identityId].push(file.url);\n }\n\n // Validate each identity has at most 4 images\n for (const [identityId, images] of Object.entries(identities)) {\n if (images.length > 4) {\n throw new Error(\n `Luma AI character supports up to 4 images per identity. ` +\n `Identity '${identityId}' has ${images.length} images.`,\n );\n }\n }\n\n options.character = Object.fromEntries(\n Object.entries(identities).map(([id, images]) => [id, { images }]),\n );\n break;\n }\n\n case 'modify_image': {\n // Only supports a single image\n if (files.length > 1) {\n throw new Error(\n 'Luma AI modify_image only supports a single input image. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.modify_image = {\n url: (files[0] as { type: 'url'; url: string }).url,\n weight: imageConfigs[0]?.weight ?? defaultWeights.modify_image,\n };\n break;\n }\n }\n\n return options;\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n }),\n ),\n);\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n\n/**\n * Provider options schema for Luma image generation.\n *\n * @see https://docs.lumalabs.ai/docs/image-generation\n */\nexport const lumaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n /**\n * The type of image reference to use when providing input images.\n * - `image`: Guide generation using reference images (up to 4). Default.\n * - `style`: Apply a specific style from reference image(s).\n * - `character`: Create consistent characters from reference images (up to 4).\n * - `modify_image`: Transform a single input image with prompt guidance.\n */\n referenceType: z\n .enum(['image', 'style', 'character', 'modify_image'])\n .nullish(),\n\n /**\n * Per-image configuration array. Each entry corresponds to an image in `prompt.images`.\n * Allows setting individual weights for each reference image.\n */\n images: z\n .array(\n z.object({\n /**\n * The weight of this image's influence on the generation.\n * - For `image`: Higher weight = closer to reference (default: 0.85)\n * - For `style`: Higher weight = stronger style influence (default: 0.8)\n * - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)\n */\n weight: z.number().min(0).max(1).nullish(),\n\n /**\n * The identity name for character references.\n * Used with `character` to specify which identity group the image belongs to.\n * Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating\n * images with multiple consistent characters.\n * Default: 'identity0'\n */\n id: z.string().nullish(),\n }),\n )\n .nullish(),\n\n /**\n * Override the polling interval in milliseconds (default 500).\n */\n pollIntervalMillis: z.number().nullish(),\n\n /**\n * Override the maximum number of polling attempts (default 120).\n */\n maxPollAttempts: z.number().nullish(),\n })\n .passthrough(),\n ),\n);\n\nexport type LumaImageProviderOptions = InferSchema<\n typeof lumaImageProviderOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA,SAAuB,wBAAoC;AAC3D;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACNP;AAAA,EAIE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,SAAS;AAElB,IAAM,+BAA+B;AACrC,IAAM,4BAA4B,MAAQ;AAYnC,IAAM,iBAAN,MAA6C;AAAA,EAUlD,YACW,SACQ,QACjB;AAFS;AACQ;AAXnB,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAAA,EASxB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEE;AAjEJ;AAkEI,UAAM,WAAmC,CAAC;AAE1C,QAAI,QAAQ,MAAM;AAChB,eAAS,KAAK;AAAA,QACZ,MAAM;AAAA,QACN,SAAS;AAAA,QACT,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAEA,QAAI,QAAQ,MAAM;AAChB,eAAS,KAAK;AAAA,QACZ,MAAM;AAAA,QACN,SAAS;AAAA,QACT,SACE;AAAA,MACJ,CAAC;AAAA,IACH;AAGA,UAAM,cAAc,MAAM,qBAAqB;AAAA,MAC7C,UAAU;AAA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B,aAAQ,YAAR,YAAmB,cAAc;AACtE,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,eAAe,OAAO;AAAA,EACxB;AAEF,QAAM,mBAAmB,CAAC,YACxB,IAAI,eAAe,SAAS;AAAA,IAC1B,UAAU;AAAA,IACV,SAAS,4BAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,iBAAiB,CAAC,YAAoB;AAC1C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,sBAAsB;AAAA,IACtB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe,CAAC,YAAoB;AAClC,YAAM,IAAI,iBAAiB;AAAA,QACzB;AAAA,QACA,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,OAAO,WAAW;","names":["_a","_b"]}
@@ -0,0 +1,260 @@
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', 'bun']}>
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
+
25
+ <Tab>
26
+ <Snippet text="bun add @ai-sdk/luma" dark />
27
+ </Tab>
28
+ </Tabs>
29
+
30
+ ## Provider Instance
31
+
32
+ You can import the default provider instance `luma` from `@ai-sdk/luma`:
33
+
34
+ ```ts
35
+ import { luma } from '@ai-sdk/luma';
36
+ ```
37
+
38
+ If you need a customized setup, you can import `createLuma` and create a provider instance with your settings:
39
+
40
+ ```ts
41
+ import { createLuma } from '@ai-sdk/luma';
42
+
43
+ const luma = createLuma({
44
+ apiKey: 'your-api-key', // optional, defaults to LUMA_API_KEY environment variable
45
+ baseURL: 'custom-url', // optional
46
+ headers: {
47
+ /* custom headers */
48
+ }, // optional
49
+ });
50
+ ```
51
+
52
+ You can use the following optional settings to customize the Luma provider instance:
53
+
54
+ - **baseURL** _string_
55
+
56
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
57
+ The default prefix is `https://api.lumalabs.ai`.
58
+
59
+ - **apiKey** _string_
60
+
61
+ API key that is being sent using the `Authorization` header.
62
+ It defaults to the `LUMA_API_KEY` environment variable.
63
+
64
+ - **headers** _Record&lt;string,string&gt;_
65
+
66
+ Custom headers to include in the requests.
67
+
68
+ - **fetch** _(input: RequestInfo, init?: RequestInit) => Promise&lt;Response&gt;_
69
+
70
+ Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
71
+ You can use it as a middleware to intercept requests,
72
+ or to provide a custom fetch implementation for e.g. testing.
73
+
74
+ ## Image Models
75
+
76
+ You can create Luma image models using the `.image()` factory method.
77
+ For more on image generation with the AI SDK see [generateImage()](/docs/reference/ai-sdk-core/generate-image).
78
+
79
+ ### Basic Usage
80
+
81
+ ```ts
82
+ import { luma, type LumaImageProviderOptions } from '@ai-sdk/luma';
83
+ import { generateImage } from 'ai';
84
+ import fs from 'fs';
85
+
86
+ const { image } = await generateImage({
87
+ model: luma.image('photon-1'),
88
+ prompt: 'A serene mountain landscape at sunset',
89
+ aspectRatio: '16:9',
90
+ });
91
+
92
+ const filename = `image-${Date.now()}.png`;
93
+ fs.writeFileSync(filename, image.uint8Array);
94
+ console.log(`Image saved to ${filename}`);
95
+ ```
96
+
97
+ ### Image Model Settings
98
+
99
+ You can customize the generation behavior with optional settings:
100
+
101
+ ```ts
102
+ const { image } = await generateImage({
103
+ model: luma.image('photon-1'),
104
+ prompt: 'A serene mountain landscape at sunset',
105
+ aspectRatio: '16:9',
106
+ maxImagesPerCall: 1, // Maximum number of images to generate per API call
107
+ providerOptions: {
108
+ luma: {
109
+ pollIntervalMillis: 5000, // How often to check for completed images (in ms)
110
+ maxPollAttempts: 10, // Maximum number of polling attempts before timeout
111
+ },
112
+ } satisfies LumaImageProviderOptions,
113
+ });
114
+ ```
115
+
116
+ Since Luma processes images through an asynchronous queue system, these settings allow you to tune the polling behavior:
117
+
118
+ - **maxImagesPerCall** _number_
119
+
120
+ Override the maximum number of images generated per API call. Defaults to 1.
121
+
122
+ - **pollIntervalMillis** _number_
123
+
124
+ Control how frequently the API is checked for completed images while they are
125
+ being processed. Defaults to 500ms.
126
+
127
+ - **maxPollAttempts** _number_
128
+
129
+ Limit how long to wait for results before timing out, since image generation
130
+ is queued asynchronously. Defaults to 120 attempts.
131
+
132
+ ### Model Capabilities
133
+
134
+ Luma offers two main models:
135
+
136
+ | Model | Description |
137
+ | ---------------- | ---------------------------------------------------------------- |
138
+ | `photon-1` | High-quality image generation with superior prompt understanding |
139
+ | `photon-flash-1` | Faster generation optimized for speed while maintaining quality |
140
+
141
+ Both models support the following aspect ratios:
142
+
143
+ - 1:1
144
+ - 3:4
145
+ - 4:3
146
+ - 9:16
147
+ - 16:9 (default)
148
+ - 9:21
149
+ - 21:9
150
+
151
+ For more details about supported aspect ratios, see the [Luma Image Generation documentation](https://docs.lumalabs.ai/docs/image-generation).
152
+
153
+ Key features of Luma models include:
154
+
155
+ - Ultra-high quality image generation
156
+ - 10x higher cost efficiency compared to similar models
157
+ - Superior prompt understanding and adherence
158
+ - Unique character consistency capabilities from single reference images
159
+ - Multi-image reference support for precise style matching
160
+
161
+ ### Image editing
162
+
163
+ Luma supports different modes of generating images that reference other images.
164
+
165
+ #### Modify an image
166
+
167
+ Images have to be passed as URLs. `weight` can be configured for each image in the `providerOPtions.luma.images` array.
168
+
169
+ ```ts
170
+ await generateImage({
171
+ model: luma.image('photon-flash-1'),
172
+ prompt: {
173
+ text: 'transform the bike to a boat',
174
+ images: [
175
+ 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/future-me-8hcBWcZOkbE53q3gshhEm16S87qDpF.jpeg',
176
+ ],
177
+ },
178
+ providerOptions: {
179
+ luma: {
180
+ images: [{ weight: 1.0 }],
181
+ } satisfies LumaImageProviderOptions,
182
+ },
183
+ });
184
+ ```
185
+
186
+ Learn more at https://docs.lumalabs.ai/docs/image-generation#modify-image.
187
+
188
+ #### Referen an image
189
+
190
+ Use up to 4 reference images to guide your generation. Useful for creating variations or visualizing complex concepts. Adjust the `weight` for each image (0-1) to control the influence of reference images.
191
+
192
+ ```ts
193
+ await generateImage({
194
+ model: luma.image('photon-flash-1'),
195
+ prompt: {
196
+ text: 'A salamander at dusk in a forest pond, in the style of ukiyo-e',
197
+ images: [
198
+ 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/future-me-8hcBWcZOkbE53q3gshhEm16S87qDpF.jpeg',
199
+ ],
200
+ },
201
+ aspectRatio: '1:1',
202
+ providerOptions: {
203
+ luma: {
204
+ referenceType: 'image',
205
+ images: [{ weight: 0.8 }],
206
+ } satisfies LumaImageProviderOptions,
207
+ },
208
+ });
209
+ ```
210
+
211
+ Learn more at https://docs.lumalabs.ai/docs/image-generation#image-reference
212
+
213
+ #### Style Reference
214
+
215
+ Apply specific visual styles to your generations using reference images. Control the style influence using the `weight` parameter.
216
+
217
+ ```ts
218
+ await generateImage({
219
+ model: luma.image('photon-flash-1'),
220
+ prompt: 'A blue cream Persian cat launching its website on Vercel',
221
+ aspectRatio: '1:1',
222
+ providerOptions: {
223
+ luma: {
224
+ referenceType: 'style',
225
+ images: [{ weight: 0.8 }],
226
+ } satisfies LumaImageProviderOptions,
227
+ },
228
+ });
229
+ ```
230
+
231
+ Learn more at https://docs.lumalabs.ai/docs/image-generation#style-reference
232
+
233
+ #### Character Reference
234
+
235
+ Create consistent and personalized characters using up to 4 reference images of the same subject. More reference images improve character representation.
236
+
237
+ ```ts
238
+ await generateImage({
239
+ model: luma.image('photon-flash-1'),
240
+ prompt: {
241
+ text: 'A woman with a cat riding a broomstick in a forest',
242
+ images: [
243
+ 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/future-me-8hcBWcZOkbE53q3gshhEm16S87qDpF.jpeg',
244
+ ],
245
+ },
246
+ aspectRatio: '1:1',
247
+ providerOptions: {
248
+ luma: {
249
+ referenceType: 'character',
250
+ images: [
251
+ {
252
+ id: 'identity0',
253
+ },
254
+ ],
255
+ } satisfies LumaImageProviderOptions,
256
+ },
257
+ });
258
+ ```
259
+
260
+ Learn more at https://docs.lumalabs.ai/docs/image-generation#character-reference
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/luma",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -8,9 +8,14 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
11
+ "docs/**/*",
12
+ "src",
11
13
  "CHANGELOG.md",
12
14
  "README.md"
13
15
  ],
16
+ "directories": {
17
+ "doc": "./docs"
18
+ },
14
19
  "exports": {
15
20
  "./package.json": "./package.json",
16
21
  ".": {
@@ -28,7 +33,7 @@
28
33
  "tsup": "^8",
29
34
  "typescript": "5.8.3",
30
35
  "zod": "3.25.76",
31
- "@ai-sdk/test-server": "1.0.1",
36
+ "@ai-sdk/test-server": "1.0.2",
32
37
  "@vercel/ai-tsconfig": "0.0.0"
33
38
  },
34
39
  "peerDependencies": {
@@ -54,7 +59,7 @@
54
59
  "scripts": {
55
60
  "build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
56
61
  "build:watch": "pnpm clean && tsup --watch",
57
- "clean": "del-cli dist *.tsbuildinfo",
62
+ "clean": "del-cli dist docs *.tsbuildinfo",
58
63
  "lint": "eslint \"./**/*.ts*\"",
59
64
  "type-check": "tsc --build",
60
65
  "prettier-check": "prettier --check \"./**/*.ts*\"",
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { createLuma, luma } from './luma-provider';
2
+ export type { LumaProvider, LumaProviderSettings } from './luma-provider';
3
+ export type {
4
+ LumaErrorData,
5
+ LumaImageProviderOptions,
6
+ } from './luma-image-model';
7
+ export { VERSION } from './version';