whiskapi
Version:
Unofficial API for Whisk image generation.
100 lines (99 loc) • 3.93 kB
TypeScript
import type { Credentials, FetchedImage, GenerationResult, ImageMetadata, Images, Projects, Prompt, RefinementRequest, Result } from "./global.types";
export default class Whisk {
#private;
credentials: Credentials;
constructor(credentials: Credentials);
/**
* Check if `Whisk` is available in your region.
*
* This un-availability can be easily bypassed by
* generating authorization token from a region where
* its available. Use VPN with US regions.
*/
isAvailable(): Promise<Result<boolean>>;
/**
* Generates the authorization token for the user.
* This generated token is required to make *most* of API calls.
*/
getAuthorizationToken(): Promise<Result<string>>;
/**
* Get the current credit status of the user. This is for `veo` only and not `whisk`.
*/
getCreditStatus(): Promise<Result<number>>;
/**
* Generates a new project ID (a unique identifier for each project) for the
* given title so that you can start generating images in that specific project.
*
* @param projectTitle The name you want to give to the project.
*/
getNewProjectId(projectTitle: string): Promise<Result<string>>;
/**
* Get all of your project history or library.
*
* @param limitCount The number of projects you want to fetch.
*/
getProjectHistory(limitCount: number): Promise<Result<Projects[]>>;
/**
* Get the image history of the user.
*
* @param limitCount The number of images you want to fetch.
*/
getImageHistory(limitCount: number): Promise<Result<Images[]>>;
/**
* Fetches the content of a project by its ID.
*
* @param projectId The ID of the project you want to fetch content from.
*/
getProjectContent(projectId: string): Promise<Result<ImageMetadata[]>>;
/**
* Rename a project title.
*
* @param newName New name for your project
* @param projectId Identifier for project that you need to rename
*/
renameProject(newName: string, projectId: string): Promise<Result<string>>;
/**
* Delete project(s) from libary
*
* @param projectIds Array of project id that you need to delete.
*/
deleteProjects(projectIds: string[]): Promise<Result<boolean>>;
/**
* Fetches the base64 encoded image from its media key (name).
* Media key can be obtained by calling: `getImageHistory()[0...N].name`
*
* @param mediaKey The media key of the image you want to fetch.
*/
getMedia(mediaKey: string): Promise<Result<FetchedImage>>;
/**
* Generates an image based on the provided prompt.
*
* @param prompt The prompt containing the details for image generation.
*/
generateImage(prompt: Prompt): Promise<Result<GenerationResult>>;
/**
* Refine a generated image.
*
* Refination actually happens in the followin way:
* 1. Client provides an image (base64 encoded) to refine with new prompt eg: "xyz".
* 2. Server responds with *a new prompt describing your image* eg: AI-Mix("pqr", "xyz")
* Where `pqr` - Description of original image
* 3. Client requests image re-generation as: AI-Mix("pqr", "xyz")
* 4. Server responds with new base64 encoded image
*/
refineImage(ref: RefinementRequest): Promise<Result<GenerationResult>>;
/**
* Save image to a file with the given name.
*
* @param image The base64 encoded image string.
* @param fileName The name of the file where the image will be saved.
*/
saveImage(image: string, fileName: string): Error | null;
/**
* Save image from its id directly
*
* @param imageId The ID of the image you want to save.
* @param fileName The name of the file where the image will be saved.
*/
saveImageDirect(imageId: string, fileName: string): Promise<Result<boolean>>;
}