gpt4free

xtekkyGPL-3.0活跃维护 有专家点评

聚合多家厂商语言模型的 Python 接口库,通过逆向方式免费调用 GPT、DeepSeek、Gemini 等模型,省去官方 API 费用。

The official gpt4free repository | various collection of powerful language models | opus 4.6 gpt 5.3 kimi 2.5 deepseek v3.2 gemini 3

v8.9.2发布于 2026-11-02 10:04 UTC67,025star +5 / 7 天13,459fork同步于 2026-11-10 23:19 UTC

专家点评

上手难度:进阶更新于 2026-11-11

把各家网页端 LLM 包装成 OpenAI 兼容接口的适配器集合,用来顶替按 token 计费的官方 API

适用场景

  • 本地跑一次性脚本或做原型验证,不想先开一堆厂商账号拿 key:起一个 FastAPI 服务就能用 OpenAI SDK 的调用方式打过去,换官方 API 就得先处理计费和配额
  • 需要同时试多个模型做横向对比:统一接口下切 provider 只改一个字段,自己写适配层则要为每家维护一套请求/响应转换
  • 已有 OpenAI 兼容的调用代码想换后端:把 base_url 指过去即可,不用改业务代码
  • 需要图像/音频/视频生成也走同一套客户端:README 里媒体生成和持久化在同一层,分开接各家 SDK 会多出几套鉴权和重试逻辑

踩坑

  • 上游是网页端而非正式 API,服务商随时改前端或封禁,适配器会成批失效;issue 里反复出现的是各类 takedown request,说明这条链路本身处在被主动清理的状态,不是偶发故障
  • 部分 provider 依赖 Chrome/Chromium 做浏览器自动化,容器里跑要额外装浏览器并加大 --shm-size,否则任务会直接挂;纯 API 型 provider 没这个问题,但你在选 provider 前未必分得清
  • 项目同时提供 GUI、API、Python 客户端和 g4f.js,配置面比单个 SDK 宽,第一次跑通要读文档确认 provider 选择和端口(8080 GUI/API、7900 VNC)

同类对比

要稳定 SLA 或合规审计就走官方 API 或 OpenRouter 这类聚合网关;只是本地跑开源权重则用 Ollama / vLLM,那条路不依赖逆向网页端。

怎么上手

由 README 提炼,执行前请确认
pip install g4f
docker pull hlohaus789/g4f
硬件要求按 README 说明

README 未说明显存要求;需 Python 3.10+,部分服务商依赖 Chrome/Chromium 浏览器自动化,支持 x86_64 与 arm64,可用 Docker 部署。

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

聚合多家可访问的 LLM 与媒体生成服务商,提供统一接口的社区项目

聚合多家厂商语言模型的 Python 接口库,通过逆向方式免费调用 GPT、DeepSeek、Gemini 等模型,省去官方 API 费用。

核心能力

  • 聚合多家 LLM 与媒体生成服务商适配器
  • 提供 OpenAI 兼容的 FastAPI 推理接口
  • 内置本地 Web GUI 与 Python 同步/异步客户端
  • 提供官方浏览器 JS 客户端 g4f.js
  • 支持图像、音频、视频生成与媒体持久化

容易踩的坑

