Skip to content

rohitaryal/imageFX-api

Repository files navigation

imageFX-api

Unofficial reverse engineered api for imageFX service provided by labs.google


Golang version can be found here
Whisk API client can be found here

Tip

Please refer to HELP section to to extract cookies, authentication token.

Installation

npm i -g @rohitaryal/imagefx-api

Usage

Command Line
imagefx --prompt "purple cat" --cookie "$COOKIE"

You can also use authentication token instead.

imagefx --prompt "purple cat" --auth "$TOKEN"

If one is present the other one is optional, but generating new authentication token will require cookies. So, its better to use the first one since it generates authentication token internally.

Full Usage Options:

Usage: imagefx [options]

Options:
  --version        Show version number                      [boolean]
  --auth           Authentication token for generating images [string]
  --cookie         Cookie (for auto auth token generation)   [string]
  --seed           Seed for reference image                  [number] [default: null]
  --count          Number of images to generate              [number] [default: 4]
  --prompt         Prompt for image generation               [string] [required]
  --dir            Directory to save images                  [string] [default: "."]
  --model          Model to use for generation                [string] [default: IMAGEN_4]
                   Choices: IMAGEN_2, IMAGEN_3, IMAGEN_4,
                            IMAGEN_3_1, IMAGEN_3_5,
                            IMAGEN_2_LANDSCAPE, IMAGEN_3_PORTRAIT,
                            IMAGEN_3_LANDSCAPE, IMAGEN_3_PORTRAIT_THREE_FOUR,
                            IMAGEN_3_LANDSCAPE_FOUR_THREE,
                            IMAGE_MODEL_NAME_UNSPECIFIED
  --ratio          Aspect ratio                               [string] [default: IMAGE_ASPECT_RATIO_LANDSCAPE]
                   Choices: IMAGE_ASPECT_RATIO_SQUARE,
                            IMAGE_ASPECT_RATIO_PORTRAIT,
                            IMAGE_ASPECT_RATIO_LANDSCAPE,
                            IMAGE_ASPECT_RATIO_UNSPECIFIED,
                            IMAGE_ASPECT_RATIO_LANDSCAPE_FOUR_THREE,
                            IMAGE_ASPECT_RATIO_PORTRAIT_THREE_FOUR
  --help           Show help                                [boolean]
Importing as module
import * as fs from "fs";
import ImageFx from "@rohitaryal/imagefx-api";


const fx = new ImageFx({
  authorizationKey: process.env.TOKEN
});

const resp = await fx.generateImage({
  prompt: "A sigma crocodile, showing off his rizz"
});

if(resp.Err || !resp.Ok) { // Failed
    console.log(resp.Err)
    process.exit(1);
}


resp.Ok.forEach((image, index) => {
  fs.writeFileSync(`image-${index + 1}.png`, image.encodedImage, "base64")
})

Note: All function return Result<T> and it consists of:

  • Ok: T - If it was success, result will be here
  • Err: Error - In case of failure, error message will be here

Help

How to extract cookies?
  1. Open labs.google, make sure you are logged in
  2. Press CTRL + SHIFT + I to open console
  3. Click on Application tab at top of console
  4. At lower left section, double click on Cookies
  5. Click on the https://labs.google
  6. Copy the corresponding value of __Secure-next-auth.session-token
How to obtain authentication token?
  1. Open labs.google, make sure you are logged in
  2. Press CTRL + SHIFT + I to open console
  3. Paste the following code into console
let script = document.querySelector("#__NEXT_DATA__");
let obj = JSON.parse(script.textContent);
let authToken = obj["props"]["pageProps"]["session"]["access_token"];

window.prompt("Copy the auth token: ", authToken);
  1. Copy the content from the prompt box.
ImageFX not available on your region?
  1. Connect to a VPN with US regions
  2. Login to labs.google
  3. Follow above guide to extract the Authentication Token and not the cookies.

Contributions

Contribution are welcome but ensure to pass all test cases and follow existing coding standard.

Desclaimer

This project demonstrates usage of Google's private API but is not affiliated with Google. Use at your own risk.

About

Unofficial reverse engineered api for imageFX from labs.google

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •