DEV Community

diwushennian4955
diwushennian4955

Posted on • Originally published at nexa-api.com

I Built a Universal AI CLI Tool in 10 Minutes (Inspired by Composio's Product Hunt Launch)

I Built a Universal AI CLI Tool in 10 Minutes (Inspired by Composio's Product Hunt Launch)

Composio Universal CLI is blowing up on Product Hunt today — developers want AI in their terminals. The idea is brilliant: a single CLI that connects AI agents to any external tool or API.

But what if you want to go further? What if you want to generate AI images, videos, and audio directly from your terminal — without any cloud dependencies, just a simple API call?

Here's how to build your own Universal AI CLI in 10 minutes using NexaAPI.

Why CLI + AI Is the New Hotness

The trend is clear: developers want to control AI from the command line. Whether it's:

  • Running AI generation in CI/CD pipelines
  • Batch processing images in scripts
  • Building AI-powered developer tools
  • Integrating AI into existing terminal workflows

The command line is where developers live. And now, with APIs like NexaAPI, you can add AI generation to any CLI tool in minutes.

Setup

pip install nexaapi
export NEXAAPI_KEY="your-key-from-rapidapi"
Enter fullscreen mode Exit fullscreen mode

Get your free API key: https://rapidapi.com/user/nexaquency

Build the CLI (Python)

# ai_cli.py — Universal AI CLI powered by NexaAPI
import argparse
import os
from nexaapi import NexaAPI

client = NexaAPI(api_key=os.environ.get('NEXAAPI_KEY', 'YOUR_API_KEY'))

def generate_image(prompt, output='output.png'):
    """Generate an image from a text prompt via CLI"""
    result = client.image.generate(
        model='flux-schnell',
        prompt=prompt
    )
    with open(output, 'wb') as f:
        f.write(result.image_data)
    print(f'✅ Image saved to {output} — Cost: $0.003')

def generate_audio(text, output='output.mp3'):
    """Generate speech from text via CLI"""
    result = client.audio.tts(text=text, voice='alloy')
    with open(output, 'wb') as f:
        f.write(result.audio_data)
    print(f'✅ Audio saved to {output}')

def main():
    parser = argparse.ArgumentParser(description='Universal AI CLI powered by NexaAPI')
    subparsers = parser.add_subparsers(dest='command')

    img_parser = subparsers.add_parser('image', help='Generate an image')
    img_parser.add_argument('prompt', type=str)
    img_parser.add_argument('--output', type=str, default='output.png')

    audio_parser = subparsers.add_parser('audio', help='Generate speech')
    audio_parser.add_argument('text', type=str)
    audio_parser.add_argument('--output', type=str, default='output.mp3')

    args = parser.parse_args()
    if args.command == 'image':
        generate_image(args.prompt, args.output)
    elif args.command == 'audio':
        generate_audio(args.text, args.output)
    else:
        parser.print_help()

if __name__ == '__main__':
    main()
Enter fullscreen mode Exit fullscreen mode

Usage:

python ai_cli.py image "a futuristic city at sunset"
python ai_cli.py audio "Hello, this is your AI assistant"
Enter fullscreen mode Exit fullscreen mode

Build the CLI (JavaScript/Node.js)

// ai-cli.mjs — Universal AI CLI powered by NexaAPI
import NexaAPI from 'nexaapi';
import { writeFileSync } from 'fs';
import { program } from 'commander';

const client = new NexaAPI({ apiKey: process.env.NEXAAPI_KEY || 'YOUR_API_KEY' });

program.name('ai-cli').description('Universal AI CLI powered by NexaAPI — $0.003/image');

program
  .command('image <prompt>')
  .option('-o, --output <file>', 'Output filename', 'output.png')
  .action(async (prompt, options) => {
    const result = await client.image.generate({ model: 'flux-schnell', prompt });
    writeFileSync(options.output, result.imageData);
    console.log(`✅ Image saved to ${options.output} — Cost: $0.003`);
  });

program
  .command('audio <text>')
  .option('-o, --output <file>', 'Output filename', 'output.mp3')
  .option('-v, --voice <voice>', 'Voice', 'alloy')
  .action(async (text, options) => {
    const result = await client.audio.tts({ text, voice: options.voice });
    writeFileSync(options.output, result.audioData);
    console.log(`✅ Audio saved to ${options.output}`);
  });

program
  .command('video <prompt>')
  .option('-o, --output <file>', 'Output filename', 'output.mp4')
  .action(async (prompt, options) => {
    const result = await client.video.generate({ model: 'kling-v1', prompt });
    writeFileSync(options.output, result.videoData);
    console.log(`✅ Video saved to ${options.output}`);
  });

program.parse();
Enter fullscreen mode Exit fullscreen mode

Usage:

node ai-cli.mjs image "a futuristic city at sunset"
node ai-cli.mjs audio "Hello world" --voice nova
node ai-cli.mjs video "a cat playing piano"
Enter fullscreen mode Exit fullscreen mode

Why NexaAPI for CLI Tools?

Feature NexaAPI OpenAI Replicate
Price/image $0.003 $0.04 $0.01
Models 56+ 3 100+
OpenAI-compatible
CLI-friendly
Free tier Limited

NexaAPI is 13x cheaper than DALL-E 3 and works with the same OpenAI SDK — just change the base_url.

Real-World Use Cases

  1. CI/CD Pipeline: Auto-generate product images when you push new features
  2. Documentation: Generate screenshots and diagrams from text descriptions
  3. Content Pipeline: Batch-generate social media images from a CSV of prompts
  4. Developer Tools: Add AI generation to your existing CLI tools

Get Started

  1. Get your free API key: https://rapidapi.com/user/nexaquency
  2. Install the SDK: pip install nexaapi or npm install nexaapi
  3. Clone the full example: GitHub Repo
  4. Try the interactive tutorial: Google Colab

NexaAPI — 56+ AI models, $0.003/image, OpenAI-compatible. Try it free →

Top comments (0)