import {z} from 'zod' export type CreateApiGenerateImageGoogleNanoBananaProArgs = {'X-Webhook-URL'?: string | undefined, body: {prompt: string, width?: number | undefined, height?: number | undefined, image_urls?: Array | undefined, aspect_ratio?: ('21:9' | '1:1' | '4:3' | '3:2' | '2:3' | '5:4' | '4:5' | '3:4' | '16:9' | '9:16') | undefined, resolution?: ('1K' | '2K' | '4K') | undefined}}; export type CreateApiGenerateImageGoogleNanoBananaProOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiGenerateImageGoogleNanoBananaProResponse = 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 }; /** * Nano Banana Pro * * POST /generate/image/google/nano-banana-pro */ export const createApiGenerateImageGoogleNanoBananaPro = async (args: CreateApiGenerateImageGoogleNanoBananaProArgs, options?: CreateApiGenerateImageGoogleNanoBananaProOptions) => { 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/image/google/nano-banana-pro${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(createApiGenerateImageGoogleNanoBananaProResponse, await res.json()) };