grok-image-cliGenerate and edit images via Grok API from the command line. Cross-platform secure credential storage for xAI API key. Supports batch generation, aspect rati...
Install via ClawdBot CLI:
clawdbot install cyberash-dev/grok-image-cliInstall grok-image-cli via npm:
Install grok-image-cli via npmInstall from source (audit before running):
Install from source (audit before running)Requires:
A CLI for generating and editing images using the xAI Grok API. Supports multiple models: grok-imagine-image (default), grok-imagine-image-pro, grok-2-image-1212. Powered by the official @ai-sdk/xai SDK. Credentials are stored in the OS native credential store (macOS Keychain, Windows Credential Manager, Linux Secret Service) via cross-keychain.
Requires Node.js >= 20.19.0. Works on macOS, Windows, and Linux. The package is fully open source under the MIT license: https://github.com/cyberash-dev/grok-image-cli
npm install -g grok-image-cli
The npm package is published with provenance attestation, linking each release to its source commit via GitHub Actions. You can verify the published contents before installing:
npm pack grok-image-cli --dry-run
Install from source (if you prefer to audit the code before running):
git clone https://github.com/cyberash-dev/grok-image-cli.git
cd grok-image-cli
npm install && npm run build && npm link
After installation the grok-img command is available globally.
grok-img auth login # Interactive prompt: enter xAI API key
grok-img generate "A futuristic city skyline at night" # Generate with default model
grok-img generate "A futuristic city skyline at night" -m grok-imagine-image-pro # Use pro model
grok-img edit "Make it a watercolor painting" -i ./photo.jpg # Edit an existing image
Store API key (interactive prompt):
grok-img auth login
Show stored key (masked) and source:
grok-img auth status
Remove key from credential store:
grok-img auth logout
The CLI also supports the XAI_API_KEY environment variable as a fallback when no credential store entry is found.
grok-img generate "A collage of London landmarks in street-art style"
grok-img generate "Mountain landscape at sunrise" -n 4 -a 16:9
grok-img generate "A serene Japanese garden" -o ./my-images
grok-img generate "Photorealistic portrait" -m grok-imagine-image-pro
grok-img generate "Abstract art" -m grok-2-image-1212
Edit a local file or a remote URL:
grok-img edit "Change the landmarks to New York City" -i ./landmarks.jpg
grok-img edit "Render as a pencil sketch" -i https://example.com/portrait.jpg
grok-img edit "Add a vintage film grain effect" -i ./photo.jpg -a 3:2 -o ./edited
generate| Flag | Description | Default |
|------|-------------|---------|
| -m, --model | Model (grok-imagine-image, grok-imagine-image-pro, grok-2-image-1212) | grok-imagine-image |
| -a, --aspect-ratio | Aspect ratio (1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, auto) | auto |
| -n, --count | Number of images to generate (1-10) | 1 |
| -o, --output | Output directory | ./grok-images |
edit| Flag | Description | Default |
|------|-------------|---------|
| -i, --image | Source image (local file path or URL) | required |
| -m, --model | Model (grok-imagine-image, grok-imagine-image-pro, grok-2-image-1212) | grok-imagine-image |
| -a, --aspect-ratio | Aspect ratio | auto |
| -o, --output | Output directory | ./grok-images |
The following properties are by design and can be verified in the source code:
cross-keychain (macOS Keychain / Windows Credential Manager / Linux Secret Service; service: grok-image-cli, account: api-key). By design, never written to disk in plaintext. If no credential store entry is found, the CLI falls back to the XAI_API_KEY environment variable. See src/infrastructure/adapters/credential-store.adapter.ts for the implementation.api.x.ai over HTTPS via the official @ai-sdk/xai SDK. When editing images with a remote URL (-i https://...), the SDK makes an additional outbound HTTPS request to fetch the source image. No other outbound connections are made by the CLI itself (npm/git fetches during installation are standard package manager behavior). See src/infrastructure/adapters/grok-api.adapter.ts../grok-images). No images are cached or uploaded elsewhere.This CLI wraps the xAI Image Generation API via the Vercel AI SDK:
POST /v1/images/generationsPOST /v1/images/editsDocumentation: https://docs.x.ai/docs/guides/image-generation
Generated Mar 1, 2026
Marketing teams can use this CLI to quickly generate custom images for social media posts, ads, and blog graphics. By scripting batch generation with specific aspect ratios and styles, they can produce branded visuals at scale without manual design work, saving time and resources.
Online retailers can edit product photos to apply different artistic styles or backgrounds, enhancing listings. For example, they could transform a plain product shot into a watercolor painting for a unique aesthetic, helping products stand out in crowded marketplaces.
Agencies can prototype visual concepts for clients by generating multiple image variations based on prompts. Using the CLI's batch capabilities, they can explore different models and aspect ratios to present options efficiently, streamlining the creative approval process.
Educators and content creators can generate custom illustrations for textbooks, presentations, or online courses. By editing existing images to match specific themes, they can produce engaging visuals that enhance learning materials without requiring graphic design expertise.
Individuals can use the CLI for personal projects like creating digital art, editing photos with style transfers, or generating images for personal blogs. The secure credential storage and command-line interface make it accessible for hobbyists to experiment with AI-generated imagery.
Offer a free tier with basic image generation and editing, then charge for advanced features like higher-resolution outputs, priority API access, or custom model training. Integrate with existing platforms via APIs to attract users who need scalable visual content.
License the CLI technology to large companies for internal use, such as marketing departments or product teams. Provide customization, support, and integration with enterprise systems, generating revenue through licensing fees and ongoing maintenance contracts.
Partner with AI service providers or cloud platforms to offer the CLI as a value-added tool. Earn commissions by driving API usage or referrals, while users benefit from seamless integration and enhanced functionality within broader ecosystems.
💬 Integration Tip
Leverage the CLI's cross-platform credential storage to simplify API key management in automated workflows, ensuring secure and consistent access across different operating systems.
Advanced filesystem operations - listing, searching, batch processing, and directory analysis for Clawdbot
Perform advanced filesystem tasks including listing, recursive searching by name or content, batch copying/moving/deleting files, and analyzing directory siz...
Essential SSH commands for secure remote access, key management, tunneling, and file transfers.
Extract text from PDF files for LLM processing
The directory for AI agent services. Discover tools, platforms, and infrastructure built for agents.
Advanced filesystem operations - listing, searching, batch processing, and directory analysis for Clawdbot