grok-image-cli
Generate and edit images via Grok API from the command line. Cross-platform secure credential storage for xAI API key. Supports batch generation, aspect ratios, and style transfer.
- License 许可
- MIT
- 最近更新
- 2026-06-07
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- grok-image-cli
- metadata
- { "clawdbot": { "os": [ "macos", "windows", "linux" ], "emoji": "🎨", "source": "https://github.com/cyberash-dev/grok-image-cli", "install": [ { "id": "npm", "bins": [ "grok-img" ], "kind": "shell", "label": "Install grok-image-cli via npm", "command": "npm install -g grok-image-cli" }, { "id": "source", "bins": [ "grok-img" ], "kind": "shell", "label": "Install from source (audit before running)", "command": "git clone https://github.com/cyberash-dev/grok-image-cli.git && cd grok-image-cli && npm install && npm run build && npm link" } ], "requires": { "env": { "XAI_API_KEY": { "required": false, "description": "xAI API key (fallback when no credential store entry exists)" } }, "bins": [ "grok-img", "node" ] }, "credentials": [ { "id": "xai-api-key", "label": "xAI API key", "account": "api-key", "service": "grok-image-cli", "storage": "cross-keychain", "env_fallback": "XAI_API_KEY" } ] } }
- description
- Generate and edit images via Grok API from the command line. Cross-platform secure credential storage for xAI API key. Supports batch generation, aspect ratios, and style transfer.
03 SKILL.md 正文
grok-image-cli
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.
Installation
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.
Quick Start
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
API Key Management
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.
Image Generation
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
Image Editing
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
Flag Reference
generate
| Flag | Description | Default |
|---|---|---|
-m, --model <model> |
Model (grok-imagine-image, grok-imagine-image-pro, grok-2-image-1212) | grok-imagine-image |
-a, --aspect-ratio <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> |
Number of images to generate (1-10) | 1 |
-o, --output <dir> |
Output directory | ./grok-images |
edit
| Flag | Description | Default |
|---|---|---|
-i, --image <path> |
Source image (local file path or URL) | required |
-m, --model <model> |
Model (grok-imagine-image, grok-imagine-image-pro, grok-2-image-1212) | grok-imagine-image |
-a, --aspect-ratio <ratio> |
Aspect ratio | auto |
-o, --output <dir> |
Output directory | ./grok-images |
Security and Data Storage
The following properties are by design and can be verified in the source code:
- xAI API key: stored in the OS native credential store via
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 theXAI_API_KEYenvironment variable. Seesrc/infrastructure/adapters/credential-store.adapter.tsfor the implementation. - No config files: all settings are passed via CLI flags. Nothing is stored on disk besides the credential store entry.
- Network: the API key is only sent to
api.x.aiover HTTPS via the official@ai-sdk/xaiSDK. 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). Seesrc/infrastructure/adapters/grok-api.adapter.ts. - Generated images: saved to the local output directory (default:
./grok-images). No images are cached or uploaded elsewhere.
API Reference
This CLI wraps the xAI Image Generation API via the Vercel AI SDK:
- Generation:
POST /v1/images/generations - Editing:
POST /v1/images/edits
Documentation: https://docs.x.ai/docs/guides/image-generation
04 同仓库更多 Skills
crowd-prompting
A marketplace where AI agents improve prompts, system instructions, tool descriptions, and other text-based content with domain expertise from real-world operations — and earn tokens for valuable contributions.
ceaser
Interact with the Ceaser privacy protocol on Base L2 using the ceaser-mcp MCP tools. This skill uses the ceaser-mcp npm package for ALL operations -- shield, unshield, note management, and protocol queries. All ceaser tool calls use CLI subcommands (npx -y ceaser-mcp <subcommand>). Ceaser is a privacy-preserving ETH wrapper using Noir/UltraHonk zero-knowledge proofs on Base L2 (chain ID 8453).
ceaser-send
Fully automated private ETH transfer via Ceaser Protocol on Base L2 using the ceaser-mcp MCP tools. This skill uses the ceaser-mcp npm package for ALL operations -- all ceaser tool calls use CLI subcommands (npx -y ceaser-mcp <subcommand>). WARNING -- creates observable on-chain links between user wallet and hot wallet (see Privacy Warning). Generates an ephemeral hot wallet with BIP-39 mnemonic recovery, user funds it, agent signs and broadcasts the Shield TX automatically. Exactly one manual step required (funding the hot wallet with ETH). Uses Noir/UltraHonk zero-knowledge proofs.
dilemm-ai
Compete in DilemmAI, the prisoner's dilemma AI arena at dilemm.ai. Use when an OpenClaw agent wants to create an account, design and submit strategy prompts for their bot, enter matchmaking, analyze historical matches and leaderboards, and iterate on bot strategy. Requires headless browser automation (no API available yet).
moldium
Post and manage content on the Moldium blog platform. Triggered by "post to Moldium", "write a blog post", "publish an article", etc.
arxiv-paper-reviews
Interact with arXiv Crawler API to fetch papers, read reviews, submit comments, search papers, and import papers. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, submitting paper reviews, searching papers by title, or importing papers from arXiv URLs via API at http://weakaccept.top:8000/.