import {z} from 'zod' export type CogVideoX3Request = {model: 'cogvideox-3', prompt?: string | undefined, quality?: ('speed' | 'quality') | undefined, with_audio?: boolean | undefined, image_url?: (Array) | undefined, size?: ('1280x720' | '720x1280' | '1024x1024' | '1920x1080' | '1080x1920' | '2048x1080' | '3840x2160') | undefined, fps?: (30 | 60) | undefined, duration?: (5 | 10) | undefined, request_id?: string | undefined, user_id?: string | undefined}; export type CreateApiPaasV4VideosGenerationsArgs = {'Accept-Language'?: 'en-US,en' | undefined, body: CogVideoX3Request}; export type CreateApiPaasV4VideosGenerationsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const videoResponse = z.object({model: z.string().optional(), id: z.string().optional(), request_id: z.string().optional(), task_status: z.string().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 }; /** * CogVideoX is a video generation large model developed by Z.AI, equipped with powerful video generation capabilities. Simply inputting text or images allows for effortless video creation. * * POST /paas/v4/videos/generations */ export const createApiPaasV4VideosGenerations = async (args: CreateApiPaasV4VideosGenerationsArgs, options?: CreateApiPaasV4VideosGenerationsOptions) => { const {baseUrl = "https://api.z.ai/api", 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['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/paas/v4/videos/generations${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(videoResponse, await res.json()) };