Unofficial free reverse engineered api for imageFX(imagen) service provided by labs.google
npm i -g @rohitaryal/imagefx-apiimagefx can be invoked through both command line and as a module.
Command Line
Make sure you have:
- Installed
imagefxglobally (How to install?) - Obtained your google account cookies (How to get cookies?)
- Set env variable
GOOGLE_COOKIEcontaining your cookieexport GOOGLE_COOKIE="__YOUR__COOKIE__HERE__"
-
Generating image with prompt
# saves generated image at current directory imagefx generate --prompt "A bad friend" --cookie $GOOGLE_COOKIE
-
Selecting a specific model
# please refer to --help for listing all models imagefx generate --prompt "An evil company" --model "IMAGEN_3_5" --cookie $GOOGLE_COOKIE
-
Selecting a specific aspect ratio
# please refer to --help for listing all aspect ratio imagefx generate --prompt "Reptillian CEO" --size "PORTRAIT" --cookie $GOOGLE_COOKIE
-
Saving to specific destination
# it will automatically create non-existing directory if possible imagefx generate --prompt "Netflix but with less fees" --dir ~/Pictures --cookie $GOOGLE_COOKIE
-
You can also save image using its media id.
imagefx fetch "__MEDIA__ID__HERE__" --cookie $GOOGLE_COOKIE
Full generation help:
imagefx generate <options>
Options:
--version Show version number
-h, --help Show help
-p, --prompt Textual description of image to be generated
-m, --model Model to be used for image generation
-n, --count Number of images to generate
--size, --sz Aspect ratio of image to be generated
-s, --seed Seed value for image to be generated
-r, --retry Number of retries if in case fetch fails
-d, --dir Directory to save generated images
-c, --cookie Google account cookie
Full fetching help:
imagefx fetch <mediaId>
Positionals:
mediaId Unique ID of generated image
Options:
--version Show version number
-h, --help Show help
-d, --dir Directory to save generated images
-c, --cookie Google account cookie
Importing as module
-
Basic image generation
import ImageFx from "@rohitaryal/imagefx-api"; const fx = new ImageFX(process.env.GOOGLE_COOKIE); // Generate images const generatedImage = await fx.generateImage("A big black cockroach"); // Iterate over multiple images and save generatedImage.forEach(image => { const savedPath = image.save(".cache/"); console.log("[+] Image saved at: " + savedPath); });
-
More descriptive prompt
const fx = new ImageFX(GOOGLE_COOKIE); const prompt = new Prompt({ seed: 0, numberOfImages: 4, prompt: "A green spongebob", generationModel: "IMAGEN_3_5", aspectRatio: "IMAGE_ASPECT_RATIO_SQUARE", }); // Generate images const generatedImage = await fx.generateImage(prompt); // Iterate over generated images and save generatedImage.forEach(image => { const savedPath = image.save(".cache/"); console.log("[+] Image saved at: " + savedPath); });
More examples are at: /examples
How to extract cookies?
- Install Cookie Editor extension in your browser.
- Open labs.google, make sure you are logged in
- Click on Cookie Editor icon from Extensions section.
- Click on Export -> Header String
- Open labs.google, make sure you are logged in
- Press CTRL + SHIFT + I to open console
- Click on Network tab at top of console
- Press CTRL + L to clear network logs
- Click CTRL + R to refresh page
- Click on
image-fxwhich should be at top - Goto Request Headers section and copy all the content of Cookie
ImageFX not available in your country?
- Install a free VPN (Windscribe, Proton, etc)
- Open labs.google and login
- From here follow the "How to extract cookie?" in HELP section (above).
- Once you have obtained this cookie, you don't need VPN anymore.
Not able to generate images?
Create an issue here. Make sure the pasted logs don't contain cookie or tokens.
Contribution are welcome but ensure to pass all test cases and follow existing coding standard.
This project demonstrates usage of Google's private API but is not affiliated with Google. Use at your own risk.
