This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
FAL CLI is an unofficial command-line interface for FAL AI Models that provides both traditional CLI usage and MCP (Model Context Protocol) server functionality for AI assistants. It enables high-quality image generation using models like FLUX, Imagen, and Qwen Image.
# Start the CLI application
npm start
npm run dev
node cli.js
# Run specific CLI commands
npm run models # List available models
npm run generate # Start image generation
npm run optimize # Optimize prompts
npm run config # Configure settings
# Start MCP server for AI assistants
npm run mcp-server # Start on default port 3001
PORT=3002 npm run mcp-server # Custom port
# Test CLI functionality
npm test # Shows help output
node cli.js --help # Command documentationThe project implements two parallel interfaces that share core business logic:
- CLI Interface (
cli.js): Traditional command-line interface with interactive prompts using Commander.js and Inquirer.js - MCP Server (
mcp-server.js): Protocol-based server for AI assistant integration using Model Context Protocol SDK
Both interfaces rely on shared core modules in the core/ directory to avoid code duplication.
core/image-generator.js: Handles all image generation logic
generateSingleImage(): Single image generation with FAL APIgenerateBatch(): Batch processing with concurrency controlcalculateCost(): Cost estimation before generation
core/prompt-optimizer.js: AI-powered prompt enhancement
optimizePrompt(): Single prompt optimization using LLMoptimizeBatch(): Batch prompt optimization with model-specific adjustments
core/model-manager.js: Model configuration and discovery
loadModels(): Loads model configurations from JSON filesgetModelById(): Retrieves specific model configurationgetFilteredModels(): Filters models by criteria (cost, category)getModelRecommendations(): Suggests optimal models for use cases
models-new.js: Model loader utilities
- Loads model configurations from
models/directory - Provides shared parameter definitions
- Handles model validation
secure-storage.js: API key management
- AES-256-GCM encryption for stored keys
- Machine-specific encryption keys
- Cross-platform secure storage locations
Models are defined as JSON files in the models/ directory with this structure:
- Model ID, pricing, and metadata
- Default parameters and constraints
- Supported aspect ratios and formats
- Model-specific optimization prompts
- Primary: Environment variable
FAL_KEYin.envfile - Secondary: Encrypted storage via
secure-storage.js - MCP Server: Can receive key via environment or config
- $5 spending limit enforced in MCP server
- Cost calculation before any generation
- User confirmation required for high-cost operations
- API key validation
- Model selection and configuration
- Optional prompt optimization
- Cost estimation and user confirmation
- Image generation with progress tracking
- Result storage with unique filenames
- Optional browser opening for results
Generated images use this pattern:
{model-key}_{prompt-index}_{iteration}_{image-index}_{timestamp}_{random}.png
- Comprehensive try-catch blocks throughout
- User-friendly error messages with suggestions
- Graceful degradation for missing features
- Validation at multiple levels (API key, model, parameters)
- This is an unofficial CLI tool, not affiliated with FAL
- No test suite currently exists
- No linting or type checking commands configured
- Uses ES modules (type: "module" in package.json)
- Requires Node.js 18+ for ES module support
- MCP server imports from non-existent
core/modules (need to be implemented or references updated)