Chinese README: README-zh.md
Flow image generation command-line tool, supporting:
- Text-to-image / Image-to-image
- 2K / 4K upscaling
- Auto downgrade to original image on upscale failure with guaranteed save
- Local browser captcha (
personal) - Local token receiver service (works with
flow-token-updaterextension for automatic ST sync)
Project Notes:
- This project is inspired by Flow2API.
flow-token-updateris inspired by Flow2API-Token-Updater.
This repository is a lightweight, image-focused implementation for local use:
- Focuses on Flow image generation workflow (ST/AT, generate, optional upscale)
- Designed as CLI + local helper tools, not a full platform service
- Must be able to sign in to Google Flow: https://labs.google/fx
- Account must have image generation permissions (otherwise cannot generate images)
- For
-u 4k, account must have corresponding subscription/permissions (429/quota errors common without permissions)
flow-image-cli/
├── flow_cli/ # CLI main code
├── flow-token-updater/ # Browser extension
├── flow_token_server.py # Local token receiver service
├── config.toml # Config template
└── README.md
- Python 3.9+
- Chrome (for extension and personal mode)
- Access to Google Flow: https://labs.google/fx
cd flow-image-cli
pip install -r requirements.txt
pip install -e .pip install playwright
python -m playwright install chromiumpython flow_token_server.pyDefault address: http://127.0.0.1:8765/token
Highly recommended to use the built-in flow-token-updater extension to automatically maintain ST, avoiding manual copy/paste.
- Open
chrome://extensions/ - Enable Developer mode
- Click "Load unpacked"
- Select:
/flow-image-cli/flow-token-updater
- Open extension popup
- Set server URL to
http://127.0.0.1:8765/token - Save config and click "Fetch Now"
After obtaining ST, CLI will automatically use the st field from ~/.flow-cli/token.json.
Config path: ~/.flow-cli/config.toml
[flow]
labs_base_url = "https://labs.google/fx/api"
api_base_url = "https://aisandbox-pa.googleapis.com/v1"
timeout = 120
max_retries = 3
[output]
output_dir = "output"
[captcha]
method = "personal" # personal / none
personal_headless = true
personal_timeout = 90
personal_settle_seconds = 2.0
[debug]
enabled = falseToken path: ~/.flow-cli/token.json
Supported captcha.method values:
personal: Solve captcha using local browser (requires Playwright)none: Do not actively solve captcha (may fail when captcha is required)
This simplified project does not include built-in third-party captcha providers (such as YesCaptcha/CapMonster/Capsolver) by default.
Default personal_headless = true (silent headless, no browser popup); set to false only when visual debugging is needed.
Provides an interactive Python script for terminal configuration:
python interactive_generate.pySupports interactive configuration:
- Prompt
- Model (index or model name)
- Output path
- Reference image path
- Upscale option (
none/2k/4k) - Language mode (
中文 / English / 双语)
Default output path uses timestamp template: output/flow_{timestamp}.png (auto-expands timestamp to avoid overwriting).
Usage Notes:
- First ensure you can log in to Flow and your account has image generation permissions before running CLI.
-u 4kis not available for all accounts; requires corresponding subscription/permissions.
flow-cli login --st "your-session-token"flow-cli models
flow-cli credits
flow-cli config# Text-to-image
flow-cli gen "a cinematic cat in neon city"
# Specify model and output
flow-cli gen "mountain landscape" -m gemini-3.1-flash-image-landscape -o output\landscape.png
# Image-to-image
flow-cli gen "convert to watercolor style" -r input.jpg -o output\watercolor.png# Generate then upscale to 2K
flow-cli gen "a cat" -m gemini-3.1-flash-image-landscape -u 2k -o output\cat_2k.png
# Generate then upscale to 4K
flow-cli gen "a cat" -m gemini-3.1-flash-image-landscape -u 4k -o output\cat_4k.pngParameters:
-u, --upscale:none/2k/4k
Note:
- When
2k/4kupscale fails, the program automatically downgrades to original image and saves to-ospecified path.
import asyncio
from flow_cli.client import ImageGenerator
async def main():
g = ImageGenerator()
path = await g.generate(
prompt="a cinematic cat",
model="gemini-3.1-flash-image-landscape",
output_path="output/api_basic.png",
)
print(path)
asyncio.run(main())import asyncio
from pathlib import Path
from flow_cli.client import ImageGenerator
async def main():
g = ImageGenerator()
path = await g.generate(
prompt="convert to watercolor",
model="gemini-3.1-flash-image-landscape",
reference_image=Path("input.jpg").read_bytes(),
output_path="output/api_img2img_2k.png",
upscale="2k",
)
print(path)
asyncio.run(main())flow_token_server.py provides local HTTP interface for extension or script calls.
curl http://127.0.0.1:8765/healthResponse:
{"status":"ok"}curl http://127.0.0.1:8765/tokenResponse:
{"has_token": true, "token_length": 2147}curl -X POST http://127.0.0.1:8765/token ^
-H "Content-Type: application/json" ^
-d "{\"session_token\":\"your-st-token\"}"Response:
{"success":true,"message":"Token saved to ...","token_length":2147}Yes. Use -u 2k.
-u 4k requires account to have corresponding subscription/permissions.
On upscale failure, it automatically downgrades to original image and saves it.
- Ensure
captcha.method = "personal" - Ensure Playwright + Chromium is installed
- Ensure browser can access and is logged into Google Flow
- 401: Usually AT expired, program will auto-refresh and retry
- 500: Upstream occasional issue, recommend retry or switch model (prefer
gemini-3.1-flash-image-*)
The CLI reads config from ~/.flow-cli/config.toml (user's home directory), NOT from the project root config.toml.
Solutions:
- Copy your config to the default location:
mkdir -p ~/.flow-cli cp <your-project-path>/config.toml ~/.flow-cli/config.toml
- Or use environment variable:
export FLOW_CONFIG=/path/to/your/config.toml
flow-cli login --st "your-new-session-token"You can get ST from Flow Token browser extension.
- Install Playwright:
pip install playwright && python -m playwright install chromium - If browser doesn't open automatically, check if another Chrome instance is using the profile
- For headless mode issues, try setting
personal_headless = falsein config - Browser profile is stored at
~/.flow-cli/browser-profile
- Check if output directory exists and is writable
- Ensure sufficient disk space
- Check debug logs for more details (set
debug.enabled = truein config)
- Do not commit ST/AT to repository
- Do not expose full tokens in chat/screenshots
~/.flow-cli/token.jsonrecommended for local use only
- Google Flow: https://labs.google/fx/tools/flow
- Flow2API: https://github.com/TheSmallHanCat/flow2api
- Flow2API-Token-Updater: https://github.com/TheSmallHanCat/Flow2API-Token-Updater
MIT. See LICENSE.