import {z} from 'zod' export type CreateApiGenerateVideoLightricksLtxVideo25FastArgs = {'X-Webhook-URL'?: string | undefined, body: {prompt: string, start_image?: (string | null) | undefined, aspect_ratio?: ('16:9' | '9:16') | undefined, duration?: (number | number | number | number | number | number | number | number) | undefined, resolution?: ('720p' | '1080p' | '1440p' | '4k') | undefined, generate_audio?: boolean | undefined, camera_motion?: ('dolly_in' | 'dolly_out' | 'dolly_left' | 'dolly_right' | 'jib_up' | 'jib_down' | 'static' | 'focus_shift') | undefined, end_image?: (string | null) | undefined}}; export type CreateApiGenerateVideoLightricksLtxVideo25FastOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiGenerateVideoLightricksLtxVideo25FastResponse = z.object({job_id: z.string(), status: z.enum(["backlogged", "queued", "scheduled", "processing", "sampling", "intermediate-complete", "completed", "failed", "cancelled"]), created_at: z.string(), completed_at: z.unknown(), result: z.unknown(), error: z.object({code: z.string(), message: z.string().optional(), param: z.string().optional()}).optional(), progress: z.number().gte(0).lte(1).nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * LTX-2.5 Fast * * POST /generate/video/lightricks/ltx-video-2.5-fast */ export const createApiGenerateVideoLightricksLtxVideo25Fast = async (args: CreateApiGenerateVideoLightricksLtxVideo25FastArgs, options?: CreateApiGenerateVideoLightricksLtxVideo25FastOptions) => { const {baseUrl = "https://api.krea.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Webhook-URL'] != null) headers.set("X-Webhook-URL", String(args['X-Webhook-URL'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/generate/video/lightricks/ltx-video-2.5-fast${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiGenerateVideoLightricksLtxVideo25FastResponse, await res.json()) };