@piapi/sdk
Version:
SDK for PIAPI
396 lines (378 loc) • 13.1 kB
text/typescript
interface PiapiConfig {
service_mode?: 'private' | 'public';
webhook_config?: {
endpoint: string;
secret: string;
};
}
interface CreateTaskRequest {
model: string;
task_type: TaskType;
input: Record<string, any>;
config?: PiapiConfig;
}
interface ResourceMetadata {
resource: string;
resource_without_watermark?: string;
height: number;
width: number;
duration: number;
}
interface BaseTaskWork {
status?: number;
type?: string;
content_type?: string;
}
interface VideoTaskWork extends BaseTaskWork {
content_type: 'video';
cover?: ResourceMetadata;
video?: ResourceMetadata;
}
interface ImageTaskWork extends BaseTaskWork {
content_type: 'image';
image: ResourceMetadata;
}
interface BaseTaskOutput {
type?: string;
status?: number;
works?: Array<VideoTaskWork | ImageTaskWork>;
}
interface VideoTaskOutput extends BaseTaskOutput {
video_url?: string;
}
interface ImageTaskOutput extends BaseTaskOutput {
image_url?: string;
image_base64?: string;
}
interface TryOnTaskOutput extends BaseTaskOutput {
works: Array<ImageTaskWork>;
}
interface HailuoTaskOutput extends BaseTaskOutput {
percent: number;
cover_url: string;
video_url: string;
download_url: string;
desc: string;
prompt_img_url: string;
status: number;
user_origin_prompt: boolean;
width: number;
height: number;
model_id: string;
message: string;
}
interface TaskResponse<T extends BaseTaskOutput = VideoTaskOutput | HailuoTaskOutput> {
code: number;
message: string;
data: {
task_id: string;
model: string;
task_type: TaskType;
status: TaskStatus;
input: Record<string, any>;
output: T | null;
error?: {
code: number;
message: string;
raw_message?: string;
detail?: any;
};
meta?: {
created_at: string;
started_at: string;
ended_at: string;
usage: {
type: string;
frozen: number;
consume: number;
};
is_using_private_pool: boolean;
};
detail?: any;
logs?: any[];
};
}
type BaseTaskType = 'video_generation' | 'extend_video' | 'lip_sync' | 'ai_try_on' | 'face-swap' | 'image_to_video';
type TaskType = BaseTaskType | string;
type TaskStatus = 'completed' | 'failed' | 'pending' | 'processing' | 'staged';
interface CreateTaskInput {
prompt: string;
negative_prompt?: string;
cfg_scale?: number;
duration: number;
aspect_ratio: string;
camera_control?: any;
mode?: string;
version?: string;
image_url?: string;
image_tail_url?: string;
origin_task_id?: string;
local_dubbing_url?: string;
tts_text?: string;
tts_speed?: number;
tts_timbre?: string;
}
interface Logger {
debug(message: string, ...args: any[]): void;
info(message: string, ...args: any[]): void;
warn(message: string, ...args: any[]): void;
error(message: string, ...args: any[]): void;
}
declare class PIAPI {
protected apiKey: string;
protected baseUrl: string;
protected logger: Logger;
constructor(apiKey: string, baseUrl?: string);
enableDebug(enable?: boolean): void;
protected request<T>(endpoint: string, options?: RequestInit): Promise<T>;
protected createTask<T extends BaseTaskOutput>(request: CreateTaskRequest): Promise<TaskResponse<T>>;
getTask<T extends BaseTaskOutput>(taskId: string): Promise<TaskResponse<T>>;
protected waitForTask<T extends BaseTaskOutput>(taskId: string, options?: {
maxAttempts?: number;
interval?: number;
}): Promise<TaskResponse<T>>;
protected createTaskAndWait<T extends BaseTaskOutput>(request: CreateTaskRequest, options?: {
maxAttempts?: number;
interval?: number;
}): Promise<TaskResponse<T>>;
}
declare namespace Kling {
type AspectRatio = '1:1' | '16:9' | '9:16';
type Mode = 'std' | 'pro';
type Version = '1.0' | '1.5' | '1.6' | '2.0' | '2.1' | '2.1-master';
type Duration = 5 | 10;
interface CameraControl {
type: string;
config: {
horizontal: number;
pan: number;
roll: number;
tilt: number;
vertical: number;
zoom: number;
};
}
interface BaseParams {
prompt: string;
negative_prompt?: string;
duration?: Duration;
aspect_ratio?: AspectRatio;
mode?: Mode;
version?: Version;
cfg_scale?: number;
camera_control?: CameraControl;
}
interface TextToVideoParams extends BaseParams {
aspect_ratio?: AspectRatio;
}
interface ImageToVideoParams extends BaseParams {
image_url: string;
image_tail_url?: string;
}
interface Config {
webhookUrl?: string;
webhookSecret?: string;
}
interface VirtualTryonParams {
model_input: string;
dress_input?: string;
upper_input?: string;
lower_input?: string;
batch_size?: number;
}
interface VideoTaskOutput extends BaseTaskOutput {
video_url: string;
works: Array<VideoTaskWork>;
}
interface TextToVideoOutput extends VideoTaskOutput {
}
interface ImageToVideoOutput extends VideoTaskOutput {
}
interface ImageElement {
image_url: string;
}
interface ElementsToVideoParams extends BaseParams {
elements: ImageElement[];
aspect_ratio?: AspectRatio;
}
type EffectName = 'squish' | 'expansion' | 'jellycat_oversea' | 'spinoff' | 'rocket' | 'hearting' | 'fighting' | 'kissing' | 'hugging' | 'figure' | 'vstack' | 'surfing' | 'birthday' | 'water';
interface EffectParams {
image_url: string;
effect: EffectName;
prompt?: string;
professional_mode?: boolean;
}
interface EffectOutput extends BaseTaskOutput {
}
}
declare class KlingAPI extends PIAPI {
private config;
constructor(apiKey: string, config?: Kling.Config, baseUrl?: string);
private static DEFAULT_PARAMS;
private static DEFAULT_CAMERA;
private createKlingRequest;
textToVideo(params: Kling.TextToVideoParams): Promise<TaskResponse<Kling.TextToVideoOutput>>;
imageToVideo(params: Kling.ImageToVideoParams): Promise<TaskResponse<Kling.ImageToVideoOutput>>;
elementsToVideo(params: Kling.ElementsToVideoParams): Promise<TaskResponse<Kling.ImageToVideoOutput>>;
getTextToVideoTask(taskId: string): Promise<TaskResponse<Kling.TextToVideoOutput>>;
getImageToVideoTask(taskId: string): Promise<TaskResponse<Kling.ImageToVideoOutput>>;
getElementsToVideoTask(taskId: string): Promise<TaskResponse<Kling.ImageToVideoOutput>>;
}
declare class KlingTryonAPI extends PIAPI {
private config;
constructor(apiKey: string, config?: Kling.Config, baseUrl?: string);
private static DEFAULT_PARAMS;
private createTryonRequest;
tryOn(params: Kling.VirtualTryonParams): Promise<TaskResponse>;
tryOnAndWait(params: Kling.VirtualTryonParams, options?: {
maxAttempts?: number;
interval?: number;
}): Promise<TaskResponse>;
}
declare class KlingEffectsAPI extends PIAPI {
private config;
constructor(apiKey: string, config?: Kling.Config, baseUrl?: string);
private static EFFECTS_CONFIG;
private createEffectsRequest;
applyEffect(params: Kling.EffectParams): Promise<TaskResponse<Kling.EffectOutput>>;
applyEffectAndWait(params: Kling.EffectParams, options?: {
maxAttempts?: number;
interval?: number;
}): Promise<TaskResponse<Kling.EffectOutput>>;
getEffectTask(taskId: string): Promise<TaskResponse<Kling.EffectOutput>>;
static getEffectConfig(effect: Kling.EffectName): {
stdMode: boolean;
proMode: boolean;
requiresPrompt: boolean;
};
static getAvailableEffects(): Kling.EffectName[];
static getEffectsByMode(professionalMode?: boolean): Kling.EffectName[];
}
type LumaAspectRatio = '16:9' | '9:16' | '1:1';
interface LumaBaseParams {
prompt: string;
expand_prompt?: boolean;
loop?: boolean;
image_url?: string;
aspect_ratio?: LumaAspectRatio;
}
interface LumaConfig {
webhookUrl?: string;
webhookSecret?: string;
}
declare class LumaAPI extends PIAPI {
private config;
constructor(apiKey: string, config?: LumaConfig, baseUrl?: string);
private static DEFAULT_PARAMS;
private createLumaRequest;
createVideo(params: LumaBaseParams): Promise<TaskResponse>;
}
interface FaceSwapConfig {
webhookUrl?: string;
webhookSecret?: string;
}
interface FaceSwapParams {
target_image: string;
swap_image: string;
}
interface FaceSwapOutput extends BaseTaskOutput {
image_url: string;
image_base64?: string;
}
declare class FaceSwapAPI extends PIAPI {
private config;
constructor(apiKey: string, config?: FaceSwapConfig, baseUrl?: string);
private createFaceSwapRequest;
faceSwap(params: FaceSwapParams): Promise<TaskResponse<FaceSwapOutput>>;
faceSwapAndWait(params: FaceSwapParams, options?: {
maxAttempts?: number;
interval?: number;
}): Promise<TaskResponse<FaceSwapOutput>>;
getFaceSwapTask(taskId: string): Promise<TaskResponse<FaceSwapOutput>>;
}
type HailuoModel = 'i2v-01' | 'i2v-01-live' | 't2v-01' | 's2v-01';
interface HailuoConfig {
webhookUrl?: string;
webhookSecret?: string;
}
interface HailuoBaseParams {
prompt?: string;
expand_prompt?: boolean;
}
interface HailuoTextToVideoParams extends HailuoBaseParams {
model: 't2v-01';
prompt: string;
image_url?: never;
}
interface HailuoImageToVideoParams extends HailuoBaseParams {
model: 'i2v-01' | 'i2v-01-live';
image_url: string;
}
interface HailuoSubjectToVideoParams extends HailuoBaseParams {
model: 's2v-01';
prompt: string;
image_url: string;
}
type HailuoVideoParams = HailuoTextToVideoParams | HailuoImageToVideoParams | HailuoSubjectToVideoParams;
declare class HailuoAPI extends PIAPI {
private config;
constructor(apiKey: string, config?: HailuoConfig, baseUrl?: string);
private validateImageUrl;
private createHailuoRequest;
generateVideo(params: HailuoVideoParams): Promise<TaskResponse<HailuoTaskOutput>>;
getVideoTask(taskId: string): Promise<TaskResponse<HailuoTaskOutput>>;
}
interface AIHugConfig {
webhookUrl?: string;
webhookSecret?: string;
}
interface AIHugVideoParams {
image_url: string;
duration?: number;
}
interface AIHugTaskOutput extends BaseTaskOutput {
video_url: string;
type: string;
status: number;
works: VideoTaskWork[];
}
declare class AIHugAPI extends PIAPI {
private config;
constructor(apiKey: string, config?: AIHugConfig, baseUrl?: string);
private validateImageUrl;
private createAIHugRequest;
generateVideo(params: AIHugVideoParams): Promise<TaskResponse<AIHugTaskOutput>>;
getVideoTask(taskId: string): Promise<TaskResponse<AIHugTaskOutput>>;
}
declare namespace Wanx {
type AspectRatio = '16:9' | '9:16';
type TaskType = 'txt2video-1.3b' | 'txt2video-14b' | 'img2video-14b';
interface Config {
webhookUrl?: string;
webhookSecret?: string;
}
interface BaseParams {
prompt: string;
negative_prompt?: string;
aspect_ratio?: AspectRatio;
}
interface TextToVideoParams extends BaseParams {
}
interface ImageToVideoParams extends BaseParams {
image: string;
}
interface VideoTaskOutput extends BaseTaskOutput {
video_url: string;
works?: Array<VideoTaskWork>;
}
}
declare class WanxAPI extends PIAPI {
private config;
private static readonly MODEL_NAME;
constructor(apiKey: string, config?: Wanx.Config, baseUrl?: string);
private createWanxRequest;
textToVideo(params: Wanx.TextToVideoParams, modelSize?: '1.3b' | '14b'): Promise<TaskResponse<Wanx.VideoTaskOutput>>;
imageToVideo(params: Wanx.ImageToVideoParams): Promise<TaskResponse<Wanx.VideoTaskOutput>>;
getVideoTask(taskId: string): Promise<TaskResponse<Wanx.VideoTaskOutput>>;
}
export { AIHugAPI, type AIHugConfig, type AIHugTaskOutput, type AIHugVideoParams, type BaseTaskOutput, type BaseTaskType, type BaseTaskWork, type CreateTaskInput, type CreateTaskRequest, FaceSwapAPI, type FaceSwapConfig, type FaceSwapOutput, type FaceSwapParams, HailuoAPI, type HailuoBaseParams, type HailuoConfig, type HailuoImageToVideoParams, type HailuoModel, type HailuoSubjectToVideoParams, type HailuoTaskOutput, type HailuoTextToVideoParams, type HailuoVideoParams, type ImageTaskOutput, type ImageTaskWork, Kling, KlingAPI, KlingEffectsAPI, KlingTryonAPI, LumaAPI, type LumaAspectRatio, type LumaBaseParams, type LumaConfig, PIAPI, type PiapiConfig, type ResourceMetadata, type TaskResponse, type TaskStatus, type TaskType, type TryOnTaskOutput, type VideoTaskOutput, type VideoTaskWork, Wanx, WanxAPI };