A powerful command-line tool for generating images and videos via Higgsfield.ai's API, built through reverse-engineering their web application.
Higgsfield CLI (hf) lets you generate AI images and videos from your terminal using Higgsfield.ai's free tier. It bypasses Cloudflare protection using TLS fingerprinting and implements the Clerk authentication flow to access generation endpoints directly.
Key Features:
- π Full authentication via Clerk (email/password + device verification)
- π― Direct API access to multiple generation models
- π Cloudflare bypass using browser TLS impersonation
- πΎ Session persistence (login once, use forever)
- π Credit tracking and usage history
- π¨ Multiple models: Z-Image, Soul, Flux-2, GPT, and video models
- π Automatic JWT token refresh
- Simple Text-to-Image: Generate images from prompts in seconds
- Text-to-Video (Kling 3.0): Generate videos from prompts via
/jobs/v2/kling3_0 - Multiple Models: Access Z-Image, Soul (stylized), Flux-2, GPT-based models, and more
- Video Generation: Foundation in place for additional image-to-video and text-to-video models
- Customization: Control dimensions, aspect ratios, seeds for reproducibility
- Account Management: Check credits, view generation history
- Session Persistence: Login once, stored securely in
~/.config/hf/ - Rich Terminal UI: Beautiful progress bars and formatted output
- Python 3.10 or higher
- pip (Python package installer)
- Higgsfield.ai account (free tier works)
git clone https://github.com/yourusername/higgsfield-cli.git
cd higgsfield-clipython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtOr install in development mode:
pip install -e .- curl_cffi β HTTP client with browser TLS fingerprinting (bypasses Cloudflare)
- click β Command-line interface framework
- rich β Beautiful terminal formatting and progress bars
Get up and running in 3 commands:
# 1. Login to your Higgsfield account
hf login
# 2. Generate your first image
hf generate "a cyberpunk cityscape at night with neon lights"
# 3. Check your remaining credits
hf statusAuthenticate with your Higgsfield.ai account.
hf loginWhat happens:
- You'll be prompted for your email and password
- First login: A 6-digit verification code will be sent to your email
- Enter the code to verify your device
- Session is saved to
~/.config/hf/session.json(secure permissions) - Future logins are automatic until session expires (~1 year)
Example:
$ hf login
Email: your.email@example.com
Password: ********
π Starting login...
π§ Verification code sent to your.email@example.com
Enter the 6-digit code from your email: 123456
β Login successful!
Generate an image from a text prompt.
Alias: hf gen
hf generate "a serene mountain landscape at sunset" [OPTIONS]Options:
| Option | Short | Default | Description |
|---|---|---|---|
--model |
-m |
z-image |
Model to use (see Available Models) |
--width |
-w |
1024 |
Image width in pixels |
--height |
-h |
1024 |
Image height in pixels |
--aspect-ratio |
-a |
1:1 |
Aspect ratio (1:1, 16:9, 9:16, 4:3, etc.) |
--seed |
-s |
Random | Random seed for reproducibility |
--output |
-o |
Auto | Output file path (default: hf_<timestamp>.png) |
Examples:
# Basic generation (1024x1024, Z-Image model)
hf generate "a cute red panda eating bamboo"
# Custom dimensions and aspect ratio
hf generate "wide cinematic landscape" --width 1920 --height 1080 --aspect-ratio 16:9
# Use a specific seed for reproducibility
hf generate "abstract art" --seed 42
# Save to specific location
hf generate "portrait of a cat" --output ~/Desktop/cat.png
# Use a different model
hf generate "stylized portrait" --model soulGenerate a video from a text prompt (currently Kling 3.0).
hf video "a cool video" [OPTIONS]Options:
| Option | Short | Default | Description |
|---|---|---|---|
--model |
-m |
kling3_0 |
Video model (kling3_0) |
--aspect-ratio |
-a |
16:9 |
Aspect ratio (16:9, 9:16, 1:1, etc.) |
--duration |
-d |
5 |
Duration in seconds |
--mode |
std |
Generation mode | |
--sound |
on |
Enable/disable sound (on/off) |
|
--cfg-scale |
0.5 |
CFG scale | |
--no-enhance-prompt |
false |
Disable prompt enhancement | |
--use-free-gens |
false |
Use free generations pool if available | |
--use-unlim |
false |
Use unlimited pool if available | |
--start-image |
None | Optional local reference image path (uploaded automatically) | |
--end-image |
None | Optional local end-frame image path (uploaded automatically) | |
--output |
-o |
Auto | Output file path (default: hf_<timestamp>.mp4) |
Examples:
# Basic video generation
hf video "a cool video"
# Vertical short with sound disabled
hf video "cinematic drone shot of a volcano" --aspect-ratio 9:16 --duration 5 --sound off
# Use a reference image (image-conditioned video)
hf video "animate this scene with subtle camera motion" --start-image ./frame.png
# Interpolate between start and end images
hf video "morph day scene into night scene" --start-image ./start.png --end-image ./end.png
# Save to specific file
hf video "cyberpunk alley with rain" --output ~/Desktop/clip.mp4List all available generation models.
hf modelsOutput:
βββββββββ¬ββββββββββββ¬ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β Kind β ID β Name β Description β
βββββββββΌββββββββββββΌββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ€
β image β z-image β Z-Image β Simple, fast image generation β
β image β soul β Soul Standard β Stylized generation (style_id) β
β image β flux-2 β Flux 2 β Advanced model (input_images) β
β image β gpt β GPT Image β OpenAI-based generation β
β video β kling3_0 β Kling 3.0 β Text-to-video generation β
βββββββββ΄ββββββββββββ΄ββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββ
Show your account information and credit balance.
hf statusOutput:
ββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β Property β Value β
ββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ€
β Email β your.email@example.com β
β Session File β /home/user/.config/hf/session.json β
β Credits β 8 β
β Plan β Free β
ββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ
View your recent generations.
hf history [--limit N]Options:
--limit/-nβ Number of items to show (default: 10)
Example:
hf history --limit 5Output:
ββββββββββββββββββββ¬ββββββββββ¬βββββββββββββββββββββββββ¬ββββββββββββ
β Created β Model β Prompt β Status β
ββββββββββββββββββββΌββββββββββΌβββββββββββββββββββββββββΌββββββββββββ€
β 2026-02-13 14:32 β z-image β a cute red panda... β completed β
β 2026-02-13 14:15 β z-image β cyberpunk cityscape β completed β
β 2026-02-13 13:45 β soul β stylized portrait β completed β
ββββββββββββββββββββ΄ββββββββββ΄βββββββββββββββββββββββββ΄ββββββββββββ
Higgsfield CLI supports multiple generation endpoints. Note: Some models require additional parameters not yet exposed in the CLI.
| Model ID | Endpoint | Description | Input Requirements | Status |
|---|---|---|---|---|
| z-image | /jobs/z-image |
Fast, simple text-to-image | Prompt only | β Fully supported |
| soul | /jobs/text2image-soul |
Stylized generation | Prompt + style_id |
|
| flux-2 | /jobs/flux-2 |
Advanced Flux model | Prompt + input_images |
|
| gpt | /jobs/text2image-gpt |
OpenAI-based generation | Prompt | β Supported |
| nano-banana-2 | /jobs/nano-banana-2 |
Nano Banana variant | Prompt + input_images |
|
| nano-banana-2-static | /jobs/nano-banana-2-static |
Static variant | Prompt + input_images |
|
| seedream | /jobs/seedream |
Seedream model | Prompt + input_images |
|
| seedream-v4-5 | /jobs/seedream-v4-5 |
Seedream v4.5 | Prompt + input_images + quality |
|
| openai-hazel | /jobs/openai-hazel |
OpenAI Hazel | Prompt |
| Model ID | Endpoint | Description | Input Requirements |
|---|---|---|---|
| kling3_0 | /jobs/v2/kling3_0 |
Kling 3.0 text-to-video | Prompt + video config |
| image2video | /jobs/image2video |
Convert image to video | Input image |
| kling | /jobs/kling |
Kling video model | Input configuration |
| veo3 | /jobs/veo3 |
Veo3 video generation | Input configuration |
| wan2-5-video | /jobs/wan2-5-video |
Wan 2.5 video model | Input configuration |
| minimax-hailuo | /jobs/minimax-hailuo |
MiniMax Hailuo | Input configuration |
| sora2-video | /jobs/sora2-video |
Sora 2 video generation | Input configuration |
| seedance | /jobs/seedance |
SeeDance video model | Input configuration |
Note: kling3_0 is exposed via hf video. Other video models still require additional model-specific parameters and are not yet first-class CLI commands.
When --start-image and/or --end-image is provided, the CLI performs:
POST /media/batchto mint a media ID + presigned upload URLPUT <upload_url>with your local image bytes- Best-effort finalize via
POST /media/{id}/upload POST /jobs/v2/kling3_0with media roles inparams.medias(e.g.start_image,end_image)
Higgsfield CLI works by replicating the web application's authentication and API flows:
Higgsfield.ai uses Clerk for authentication. The login process:
- Sign-In Identify:
POST /v1/client/sign_inswith your email (identifier) - First Factor (Password):
POST /v1/client/sign_ins/{id}/attempt_first_factor - Device Verification (Optional): If required, prepare + attempt
email_codesecond factor - Session + Token Refresh: Successful auth returns a session ID and
__clientcookie; JWTs expire in ~60 seconds, refreshed viaPOST /v1/client/sessions/{sid}/tokens
Key Insight: The __client cookie on .clerk.higgsfield.ai is long-lived (~1 year). Session persistence uses this cookie + session ID.
Higgsfield's API is protected by Cloudflare, which blocks standard Python HTTP clients (requests, urllib3, httpx) based on TLS fingerprints.
Solution: curl_cffi library provides browser TLS impersonation:
from curl_cffi import requests
session = requests.Session(impersonate="chrome131")This makes requests indistinguishable from a real Chrome 131 browser at the TLS layer.
Additional Warmup: Before API calls, the CLI hits https://higgsfield.ai to establish a Cloudflare session.
JWT tokens expire quickly (~60 seconds). The client:
- Loads saved session from
~/.config/hf/session.json - Before each API call, refreshes the JWT via Clerk's token endpoint
- Uses fresh JWT in
Authorization: Bearer {jwt}header
Image generation is asynchronous:
- Submit:
POST /jobs/{model-endpoint}with generation parameters- Returns job set ID
- Poll:
GET /job-sets/{job_set_id}every 2 seconds- Status progression:
queuedβin_progressβcompleted
- Status progression:
- Download: Extract CloudFront CDN URL from
jobs[0].results.raw.url- Download image directly to local filesystem
Token Management During Polling: JWT is refreshed every 20 poll cycles (~40 seconds) to prevent expiration during long generations.
- 10 credits per day (resets at midnight UTC)
- Each generation typically costs 1 credit
- Credit balance visible via
hf status
| Model | Credits per Generation |
|---|---|
| Z-Image | 1 |
| Soul | 1 |
| Flux-2 | 1-2 |
| Video models | 2-5 (varies) |
Note: Exact credit costs depend on parameters like resolution and batch size. Free tier limits may change.
Cause: No saved session or session expired.
Solution:
hf loginCause: Session expired or invalidated.
Solution:
- Delete old session:
rm ~/.config/hf/session.json - Re-login:
hf login
Cause: TLS fingerprint detection or rate limiting.
Solution:
- Ensure
curl_cffiis correctly installed with browser impersonation - Update impersonation target:
IMPERSONATE = "chrome131" # Try "safari15_5" or other browsers
- Add delays between requests
- Check if your IP is rate-limited (try different network)
Cause: Email in spam or Clerk rate limiting.
Solution:
- Check spam/junk folder
- Wait 60 seconds and try again
- Verify email address is correct
Cause: API queue delays or network issues.
Solution:
- Free tier may have longer queue times during peak hours
- Check your internet connection
- Try again later
- Increase timeout in code if needed (default: 2 minutes)
Cause: ~/.config/hf/session.json has wrong permissions.
Solution:
chmod 600 ~/.config/hf/session.jsonThis tool is unofficial and not affiliated with Higgsfield.ai.
- Built through reverse-engineering the web application's API
- Use at your own risk
- Respect Higgsfield's Terms of Service
- Free tier usage only (paid tier endpoints not tested)
- May break if Higgsfield updates their API or authentication
- Not responsible for account bans or API changes
Educational Purpose: This project demonstrates API reverse-engineering, Cloudflare bypass techniques, and OAuth flow implementation. Use responsibly.
MIT License
Copyright (c) 2026 Higgsfield CLI Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Contributions are welcome! Areas for improvement:
- Add support for
style_idparameter (Soul models) - Implement input image upload for Flux-2, Nano Banana models
- Add batch generation support
- Implement first-class
kling3_0video generation command (hf video) - Add first-class commands for remaining video models
- Add proxy support for additional CF bypass
- Better error messages and retry logic
- Configuration file for defaults
- Export history to JSON/CSV
- Higgsfield.ai β Official website
- curl_cffi Documentation β TLS impersonation library
- Clerk Documentation β Authentication platform
Enjoy generating! π¨
If you find this useful, consider starring the repo β