Package Exports
- @rohitaryal/whisk-api
- @rohitaryal/whisk-api/src/index.ts
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rohitaryal/whisk-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
whisk-api
An unofficial TypeScript/JavaScript API wrapper for Google Labs' Whisk image generation platform.
Features
- 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
Installation
bun i whisk-api
# or
npm i whisk-apiQuick Start
import Whisk from '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");
}Authentication
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
Supported Models
| 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 |
Examples
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
API Reference
Core Methods
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
Response Format
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);
}Development
# Install dependencies
bun install
# Run tests
bun test
# Set up environment
export COOKIE="your_cookie_here"Testing
The test suite requires a valid Google Labs cookie. Set the COOKIE environment variable and run:
bun testLimitations
- Requires valid Google Labs authentication
- Rate limiting applies based on Google's policies
- Regional availability may vary
- Unofficial API subject to changes
Contributing
Contributions are welcome. Please ensure all tests pass and follow the existing code style.
License
This project is for educational and research purposes. Please respect Google's terms of service when using this library.
Disclaimer
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.