import {z} from 'zod' export type Seedance25Request = {mode?: ('text-to-video' | 'image-to-video' | 'media-to-video') | undefined, prompt: string, channel?: ('standard' | 'real' | 'wild') | undefined, aspect_ratio?: ('1:1' | '21:9' | '4:3' | '3:4' | '16:9' | '9:16' | 'adaptive') | undefined, duration?: ('auto' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30') | undefined, resolution?: ('480p' | '720p' | '1080p' | '1080p-plus') | undefined, image_url?: string | undefined, end_image_url?: string | undefined, media_urls?: Array | undefined, generate_audio?: boolean | undefined}; export type CreateApiApiV1VideoSeedance25Args = {'Idempotency-Key'?: string | undefined, body: Seedance25Request}; export type CreateApiApiV1VideoSeedance25Options = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1VideoSeedance25Response = z.object({id: z.string(), status: z.enum(["processing", "completed"]), model: z.literal("seedance25"), credits_used: z.number().optional(), remaining_credits: z.number().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 }; /** * Generate a Seedance 2.5 video * * POST /api/v1/video/seedance25 */ export const createApiApiV1VideoSeedance25 = async (args: CreateApiApiV1VideoSeedance25Args, options?: CreateApiApiV1VideoSeedance25Options) => { const {baseUrl = "https://www.seedance2ai.io", 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['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/video/seedance25${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(createApiApiV1VideoSeedance25Response, await res.json()) };