An unofficial TypeScript/JavaScript API wrapper for Google Labs' Whisk image generation platform.
- Image Generation: Create high-quality images from text prompts
- Image Refinement: Enhance and modify existing generated images
- Project Management: Organize generations into projects with full CRUD operations
- Media Management: Access generation history and download images
- Multiple Models: Support for various Imagen models with different capabilities
- Type Safety: Full TypeScript support with comprehensive type definitions
bun i @rohitaryal/whisk-api
# or
npm i @rohitaryal/whisk-api
import Whisk from '@rohitaryal/whisk-api';
const whisk = new Whisk({
cookie: "your_google_labs_cookie_here"
});
// Generate an image
const result = await whisk.generateImage({
prompt: "A serene mountain landscape at sunset"
});
if (result.Ok) {
const imageData = result.Ok.imagePanels[0]?.generatedImages[0]?.encodedImage;
whisk.saveImage(imageData, "mountain_sunset.png");
}
You'll need to obtain your Google Labs session cookie:
- Visit labs.google/fx/tools/whisk
- Open browser developer tools (F12)
- Go to Application/Storage → Cookies
- Copy the cookie value and use it in your configuration
Model | Description | Capabilities |
---|---|---|
Imagen 2 | Second generation model | Standard quality image generation |
Imagen 3 | Third generation model | Improved quality and prompt adherence |
Imagen 3.1 | Enhanced version of Imagen 3 | Better detail rendering |
Imagen 4 | Latest generation model | Highest quality, best prompt understanding |
Imagen 3 Portrait | Portrait-optimized variant | Specialized for portrait generation |
Imagen 3 Landscape | Landscape-optimized variant | Specialized for landscape generation |
Imagen 3 Portrait 3:4 | Portrait with 3:4 aspect ratio | Fixed aspect ratio portraits |
Imagen 3 Landscape 4:3 | Landscape with 4:3 aspect ratio | Fixed aspect ratio landscapes |
The library includes comprehensive examples in the examples/
directory:
- Getting authorization tokens
- Checking credit status
- Creating projects
- Managing project history
- Project content management
- Deleting projects
- Renaming projects
- Image generation history
- Saving images
- Basic image generation
- Image refinement
generateImage(prompt)
- Generate images from text promptsrefineImage(refinementRequest)
- Refine existing images with new promptsgetProjectHistory(limit)
- Retrieve project historygetImageHistory(limit)
- Retrieve image generation historygetNewProjectId(title)
- Create new projectsdeleteProjects(projectIds)
- Delete multiple projectsrenameProject(newName, projectId)
- Rename existing projectssaveImage(base64Data, fileName)
- Save images to diskgetAuthorizationToken()
- Generate authentication tokens
All methods return a Result<T>
type with either:
Ok
: Contains the successful response dataErr
: Contains error information
const result = await whisk.generateImage({ prompt: "example" });
if (result.Err) {
console.error("Generation failed:", result.Err);
} else {
console.log("Success:", result.Ok);
}
# Install dependencies
bun install
# Set up environment
export COOKIE="your_cookie_here"
# Run tests
bun test
The test suite requires a valid Google Labs cookie. Set the COOKIE
environment variable and run:
bun test
- Requires valid Google's logged in cookies.
- Regional availability may vary
- Unofficial API subject to changes
Contributions are welcome. Please ensure all tests pass and follow the existing code style.
This project is for educational and research purposes. Please respect Google's terms of service when using this library.
This is an unofficial API wrapper and is not affiliated with Google. Use at your own risk and ensure compliance with Google's terms of service.