G4F CLI Client

A command-line interface for interacting with various AI providers and models, supporting text and image generation with conversation history.

Installation

pip install g4f[all]

Call it in your terminal:

g4f client "Explain generative AI"

Or with:

python -m g4f.cli.client "Explain quantum computing"

Usage

usage: g4f [-h] [--debug] [-p PROVIDER] [-m MODEL] [-O [FILE]] [-i INSTRUCTIONS] [-c COOKIES_DIR]
           [--conversation-file CONVERSATION_FILE] [-C]
           [input ...]

Basic Examples

  1. Text generation:

    g4f "Explain quantum computing in simple terms"
  2. Image description:

    g4f image.jpg "Describe this image"
  3. Image generation (with supported models):

    g4f -m flux -O output.jpg "A futuristic cityscape"
  4. Continue conversation:

    g4f "Now explain it like I'm five"

Options

Option Description
-h, --help Show help message
--debug, -d Enable verbose logging
-p PROVIDER, --provider PROVIDER Specify provider (e.g., OpenaiChat, Gemini, Grok)
-m MODEL, --model MODEL Specify model (provider-specific)
-O [FILE], --output [FILE] Save response to file (for text or image generation)
-i INSTRUCTIONS, --instructions INSTRUCTIONS Add custom system instructions
-c COOKIES_DIR, --cookies-dir COOKIES_DIR Directory for authenticated providers
--conversation-file FILE Custom conversation state file
-C, --clear-history Clear conversation history before starting

Features

Advanced Usage

  1. Custom provider with instructions:

    g4f -p PollinationsAI -i "You are a helpful science tutor" "Explain photosynthesis"
  2. Debug mode:

    g4f --debug "What's the weather today?"
  3. Clear history and start fresh:

    g4f -C "New conversation"
  4. Save response to file:

    g4f -O response.txt "Write a poem about the ocean"

Configuration

Supported Providers

The CLI supports numerous providers including:

Run g4f --help to see the complete list.

Notes