This page documents the command-line interface (CLI) tools provided by g4f. The CLI offers multiple entry points for running servers, managing authentication, and interacting with providers directly from the terminal.
For information about the HTTP API server, see FastAPI Application. For the web-based graphical interface, see Web GUI. For the Model Context Protocol server integration, see MCP Server Integration.
The g4f package provides several CLI commands installed as console script entry points. These commands enable users to start servers, authenticate with providers, and perform provider-specific operations without writing Python code.
CLI Entry Points:
| Command | Module Path | Purpose |
|---|---|---|
g4f | g4f.cli:main | Main CLI interface |
g4f-mcp | g4f.mcp.server:main | MCP server for AI assistant integration |
g4f-antigravity | g4f.Provider.needs_auth.Antigravity:cli_main | Antigravity provider authentication |
g4f-geminicli | g4f.Provider.needs_auth.GeminiCLI:cli_main | Gemini OAuth authentication |
g4f-qwencode | g4f.Provider.qwen.QwenCode:cli_main | Qwen Code OAuth authentication |
g4f-github-copilot | g4f.Provider.github.GithubCopilot:cli_main | GitHub Copilot authentication |
Sources: setup.py118-127
Sources: setup.py118-127 README.md189-226
g4f CommandThe g4f command is the primary entry point defined in g4f.cli While the source file is not provided in the context, based on the README usage patterns, it supports subcommands for starting servers.
Common Usage:
Sources: README.md189-205 setup.py120
The CLI can be invoked as a Python module using the -m flag:
| Invocation | Functionality |
|---|---|
python -m g4f.cli gui | Starts Flask-based web GUI server |
python -m g4f | Starts FastAPI/Interference API server |
python -m g4f.mcp | Starts MCP server in stdio mode |
Sources: README.md189-217
The GUI server command launches the Flask-based web interface for interactive chat and image generation.
Command Syntax:
Python API Equivalent:
Default Endpoint:
http://localhost:8080/chat/Common Options:
--port PORT: Specify server port (default: 8080)--debug: Enable debug mode with auto-reloadThe GUI server provides:
Sources: README.md181-191 README.md500-505
The FastAPI server provides an OpenAI-compatible REST API (Interference API).
Command Syntax:
Docker Slim Configuration:
In slim Docker deployments, the FastAPI server may be mapped to a different port:
Default Endpoints:
http://localhost:1337/v1 (in slim Docker)http://localhost:1337/docsThe FastAPI server implements OpenAI-compatible endpoints including:
/v1/chat/completions/v1/images/generations/v1/modelsSources: README.md193-199 README.md517-523
The Model Context Protocol (MCP) server exposes g4f capabilities as tools for AI assistants like Claude Desktop.
Stdio Mode (default):
HTTP Mode:
| Endpoint | Method | Purpose |
|---|---|---|
/mcp | POST | JSON-RPC endpoint for MCP protocol |
/health | GET | Health check endpoint |
To integrate with Claude Desktop, add the following to claude_desktop_config.json:
The MCP server exposes three tools:
| Tool Name | Description |
|---|---|
web_search | Search the web using DuckDuckGo |
web_scrape | Extract text content from web pages |
image_generation | Generate images from text prompts |
Sources: README.md208-251 setup.py121
Several providers expose dedicated CLI commands for authentication and token management.
g4f-geminicli - Gemini OAuth AuthenticationPurpose: Authenticates with Google Gemini using OAuth2 PKCE flow.
Entry Point: g4f.Provider.needs_auth.GeminiCLI
Authentication Flow:
Usage:
The command handles the complete OAuth flow and stores credentials for subsequent requests.
Sources: setup.py123
g4f-antigravity - Antigravity Provider AuthenticationPurpose: Authenticates with Antigravity provider using OAuth2 PKCE.
Entry Point: g4f.Provider.needs_auth.Antigravity
Usage:
Similar to GeminiCLI, this implements a PKCE flow with browser-based authentication.
Sources: setup.py122
g4f-qwencode - Qwen Code OAuthPurpose: Authenticates with Qwen Code using device code flow.
Entry Point: g4f.Provider.qwen.QwenCode
Authentication Flow:
Usage:
The device code flow is suitable for CLI environments where opening a browser callback is impractical.
Sources: setup.py124
g4f-github-copilot - GitHub Copilot Token ManagementPurpose: Extracts and manages GitHub Copilot authentication tokens.
Entry Point: g4f.Provider.github.GithubCopilot
Usage:
This command may use browser automation (nodriver/zendriver) to extract authentication tokens from an active GitHub Copilot session.
Sources: setup.py125
The CLI respects environment variables for configuration:
| Variable | Purpose | Example |
|---|---|---|
G4F_PROXY | HTTP/SOCKS proxy for provider requests | http://proxy:8080 |
G4F_VERSION | Package version override | 0.3.1.0 |
Proxy Configuration Example:
The proxy setting is automatically applied to provider requests when the G4F_PROXY environment variable is set.
Sources: g4f/__init__.py49-52 setup.py105
CLI commands that involve authentication or media generation use persistent storage directories:
| Directory | Purpose |
|---|---|
har_and_cookies/ | HAR files, cookies, authentication tokens |
generated_media/ | Images, audio, video outputs |
.gui_cache/ | Web GUI cached assets |
Docker Volume Mapping:
These directories must be writable by the application user (UID 1200:1201 in full Docker, 1000:1000 in slim).
Sources: README.md107-109 README.md128-136
CLI commands are automatically installed when installing g4f via pip:
After installation, all console entry points become available in the PATH:
g4fg4f-mcpg4f-antigravityg4f-geminiclig4f-qwencodeg4f-github-copilotFor minimal installations without GUI or API dependencies:
Partial installations may exclude some CLI functionality that depends on optional dependencies.
Sources: README.md158-161 setup.py20-96
Windows users can download a standalone executable that includes CLI functionality:
g4f.exe.zip from releasesg4f.exeSources: README.md141-150
Sources: setup.py118-127 README.md183-226
The g4f CLI provides multiple entry points for different use cases:
g4f): General-purpose interface for starting serversAll commands support environment variable configuration and persistent storage for authentication data and generated media. The CLI is automatically installed with the g4f package and available in both pip installations and Docker containers.
Sources: setup.py118-127 README.md179-260
Refresh this wiki