wavespeed
Version:
WaveSpeed Client SDK for Wavespeed API
123 lines (122 loc) • 3.48 kB
TypeScript
/**
* Input parameters for image generation
*/
/**
* Prediction status
*/
export type PredictionStatus = 'created' | 'processing' | 'completed' | 'failed';
/**
* Prediction URLs
*/
export interface PredictionUrls {
get: string;
}
export interface UploadFileResp {
code: number;
message: string;
data: {
type: string;
download_url: string;
filename: string;
size: number;
};
}
/**
* Request options for fetch
*/
export interface RequestOptions extends RequestInit {
timeout?: number;
maxRetries?: number;
webhook?: string;
isUpload?: boolean;
filename?: string;
}
/**
* Prediction model representing an image generation job
*/
export declare class Prediction {
id: string;
model: string;
status: PredictionStatus;
input: Record<string, any>;
outputs: string[];
urls: PredictionUrls;
has_nsfw_contents: boolean[];
created_at: string;
error?: string;
executionTime?: number;
private client;
constructor(data: any, client: WaveSpeed);
/**
* Wait for the prediction to complete
*/
wait(): Promise<Prediction>;
/**
* Reload the prediction status
*/
reload(): Promise<Prediction>;
}
/**
* WaveSpeed client for generating images
*/
export declare class WaveSpeed {
private apiKey;
private baseUrl;
readonly pollInterval: number;
readonly timeout: number;
/**
* Create a new WaveSpeed client
*
* @param apiKey Your WaveSpeed API key (or set WAVESPEED_API_KEY environment variable)
* @param options Additional client options
*/
constructor(apiKey?: string, options?: {
baseUrl?: string;
pollInterval?: number;
timeout?: number;
});
/**
* Fetch with timeout support
*
* @param path API path
* @param options Fetch options
*/
fetchWithTimeout(path: string, options?: RequestOptions): Promise<Response>;
/**
* Calculate backoff time with exponential backoff and jitter
* @param retryCount Current retry attempt number
* @param initialBackoff Initial backoff time in ms
* @returns Backoff time in ms
* @private
*/
_getBackoffTime(retryCount: number, initialBackoff: number): number;
/**
* Generate an image and wait for the result
*
* @param modelId Model ID to use for prediction
* @param input Input parameters for the prediction
* @param options Additional fetch options
*/
run(modelId: string, input: Record<string, any>, options?: RequestOptions): Promise<Prediction>;
/**
* Create a prediction without waiting for it to complete
*
* @param modelId Model ID to use for prediction
* @param input Input parameters for the prediction
* @param options Additional fetch options
*/
create(modelId: string, input: Record<string, any>, options?: RequestOptions): Promise<Prediction>;
getPrediction(predictionId: string): Promise<Prediction>;
/**
* Upload a file (binary) to the /media/upload/binary endpoint
* @param filePath Absolute path to the file to upload
* @returns The API response JSON
*/
/**
* Upload a file (binary) to the /media/upload/binary endpoint (browser Blob version)
* @param file Blob to upload
* @returns The API response JSON
*/
upload(file: File | Blob, options?: RequestOptions): Promise<string>;
}
export default WaveSpeed;