gpt4free README

The project's README from github.com/xtekky/gpt4free. As one markdown file: README.md.

GPT4Free (g4f)

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

Community Day 2026

Created by @xtekky,
maintained by @hlohaus

Support the project on GitHub Sponsors ❤️

Live demo & docs: https://g4f.dev | Documentation: https://g4f.dev/docs


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



Requirements & compatibility


Installation

  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:

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:

Windows Guide (.exe)

👉 Check out the Windows launcher for GPT4Free:
🔗 https://github.com/gpt4free/g4f.exe 🚀

  1. Download the release artifact g4f.exe.zip from: https://github.com/xtekky/gpt4free/releases/latest
  2. Unzip and run g4f.exe.
  3. Open GUI at: http://localhost:8080/chat/
  4. If Windows Firewall blocks access, allow the application.

Python Installation (pip / from source / partial installs)

Prerequisites:

Install from PyPI (recommended):

pip install -U g4f[all]

Partial installs

Install from source:

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

Notes:


Running the app

GUI (web client)

from g4f.gui import run_gui
run_gui()
python -m g4f.cli gui --port 8080 --debug

FastAPI / Interference API

python -m g4f --port 8080 --debug

CLI

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:

Configuring with Claude Desktop:

Add to your claude_desktop_config.json:

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

Available MCP Tools:

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

Optional provider login (desktop within container)


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:


Providers & models (overview)

Provider requirements may include:


Local inference & media


Configuration & customization


Running on smartphone


Interference API (OpenAI‑compatible)


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

How AI can help you write code


Security, privacy & takedown policy


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:

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 (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:

Docs & deeper reading


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

gpt4free (xtekky/gpt4free)

Searching Database…

66.9K ·GitHub
这是什么?GPT4Free(g4f)是一个社区驱动的项目,它汇集了许多通往商业大语言模型(GPT-4、Claude、Gemini、DeepSeek 等)和媒体生成模型的免费及逆向工程访问入口,并通过统一的 Python/JS 客户端、网页图形界面和兼容 OpenAI 的 API 对外提供服务。
这是 Python 库、托管应用,还是两者兼有?两者都是:它既可以作为可安装的 Python 客户端库使用,也可以作为自托管应用运行,自带网页图形界面和兼容 OpenAI 的 FastAPI 服务器(即 'Interference API')。
我该怎么把它跑起来?最简单的方法是使用 Docker:拉取 g4f 镜像并运行容器,容器会在 8080 端口提供图形界面和 API。也可以从 PyPI 安装 Python 包、从源码运行,或下载 Windows 启动程序 g4f.exe。
我需要先安装什么?推荐安装 Python 3.10+;对于依赖浏览器自动化的服务提供方,需要安装 Chrome/Chromium。如果不想在本机配置 Python,也可以改用 Docker。
服务提供方装好就能直接用吗?不一定。很多服务提供方是对付费服务的逆向工程免费访问,因此有些需要 API 密钥,或需要通过内置的容器桌面环境登录服务方网站后获取浏览器 Cookie 或 HAR 文件。
把它接入我的服务账号安全吗?项目提醒你要遵循各服务方的安全规范,不要保存或分享敏感凭据;Cookie 和 HAR 数据保存在本地挂载的目录中,不会发送给维护者。
MCP 服务器是做什么用的?GPT4Free 内置了一个 Model Context Protocol(MCP)服务器,让 Claude Desktop 等 AI 助手可以直接调用其网页搜索、网页抓取和图像生成工具。
我能不用后端,直接在浏览器里使用 GPT4Free 吗?可以。官方提供了 GPT4Free.js 客户端,通过 CDN 分发,完全在浏览器中运行,无需任何服务器配置。
'Interference API' 是什么?它是基于 FastAPI、兼容 OpenAI 的接口,让你可以像使用 OpenAI 官方 API 一样,通过 GPT4Free 的服务方选择机制转发对话和补全请求。
它能生成图片,还是只能生成文字?除了文字对话补全之外,它还支持通过 Pollinations 等媒体服务方生成图片、音频和视频。
Creator
xtekky
Size
234.7 MB
Stars
66.9K
Age
3y
Commits · 90 Days