部分服务商依赖 Chrome/Chromium 浏览器自动化,需另行安装;Docker 默认 8080 端口提供 GUI/API,7900 为可选 VNC 桌面;浏览器自动化任务需加大 --shm-size。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v8.9.2
  1. v8.9.2Release v8.9.2最新正式版2026-11-02 · 2026-11-02 10:04 UTC

    Full Changelog: https://github.com/xtekky/gpt4free/compare/v8.9.1...v8.9.2

    Download Options

    Python Package:

    • PyPI: pip install g4f==v8.9.2

    Executables (g4f-go, self-contained with embedded Python):

    • Windows amd64: g4f-go-v8.9.2-windows-amd64.zip
    • Linux x64: g4f-go-v8.9.2-linux-amd64.zip
    • Linux ARM64: g4f-go-v8.9.2-linux-arm64.zip
    • macOS x64: g4f-go-v8.9.2-darwin-amd64.zip
    • macOS ARM64: g4f-go-v8.9.2-darwin-arm64.zip
    • FreeBSD amd64: g4f-go-v8.9.2-freebsd-amd64.zip

    Standalone sandbox launcher (Docker/Podman, image pulled on demand):

    • Windows amd64/arm64: g4f-sandbox-v8.9.2-windows-<arch>.zip
    • Linux amd64/arm64: g4f-sandbox-v8.9.2-linux-<arch>.zip
    • macOS amd64/arm64: g4f-sandbox-v8.9.2-darwin-<arch>.zip
    • Termux/Android arm64: g4f-sandbox-v8.9.2-android-arm64.zip (native Python API, no Docker)
    • Defaults to the small API-only image (latest-slim); --desktop pulls the full desktop image only when needed.

    Android App:

    • Android APK: g4f-v8.9.2.apk

    Browser Extension (Chrome/Edge):

    • g4f-browser-extension-v8.9.2.zip (unzip, then load unpacked via chrome://extensions)

    System Packages:

    • WinGet: winget install gpt4free

    Docker:

    • docker pull hlohaus789/g4f:v8.9.2
    • docker pull hlohaus789/g4f:v8.9.2-slim
    • docker pull hlohaus789/g4f:v8.9.2-sandbox-desktop

    Docker sandboxed AI tools sets (one-click install, 100+ different AI tools):

    • docker pull hlohaus789/g4f:v8.9.2-sandbox-desktop — a full Xfce desktop (TigerVNC + noVNC) with the g4f API and a one-click menu for 100+ different AI tools: coding agents (OpenCode, Copilot CLI, Hermes, Aider, …), chat UIs, image/audio/video tools and gateways.
    • Desktop + API: http://localhost:8080/desktop/ — API: http://localhost:8080
    • Mount your own app at /app/gpt4free and persist agent settings:
      docker run -d --name g4f-sandbox-desktop \
        -p 8080:8080 -p 5900:5900 --shm-size="2gb" \
        -v ${PWD}:/app/gpt4free \
        -v ${PWD}/sandbox-home/.config:/home/pn/.config \
        -v ${PWD}/sandbox-home/.local:/home/pn/.local \
        hlohaus789/g4f:v8.9.2-sandbox-desktop
      
    • Docs: docker/sandbox-menu/README.md
  2. v8.9.1Release v8.9.12026-11-02 · 2026-11-02 09:02 UTC
    查看更新说明

    Full Changelog: https://github.com/xtekky/gpt4free/compare/v8.9.0...v8.9.1

    Download Options

    Python Package:

    • PyPI: pip install g4f==v8.9.1

    Executables (g4f-go, self-contained with embedded Python):

    • Windows amd64: g4f-go-v8.9.1-windows-amd64.zip
    • Linux x64: g4f-go-v8.9.1-linux-amd64.zip
    • Linux ARM64: g4f-go-v8.9.1-linux-arm64.zip
    • macOS x64: g4f-go-v8.9.1-darwin-amd64.zip
    • macOS ARM64: g4f-go-v8.9.1-darwin-arm64.zip
    • FreeBSD amd64: g4f-go-v8.9.1-freebsd-amd64.zip

    Standalone sandbox launcher (Docker/Podman, image pulled on demand):

    • Windows amd64/arm64: g4f-sandbox-v8.9.1-windows-<arch>.zip
    • Linux amd64/arm64: g4f-sandbox-v8.9.1-linux-<arch>.zip
    • macOS amd64/arm64: g4f-sandbox-v8.9.1-darwin-<arch>.zip
    • Termux/Android arm64: g4f-sandbox-v8.9.1-android-arm64.zip (native Python API, no Docker)
    • Defaults to the small API-only image (latest-slim); --desktop pulls the full desktop image only when needed.

    Android App:

    • Android APK: g4f-v8.9.1.apk

    Browser Extension (Chrome/Edge):

    • g4f-browser-extension-v8.9.1.zip (unzip, then load unpacked via chrome://extensions)

    System Packages:

    • WinGet: winget install gpt4free

    Docker:

    • docker pull hlohaus789/g4f:v8.9.1
    • docker pull hlohaus789/g4f:v8.9.1-slim
    • docker pull hlohaus789/g4f:v8.9.1-sandbox-desktop

    Docker sandboxed AI tools sets (one-click install, 100+ different AI tools):

    • docker pull hlohaus789/g4f:v8.9.1-sandbox-desktop — a full Xfce desktop (TigerVNC + noVNC) with the g4f API and a one-click menu for 100+ different AI tools: coding agents (OpenCode, Copilot CLI, Hermes, Aider, …), chat UIs, image/audio/video tools and gateways.
    • Desktop + API: http://localhost:8080/desktop/ — API: http://localhost:8080
    • Mount your own app at /app/gpt4free and persist agent settings:
      docker run -d --name g4f-sandbox-desktop \
        -p 8080:8080 -p 5900:5900 --shm-size="2gb" \
        -v ${PWD}:/app/gpt4free \
        -v ${PWD}/sandbox-home/.config:/home/pn/.config \
        -v ${PWD}/sandbox-home/.local:/home/pn/.local \
        hlohaus789/g4f:v8.9.1-sandbox-desktop
      
    • Docs: docker/sandbox-menu/README.md
  3. v8.9.0Release v8.9.02026-11-02 · 2026-11-02 08:25 UTC
    查看更新说明

    Full Changelog: https://github.com/xtekky/gpt4free/compare/v8.8.18...v8.9.0

    Download Options

    Python Package:

    • PyPI: pip install g4f==v8.9.0

    Executables (g4f-go, self-contained with embedded Python):

    • Windows amd64: g4f-go-v8.9.0-windows-amd64.zip
    • Linux x64: g4f-go-v8.9.0-linux-amd64.zip
    • Linux ARM64: g4f-go-v8.9.0-linux-arm64.zip
    • macOS x64: g4f-go-v8.9.0-darwin-amd64.zip
    • macOS ARM64: g4f-go-v8.9.0-darwin-arm64.zip
    • FreeBSD amd64: g4f-go-v8.9.0-freebsd-amd64.zip

    Standalone sandbox launcher (Docker/Podman, image pulled on demand):

    • Windows amd64/arm64: g4f-sandbox-v8.9.0-windows-<arch>.zip
    • Linux amd64/arm64: g4f-sandbox-v8.9.0-linux-<arch>.zip
    • macOS amd64/arm64: g4f-sandbox-v8.9.0-darwin-<arch>.zip
    • Termux/Android arm64: g4f-sandbox-v8.9.0-android-arm64.zip (native Python API, no Docker)
    • Defaults to the small API-only image (latest-slim); --desktop pulls the full desktop image only when needed.

    Android App:

    • Android APK: g4f-v8.9.0.apk

    Browser Extension (Chrome/Edge):

    • g4f-browser-extension-v8.9.0.zip (unzip, then load unpacked via chrome://extensions)

    System Packages:

    • WinGet: winget install gpt4free

    Docker:

    • docker pull hlohaus789/g4f:v8.9.0
    • docker pull hlohaus789/g4f:v8.9.0-slim
    • docker pull hlohaus789/g4f:v8.9.0-sandbox-desktop

    Docker sandboxed AI tools sets (one-click install, 100+ different AI tools):

    • docker pull hlohaus789/g4f:v8.9.0-sandbox-desktop — a full Xfce desktop (TigerVNC + noVNC) with the g4f API and a one-click menu for 100+ different AI tools: coding agents (OpenCode, Copilot CLI, Hermes, Aider, …), chat UIs, image/audio/video tools and gateways.
    • Desktop + API: http://localhost:8080/desktop/ — API: http://localhost:8080
    • Mount your own app at /app/gpt4free and persist agent settings:
      docker run -d --name g4f-sandbox-desktop \
        -p 8080:8080 -p 5900:5900 --shm-size="2gb" \
        -v ${PWD}:/app/gpt4free \
        -v ${PWD}/sandbox-home/.config:/home/pn/.config \
        -v ${PWD}/sandbox-home/.local:/home/pn/.local \
        hlohaus789/g4f:v8.9.0-sandbox-desktop
      
    • Docs: docker/sandbox-menu/README.md
  4. v8.8.18Release v8.8.182026-11-02 · 2026-11-02 01:43 UTC
    查看更新说明

    Full Changelog: https://github.com/xtekky/gpt4free/compare/v8.8.17...v8.8.18

    Download Options

    Python Package:

    • PyPI: pip install g4f==v8.8.18

    Executables (g4f-go, self-contained with embedded Python):

    • Windows amd64: g4f-go-v8.8.18-windows-amd64.zip
    • Linux x64: g4f-go-v8.8.18-linux-amd64.zip
    • Linux ARM64: g4f-go-v8.8.18-linux-arm64.zip
    • macOS x64: g4f-go-v8.8.18-darwin-amd64.zip
    • macOS ARM64: g4f-go-v8.8.18-darwin-arm64.zip
    • FreeBSD amd64: g4f-go-v8.8.18-freebsd-amd64.zip

    Standalone sandbox launcher (Docker/Podman, image pulled on demand):

    • Windows amd64/arm64: g4f-sandbox-v8.8.18-windows-<arch>.zip
    • Linux amd64/arm64: g4f-sandbox-v8.8.18-linux-<arch>.zip
    • macOS amd64/arm64: g4f-sandbox-v8.8.18-darwin-<arch>.zip
    • Termux/Android arm64: g4f-sandbox-v8.8.18-android-arm64.zip (native Python API, no Docker)
    • Defaults to the small API-only image (latest-slim); --desktop pulls the full desktop image only when needed.

    Android App:

    • Android APK: g4f-v8.8.18.apk

    Browser Extension (Chrome/Edge):

    • g4f-browser-extension-v8.8.18.zip (unzip, then load unpacked via chrome://extensions)

    System Packages:

    • WinGet: winget install gpt4free

    Docker:

    • docker pull hlohaus789/g4f:v8.8.18
    • docker pull hlohaus789/g4f:v8.8.18-slim
    • docker pull hlohaus789/g4f:v8.8.18-sandbox-desktop

    Docker sandboxed AI tools sets (one-click install, 100+ different AI tools):

    • docker pull hlohaus789/g4f:v8.8.18-sandbox-desktop — a full Xfce desktop (TigerVNC + noVNC) with the g4f API and a one-click menu for 100+ different AI tools: coding agents (OpenCode, Copilot CLI, Hermes, Aider, …), chat UIs, image/audio/video tools and gateways.
    • Desktop + API: http://localhost:8080/desktop/ — API: http://localhost:8080
    • Mount your own app at /app/gpt4free and persist agent settings:
      docker run -d --name g4f-sandbox-desktop \
        -p 8080:8080 -p 5900:5900 --shm-size="2gb" \
        -v ${PWD}:/app/gpt4free \
        -v ${PWD}/sandbox-home/.config:/home/pn/.config \
        -v ${PWD}/sandbox-home/.local:/home/pn/.local \
        hlohaus789/g4f:v8.8.18-sandbox-desktop
      
    • Docs: docker/sandbox-menu/README.md
  5. v8.8.17Check new Slim Image2026-11-02 · 2026-11-02 00:32 UTC
    查看更新说明

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    GPT4Free (g4f)

    PyPI Docker Hub License: GPL v3 PyPI Downloads GitHub Repo stars


    GPT4Free (g4f) is a community-driven project that aggregates multiple accessible providers and interfaces to make working with modern LLMs and media-generation models easier and more flexible. GPT4Free aims to offer multi-provider support, local GUI, OpenAI-compatible REST APIs, and convenient Python and JavaScript clients — all under a community-first license.

    This README is a consolidated, improved, and complete guide to installing, running, and contributing to GPT4Free.

    Table of contents


    What’s included

    • Python client library and async client.
    • Optional local web GUI.
    • FastAPI-based OpenAI-compatible API (Inference API).
    • Official browser JS client (g4f.dev distribution).
    • Docker images (full and slim).
    • Multi-provider adapters (LLMs, media providers, local inference backends).
    • Tooling for image/audio/video generation and media persistence.

    Quick links


    Related projects


    Requirements & compatibility

    • Python 3.10+ recommended.
    • Google Chrome/Chromium for providers using browser automation.
    • Docker for containerized deployment.
    • Works on x86_64 and arm64 (slim image supports both).
    • Some provider adapters may require platform-specific tooling (Chrome/Chromium, etc.). Check provider docs for details.

    Installation

    Docker (recommended)

    1. Install Docker: https://docs.docker.com/get-docker/
    2. Create persistent directories:
      • Example (Linux/macOS):
        mkdir -p ${PWD}/har_and_cookies ${PWD}/generated_media
        sudo chown -R 1200:1201 ${PWD}/har_and_cookies ${PWD}/generated_media
        
    3. Pull image:
      docker pull hlohaus789/g4f
      
    4. Run container:
      docker run -p 8080:8080 -p 7900:7900 \
        --shm-size="2g" \
        -v ${PWD}/har_and_cookies:/app/har_and_cookies \
        -v ${PWD}/generated_media:/app/generated_media \
        hlohaus789/g4f:latest
      

    Notes:

    • Port 8080 serves GUI/API; 7900 can expose a VNC-like desktop for provider logins (optional).
    • Increase --shm-size for heavier browser automation tasks.

    Slim Docker image (x64 & arm64)

    mkdir -p ${PWD}/har_and_cookies ${PWD}/generated_media
    chown -R 1000:1000 ${PWD}/har_and_cookies ${PWD}/generated_media
    
    docker run \
      -p 1337:8080 -p 8080:8080 \
      -v ${PWD}/har_and_cookies:/app/har_and_cookies \
      -v ${PWD}/generated_media:/app/generated_media \
      hlohaus789/g4f:latest-slim
    

    Notes:

    • The slim image can update the g4f package on startup and installs additional dependencies as needed.
    • In this example, the Inference API is mapped to 1337.

    Sandbox desktop (Docker)

    A full Xfce desktop (TigerVNC + noVNC) with the g4f API and a one-click one-click menu for 100+ AI tools and providers — coding agents, browsers, gateways, local runtimes and assistants. See docs/sandbox-desktop for the start script, clipboard, scaling, app volume, user id, password and domain-routing options, and docker/sandbox-menu/README.md for the menu, the tool list and the settings.

    docker run -d --name g4f-sandbox-desktop \
      --cap-add NET_ADMIN \
      -p 127.0.0.1:8080:8080 -p 127.0.0.1:5900:5900 \
      --shm-size="2gb" \
      -v ${PWD}:/app/gpt4free \
      -v ${PWD}/sandbox-home/.config:/home/pn/.config \
      -v ${PWD}/sandbox-home/.local:/home/pn/.local \
      hlohaus789/g4f:latest-sandbox-desktop
    
    • Desktop (browser): http://127.0.0.1:8080/desktop/ · API: http://127.0.0.1:8080/ · Direct VNC: 127.0.0.1:5900
    • The ports bind to 127.0.0.1 by default (localhost only, not every host interface). Set SANDBOX_BIND_ADDR=0.0.0.0 to expose the desktop on the LAN; bin/start-sandbox-desktop.sh --bind <addr> does the same.
    • The image starts an egress firewall (needs --cap-add NET_ADMIN): the sandbox can reach the public internet, but connections to private, link-local and reserved networks — the host LAN, other Docker networks and cloud metadata — are rejected. Loopback inside the container stays usable, so the g4f API, its *.g4f.local router and local gateways keep working. Replies to connections that come in from the host are allowed, so the published desktop/API ports stay reachable even though the host address is in a blocked range; the filter only stops the sandbox from starting such connections itself. Outbound file-sharing/sync protocols (SMB, NetBIOS, NFS, AFP, FTP/TFTP, rsync, iSCSI, rpcbind) and common crypto-mining pool ports are rejected too. Host-side services reached through host.docker.internal, 172.17.0.1 or the host's LAN address are blocked as well; run them inside the sandbox or set SANDBOX_BLOCK_LOCAL_NETWORK=0 to disable the filter for a trusted setup. If the filter cannot be installed the sandbox still starts with a warning; set SANDBOX_FIREWALL_STRICT=1 to make that fatal.
    • -v ${PWD}:/app/gpt4free mounts your app into the sandbox at the path the image's editable g4f install points at, so the API serves your code and the agents can edit it. Mount at /app/gpt4free, not /app.
    • -v ${PWD}/sandbox-home/.config:/home/pn/.config and …/.local:/home/pn/.local keep agent configs, credentials, caches and the sandbox settings across container restarts — without them every new container starts with an empty home and every tool asks for its login again. Do not mount over /home/pn itself: the embedded Python and g4f runtime live in /home/pn/.g4f.
    • To give the agents a throwaway profile instead, point HOME at a mounted directory: -v ${PWD}/agent-home:/home/pn/work plus Sandbox Settings → sandbox-cli settings --home /home/pn/work.
    • bin/start-sandbox-desktop.sh wraps the same run (and docker/docker-compose.sandbox-desktop.yml) with --build, --pull, --port, --bind, --app-dir, --user-id, --api-key, --domain-suffix, --no-domain-router, shell, logs and stop. --api-key KEY protects the desktop/API with a password (any username works in the browser login); see docs/sandbox-desktop.
    • The sandbox user (pn) runs with uid/gid 1000 by default. On a host whose user has another id, build the image with --build-arg G4F_USER_ID="$(id -u)" (or run bin/start-sandbox-desktop.sh --user-id "$(id -u)"; it rebuilds when the existing image was built for a different id). Matching the id keeps the bind-mounted sandbox-home and files written under /app/gpt4free owned by your host user.
    Sandbox launcher (g4f-go sandbox)

    Download g4f-go from the release assets for Windows, Linux, macOS or Termux (amd64/arm64). The sandbox subcommand requires only Docker, Podman or, on Termux/Android, udocker; it does not embed the image and pulls it on demand:

    g4f-go sandbox                    # small API-only sandbox (latest-slim)
    g4f-go sandbox --desktop          # full desktop image, pulled on first use
    g4f-go sandbox --desktop install chrome
    g4f-go sandbox-cli list           # shorthand for `g4f-go sandbox --desktop cli`
    g4f-go sandbox status
    g4f-go sandbox down
    

    The default API-only mode uses the multi-arch latest-slim image; --desktop pulls latest-sandbox-desktop only when the desktop is requested. Tools are installed on demand from the sandbox menu or with g4f-go sandbox --desktop install <tool>. On Termux/Android the same command uses udocker (installed with pip on first use) to run those images without root; the native API-only backend is still available with --backend termux. See g4f-go and the sandbox desktop documentation.

    Python Installation (pip / from source / partial installs)

    Prerequisites:

    Install from PyPI (recommended):

    pip install -U g4f[all]
    

    Partial installs

    • To install only specific functionality, use optional extras groups. See docs/requirements in the project docs.

    Install from source:

    git clone https://github.com/xtekky/gpt4free.git
    cd gpt4free
    pip install -r requirements.txt
    pip install -e .
    

    Notes:

    • Some features require Chrome/Chromium or other tools; follow provider-specific docs.

    Running the app

    GUI (web client)

    • Run via Python:
    from g4f.gui import run_gui
    run_gui()
    
    • Or via CLI:
    python -m g4f.cli gui --port 8080 --debug
    

    FastAPI / Inference API

    • Start FastAPI server:
    python -m g4f --port 8080 --debug
    
    • If using slim docker mapping, Inference API may be available at http://localhost:1337/v1
    • Swagger UI: http://localhost:1337/docs

    CLI

    • Start GUI server:
    python -m g4f.cli gui --port 8080 --debug
    

    MCP Server

    GPT4Free now includes a Model Context Protocol (MCP) server that allows AI assistants like Claude to access web search, scraping, and image generation capabilities.

    Starting the MCP server (stdio mode):

    # Using g4f command
    g4f mcp
    
    # Or using Python module
    python -m g4f.mcp
    

    Starting the MCP server (HTTP mode):

    # Start HTTP server on port 8765
    g4f mcp --http --port 8765
    
    # Custom host and port
    g4f mcp --http --host 127.0.0.1 --port 3000
    

    HTTP mode provides:

    • POST http://localhost:8765/mcp - JSON-RPC endpoint
    • GET http://localhost:8765/health - Health check

    Configuring with Claude Desktop:

    Add to your claude_desktop_config.json:

    {
      "mcpServers": {
        "gpt4free": {
          "command": "python",
          "args": ["-m", "g4f.mcp"]
        }
      }
    }
    

    Available MCP Tools:

    • web_search - Search the web using DuckDuckGo
    • web_scrape - Extract text content from web pages
    • image_generation - Generate images from text prompts
    • polli_publish_app - Publish a built app from the workspace to https://<name>.pollinations.app with the Pollinations CLI

    For detailed MCP documentation, see g4f/mcp/README.md

    Optional provider login (desktop within container)

    • Accessible at:
      http://localhost:7900/?autoconnect=1&resize=scale&password=secret
      
    • Useful for logging into web-based providers to obtain cookies/HAR files.

    Using the Python client

    Install:

    pip install -U g4f[all]
    

    Synchronous text example:

    from g4f.client import Client
    
    client = Client()
    response = client.chat.completions.create(
        model="auto",
        messages=[{"role": "user", "content": "Hello, how are you?"}],
        web_search=False
    )
    print(response.choices[0].message.content)
    

    Expected:

    Hello! How can I assist you today?
    

    Image generation example:

    from g4f.client import Client
    
    client = Client()
    response = client.images.generate(
        model="flux",
        prompt="a white siamese cat",
        response_format="url"
    )
    print(f"Generated image URL: {response.data[0].url}")
    

    Async client example:

    from g4f.client import AsyncClient
    import asyncio
    
    async def main():
        client = AsyncClient()
        response = await client.chat.completions.create(
            model="auto",
            messages=[{"role": "user", "content": "Explain quantum computing briefly"}],
        )
        print(response.choices[0].message.content)
    
    asyncio.run(main())
    

    Notes:


    Using GPT4Free.js (browser JS client)

    Use the official JS client in the browser—no backend required.

    Example:

    <script type="module">
      import Client from 'https://g4f.dev/dist/js/client.js';
    
      const client = new Client();
      const result = await client.chat.completions.create({
          model: 'auto',  // Or "glm-5.3", "kimi-k3", etc.
          messages: [{ role: 'user', content: 'Explain quantum computing' }]
      });
      console.log(result.choices[0].message.content);
    </script>
    

    Notes:

    • The JS client is distributed via the g4f.dev CDN for easy usage. Review CORS considerations and usage limits.

    Providers & models (overview)

    • GPT4Free integrates many providers including (but not limited to) OpenAI-compatible endpoints, PerplexityLabs, Gemini, MetaAI, Pollinations (media), and local inference backends.
    • Model availability and behavior depend on provider capabilities. See the providers doc for current, supported provider/model lists: https://g4f.dev/docs/providers-and-models

    Provider requirements may include:

    • API keys or tokens (for authenticated providers)
    • Browser cookies / HAR files for providers scraped via browser automation
    • Chrome/Chromium or headless browser tooling
    • Local model binaries and runtime (for local inference)

    Local inference & media

    • GPT4Free supports local inference backends. See docs/local for supported runtimes and hardware guidance.
    • Media generation (image, audio, video) is supported through providers (e.g., Pollinations). See docs/media for formats, options, and sample usage.

    Configuration & customization

    • Configure via environment variables, CLI flags, or config files. See docs/config.
    • To reduce install size, use partial requirement groups. See docs/requirements.
    • Provider selection: learn how to set defaults and override per-request at docs/selecting_a_provider.
    • Persistence: HAR files, cookies, and generated media persist in mapped directories (e.g., har_and_cookies, generated_media).

    Running on smartphone

    • The web GUI is responsive and can be accessed from a phone by visiting your host IP:8080 or via a tunnel. See docs/guides/phone.

    Inference API (OpenAI‑compatible)

    • The Inference API enables OpenAI-like workflows routed through GPT4Free provider selection.
    • Docs: docs/interference-api
    • Default endpoint (example slim docker): http://localhost:1337/v1
    • Swagger UI: http://localhost:1337/docs

    Examples & common patterns


    Contributing

    Contributions are welcome — new providers, features, docs, and fixes are appreciated.

    How to contribute:

    1. Fork the repository.
    2. Create a branch for your change.
    3. Run tests and linters.
    4. Open a Pull Request with a clear description and tests/examples if applicable.

    Repository: https://github.com/xtekky/gpt4free

    How to create a new provider

    • Read the guide: docs/guides/create_provider
    • Typical steps:
      • Implement a provider adapter in g4f/Provider/
      • Add configuration and dependency notes
      • Include tests and usage examples
      • Respect third‑party code licenses and attribute appropriately

    How AI can help you write code

    • See: docs/guides/help_me for prompt templates and workflows to accelerate development.
    • Automatic development loop: docs/dev-pipeline explains bin/dev-pipeline, which reads tasks from AGENTS.md and implements them with working free models from pi-freeflow.

    Security, privacy & takedown policy

    • Do not store or share sensitive credentials. Use per-provider recommended security practices.
    • Conversations are stored locally on your device by default; server/cloud synchronization (Secret Storage) is strictly opt-in and client-side encrypted.
    • If your site appears in the project’s links and you want it removed, send proof of ownership to https://g4f.dev/community and it will be removed promptly.
    • For production, secure the server with HTTPS, authentication, and firewall rules. Limit access to provider credentials and cookie/HAR storage.

    Credits, contributors & attribution

    Many more contributors are acknowledged in the repository.


    Powered-by highlights


    Changelog & releases


    Manifesto / Project principles

    GPT4Free is guided by community principles:

    1. Open access to AI tooling and models.
    2. Collaboration across providers and projects.
    3. Opposition to monopolistic, closed systems that restrict creativity.
    4. Community-centered development and broad access to AI technologies.
    5. Promote innovation, creativity, and accessibility.

    https://g4f.dev/manifesto


    License

    This program is licensed under the GNU General Public License v3.0 (GPLv3). See the full license: https://www.gnu.org/licenses/gpl-3.0.txt

    Summary:

    • You may redistribute and/or modify under the terms of GPLv3.
    • The program is provided WITHOUT ANY WARRANTY.

    Copyright notice

    xtekky/gpt4free: Copyright (C) 2025 xtekky
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    

    Contact & sponsorship


    Appendix: Quick commands & examples

    Install g4f-go (launcher):

    curl -fsSL https://raw.githubusercontent.com/xtekky/gpt4free/main/bin/install.sh | bash
    

    Install (pip):

    pip install -U g4f[all]
    

    Run GUI (Python):

    python -m g4f.cli gui --port 8080 --debug
    # or
    python -c "from g4f.gui import run_gui; run_gui()"
    

    Docker (full):

    docker pull hlohaus789/g4f
    docker run -p 8080:8080 -p 7900:7900 \
      --shm-size="2g" \
      -v ${PWD}/har_and_cookies:/app/har_and_cookies \
      -v ${PWD}/generated_media:/app/generated_media \
      hlohaus789/g4f:latest
    

    Docker (slim):

    docker run -p 1337:8080 -p 8080:8080 \
      -v ${PWD}/har_and_cookies:/app/har_and_cookies \
      -v ${PWD}/generated_media:/app/generated_media \
      hlohaus789/g4f:latest-slim
    

    Python usage patterns:

    • client.chat.completions.create(...)
    • client.images.generate(...)
    • Async variants via AsyncClient

    Docs & deeper reading


    Thank you for using and contributing to GPT4Free — together we make powerful AI tooling accessible, flexible, and community-driven.