gpt4free 项目遭 OpenAI 起诉
gpt4free 因绕过付费被 OpenAI 官方起诉。反映 AI 商业化与开源生态的法律冲突。
gpt4free 因绕过付费被 OpenAI 官方起诉。反映 AI 商业化与开源生态的法律冲突。
由 @xtekky 创建,由 @hlohaus 维护
在 GitHub Sponsors 上支持该项目 ❤️
在线演示及文档:https://g4f.dev | 文档:https://g4f.dev/docs
GPT4Free (g4f) 是一个社区驱动的项目,它聚合了多个易于访问的提供商和接口,使处理现代 LLM 和媒体生成模型变得更加容易和灵活。GPT4Free 致力于提供多提供商支持、本地 GUI、OpenAI 兼容的 REST API,以及便捷的 Python 和 JavaScript 客户端——全部在社区优先的许可证下。
本 README 是安装、运行和贡献 GPT4Free 的综合、改进和完整指南。
安装 Docker:https://docs.docker.com/get-docker/
创建持久目录:
mkdir -p ${PWD}/har_and_cookies ${PWD}/generated_media
sudo chown -R 1200:1201 ${PWD}/har_and_cookies ${PWD}/generated_media
拉取镜像:
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
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
slim 镜像可在启动时更新 g4f 包,并按需安装额外依赖。
在本例中,Interference API 映射到 1337。
👉 查看 GPT4Free 的 Windows 启动器:🔗 https://github.com/gpt4free/g4f.exe 🚀
从以下地址下载发布版本 g4f.exe.zip:https://github.com/xtekky/gpt4free/releases/latest
解压并运行 g4f.exe。
打开 GUI:http://localhost:8080/chat/
如果 Windows 防火墙阻止访问,请允许该应用程序。
需要:
从 PyPI 安装(推荐):
pip install -U g4f[all]
要仅安装特定功能,请使用可选的额外功能组。见项目文档中的 docs/requirements.md。
从源代码安装:
git clone https://github.com/xtekky/gpt4free.git
cd gpt4free
pip install -r requirements.txt
pip install -e .
某些功能需要 Chrome/Chromium 或其他工具;请遵循提供商专用文档。
from g4f.gui import run_gui
run_gui()
或通过 CLI:
python -m g4f.cli gui --port 8080 --debug
打开:http://localhost:8080/chat/
启动 FastAPI 服务器:
python -m g4f --port 8080 --debug
如果使用 slim docker 映射,Interference API 可能在 http://localhost:1337/v1 可用
Swagger UI:http://localhost:1337/docs
python -m g4f.cli gui --port 8080 --debug
可在以下地址访问:http://localhost:7900/?autoconnect=1&resize=scale&password=secret
用于登录基于网页的提供商以获取 cookie/HAR 文件。
GPT4Free 现包括 Model Context Protocol (MCP) 服务器,允许 Claude 等 AI 助手访问网页搜索、网页抓取和图像生成功能。
# 使用 g4f 命令
g4f mcp
# 或使用 Python 模块
python -m g4f.mcp
# 在端口 8765 启动 HTTP 服务器
g4f mcp --http --port 8765
# 自定义主机和端口
g4f mcp --http --host 127.0.0.1 --port 3000
添加到你的 claude_desktop_config.json:
{
"mcpServers": {
"gpt4free": {
"command": "python",
"args": ["-m", "g4f.mcp"]
}
}
}
详细的 MCP 文档见 g4f/mcp/README.md
pip install -U g4f[all]
from g4f.client import Client
client = Client()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello, how are you?"}],
web_search=False
)
print(response.choices[0].message.content)
输出:
Hello! How can I assist you today?
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}")
from g4f.client import AsyncClient
import asyncio
async def main():
client = AsyncClient()
response = await client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Explain quantum computing briefly"}],
)
print(response.choices[0].message.content)
asyncio.run(main())
详见完整的 API 参考了解流式传输、工具调用模式和高级选项:https://g4f.dev/docs/client
在浏览器中使用官方 JS 客户端——无需后端。
<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: 'gpt-4.1', // 或 "gpt-4o"、"deepseek-v3" 等
messages: [{ role: 'user', content: 'Explain quantum computing' }]
});
console.log(result.choices[0].message.content);
</script>
JS 客户端通过 g4f.dev CDN 分发,便于使用。查看 CORS 考虑和使用限制。
GPT4Free 集成了许多提供商,包括(但不限于)OpenAI 兼容端点、PerplexityLabs、Gemini、MetaAI、Pollinations(媒体)和本地推理后端。
模型可用性和行为取决于提供商功能。查看提供商文档了解当前支持的提供商/模型列表:https://g4f.dev/docs/providers-and-models
提供商需求可能包括:
GPT4Free 支持本地推理后端。见 docs/local.md 了解支持的运行时和硬件指导。
媒体生成(图像、音频、视频)通过提供商(例如 Pollinations)支持。见 docs/media.md 了解格式、选项和示例用法。
通过环境变量、CLI 标志或配置文件进行配置。见 docs/config.md。
要减少安装大小,使用部分需求组。见 docs/requirements.md。
提供商选择:在 docs/selecting_a_provider.md 了解如何设置默认值和覆盖每个请求。
持久性:HAR 文件、cookie 和生成的媒体持久保存在映射目录中(例如 har_and_cookies、generated_media)。
Web GUI 响应式,可通过访问你的主机 IP:8080 或通过隧道从手机访问。见 docs/guides/phone.md。
Interference API 启用通过 GPT4Free 提供商选择路由的类似 OpenAI 的工作流。
文档:docs/interference-api.md
默认端点(示例 slim docker):http://localhost:1337/v1
Swagger UI:http://localhost:1337/docs
流式完成、停止条件、系统消息和工具调用模式均记录在:
集成(LangChain、PydanticAI):docs/pydantic_ai.md
旧版示例:docs/legacy.md
欢迎贡献——新提供商、功能、文档和修复都受欢迎。
仓库:https://github.com/xtekky/gpt4free
阅读指南:docs/guides/create_provider.md
典型步骤:
见:docs/guides/help_me.md 了解提示模板和工作流以加速开发。
核心创建者:@xtekky(原始者),由 @hlohaus 维护。
完整贡献者图表:https://github.com/xtekky/gpt4free/graphs/contributors
显著的代码输入和归属:
许多其他贡献者在仓库中得到确认。
完整的使用 GPT4Free 的项目和网站列表,见:docs/powered-by.md
https://github.com/xtekky/gpt4free/releases
订阅 Discord/Telegram 获取公告。
GPT4Free 由社区原则指导:
本程序在 GNU General Public License v3.0 (GPLv3) 下获得许可。见完整许可证:https://www.gnu.org/licenses/gpl-3.0.txt
你可以在 GPLv3 的条款下重新分发和/或修改。
该程序按"原样"提供,不附带任何保证。
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.
维护者:https://github.com/hlohaus
赞助:https://github.com/sponsors/hlohaus
问题和功能请求:https://github.com/xtekky/gpt4free/issues
删除请求:takedown@g4f.ai
pip install -U g4f[all]
python -m g4f.cli gui --port 8080 --debug
# 或
python -c "from g4f.gui import run_gui; run_gui()"
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 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
client.chat.completions.create(...)
client.images.generate(...)
通过 AsyncClient 的异步变量
感谢你使用和贡献 GPT4Free——共同我们使强大的 AI 工具变得易于访问、灵活和社区驱动。