Skip to content
Back to search

https://github.com/xtekky/gpt4free

SkillGitHubIncomplete

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026. Its scripts were only partly scanned.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/xtekky/gpt4free with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/xtekky/gpt4free'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/xtekky--gpt4free/badge.svg)](/listings/xtekky--gpt4free)

HTML

<a href="/listings/xtekky--gpt4free"><img src="/api/listings/xtekky--gpt4free/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Docker (recommended)

1. Install Docker: https://docs.docker.com/get-docker/ 2. Create persistent directories: - Example (Linux/macOS): ```bash 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 Interference API is mapped to 1337.

Sandbox desktop (Docker)

A full Xfce desktop (TigerVNC + noVNC) with the g4f API and a one-click **Install & Open** menu for 100+ AI tools and providers — coding agents, browsers, gateways, local runtimes and assistants. See [docker/sandbox-menu/README.md](docker/sandbox-menu/README.md) for the menu, the tool list and the 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:latest-sandbox-desktop

- Desktop (browser): http://localhost:8080/desktop/ · API: http://localhost:8080/ · Direct VNC: `localhost:5900` - `-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`, `shell`, `logs` and `stop`.

Python Installation (pip / from source / partial installs)

Prerequisites: - Python 3.10+ (https://www.python.org/downloads/) - Chrome/Chromium for some providers.

Install from PyPI (recommended):

pip install -U g4f[all]

Partial installs - To install only specific functionality, use optional extras groups. See docs/requirements.md 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.

---

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 48 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. # SKILL.md
  2. ## Using gpt4free as an LLM Server for Bots (Clawbot/OpenClaw)
  3. ### Overview
  4. This skill covers running gpt4free as a local LLM server with an OpenAI-compatible REST API, custom model routing (config.yaml), and integration with bots like Clawbot or OpenClaw.
  5. ### Best Practices
  6. - Start the API server with: `python -m g4f --port 8080` (or use `g4f api --debug --port 8080`)
  7. - Use the `/v1` endpoint for OpenAI-compatible requests (e.g., POST to `http://localhost:8080/v1/chat/completions`)
  8. - Define custom model routes in `config.yaml` to aggregate/fallback across providers
  9. - Place `config.yaml` in your cookies directory (e.g., `~/.g4f/cookies/config.yaml`)
  10. - For Clawbot/OpenClaw, patch their config to point to your gpt4free server (see `patch-openclaw.py`)
  11. - Test with: `g4f client "Hello" --model openclaw` or Python client
  12. ### Common Pitfalls
  13. - Not starting the server before connecting bots
  14. - Incorrect config.yaml path or syntax errors
  15. - Missing required Python dependencies (install with `pip install -r requirements.txt`)
  16. - Not exposing the correct port (default 8080)
  17. - Forgetting to patch bot configs to use your local endpoint
  18. ### Workflow Steps
  19. 1. Install and set up gpt4free (see README)
  20. 2. Start the API server: `python -m g4f --port 8080`
  21. 3. (Optional) Create or edit `config.yaml` for custom model routing:
  22. ```yaml
  23. models:
  24. - name: "openclaw"
  25. providers:
  26. - provider: "GeminiCLI"
  27. model: "gemini-3-flash-preview"
  28. condition: "quota.models.gemini-3-flash-preview.remainingFraction > 0 and error_count < 3"
  29. - provider: "Antigravity"
  30. model: "gemini-3-flash"
  31. - provider: "PollinationsAI"
  32. model: "openai"
  33. ```
  34. 4. Patch your bot config (e.g., OpenClaw) to use `http://localhost:8080/v1` as the base URL (see `bin/patch-openclaw.py`)
  35. 5. Start your bot and verify it connects to gpt4free
  36. 6. Monitor logs and test with the Python client or CLI
  37. ### References
  38. - [README.md](../README.md)
  39. - [docs/config-yaml-routing.md](../docs/config-yaml-routing.md)
  40. - [bin/patch-openclaw.py](../bin/patch-openclaw.py)
  41. - [bin/setup-openclaw.sh](../bin/setup-openclaw.sh)
  42. - [g4f/client/__init__.py](../g4f/client/__init__.py)
README.md · README · 632 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. # GPT4Free (g4f)
  2. [![PyPI](https://img.shields.io/pypi/v/g4f)](https://pypi.org/project/g4f) [![Docker Hub](https://img.shields.io/badge/docker-hlohaus789%2Fg4f-blue)](https://hub.docker.com/r/hlohaus789/g4f) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-red.svg)](https://www.gnu.org/licenses/gpl-3.0.txt) [![PyPI Downloads](https://static.pepy.tech/personalized-badge/g4f?period=total&units=INTERNATIONAL_SYSTEM&left_color=GREY&right_color=GREEN&left_text=downloads)](https://pepy.tech/projects/g4f) ![GitHub Repo stars](https://img.shields.io/github/stars/xtekky/gpt4free)
  3. <p align="center">
  4. <!--img src="https://g4f.dev/docs/images/477107515-7f60c240-00fa-4c37-bf7f-ae5cc20906a1.png" alt="GPT4Free logo" height="200" /-->
  5. [<img alt="Community Day 2026" src="https://g4f.dev/community-day-2026/awards/Start.jpeg" />](https://g4f.dev/community-day-2026/awards/)
  6. </p>
  7. <p align="center">
  8. <span style="background: linear-gradient(45deg, #12c2e9, #c471ed, #f64f59); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
  9. <strong>Created by <a href="https://github.com/xtekky">@xtekky</a>,<br> maintained by <a href="https://github.com/hlohaus">@hlohaus</a></strong>
  10. </span>
  11. </p>
  12. <p align="center">
  13. <span>Support the project on</span>
  14. <a href="https://github.com/sponsors/hlohaus" target="_blank" rel="noopener noreferrer">
  15. GitHub Sponsors
  16. </a>
  17. ❤️
  18. </p>
  19. <p align="center">
  20. Live demo & docs: https://g4f.dev | Documentation: https://g4f.dev/docs
  21. </p>
  22. ---
  23. 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.
  24. This README is a consolidated, improved, and complete guide to installing, running, and contributing to GPT4Free.
  25. Table of contents
  26. - [What’s included](#whats-included)
  27. - [Quick links](#quick-links)
  28. - [Requirements & compatibility](#requirements--compatibility)
  29. - [Installation](#installation)
  30. - [Docker (recommended)](#docker-recommended)
  31. - [Slim Docker image](#slim-docker-image)
  32. - [Sandbox desktop (Docker)](#sandbox-desktop-docker)
  33. - [Windows (.exe)](#windows-exe)
  34. - [Python (pip / from source / partial installs)](#python-pip--from-source--partial-installs)
  35. - [Running the app](#running-the-app)
  36. - [GUI (web client)](#gui-web-client)
  37. - [FastAPI / Inference API](#fastapi--inference-api)
  38. - [CLI](#cli)
  39. - [Optional provider login (desktop in container)](#optional-provider-login-desktop-in-container)
  40. - [Using the Python client](#using-the-python-client)
  41. - [Synchronous text example](#synchronous-text-example)
  42. - [Image generation example](#image-generation-example)
  43. - [Async client example](#async-client-example)
  44. - [Using GPT4Free.js (browser JS client)](#using-gpt4freejs-browser-js-client)
  45. - [Providers & models (overview)](#providers--models-overview)
  46. - [Local inference & media](#local-inference--media)
  47. - [Configuration & customization](#configuration--customization)
  48. - [Running on smartphone](#running-on-smartphone)
  49. - [Inference API (OpenAI‑compatible)](#interference-api-openai-compatible)
  50. - [Examples & common patterns](#examples--common-patterns)
  51. - [Contributing](#contributing)
  52. - [How to create a new provider](#how-to-create-a-new-provider)
  53. - [How AI can help you write code](#how-ai-can-help-you-write-code)
  54. - [Security, privacy & takedown policy](#security-privacy--takedown-policy)
  55. - [Credits, contributors & attribution](#credits-contributors--attribution)
  56. - [Powered-by highlights](#powered-by-highlights)
  57. - [Changelog & releases](#changelog--releases)
  58. - [Manifesto / Project principles](#manifesto--project-principles)
  59. - [License](#license)
  60. - [Contact & sponsorship](#contact--sponsorship)
  61. - [Appendix: Quick commands & examples](#appendix-quick-commands--examples)
  62. ---
  63. ## What’s included
  64. - Python client library and async client.
  65. - Optional local web GUI.
  66. - FastAPI-based OpenAI-compatible API (Inference API).
  67. - Official browser JS client (g4f.dev distribution).
  68. - Docker images (full and slim).
  69. - Multi-provider adapters (LLMs, media providers, local inference backends).
  70. - Tooling for image/audio/video generation and media persistence.
  71. ---
  72. ## Quick links
  73. - Website & docs: https://g4f.dev | https://g4f.dev/docs
  74. - PyPI: https://pypi.org/project/g4f
  75. - Docker image: https://hub.docker.com/r/hlohaus789/g4f
  76. - Releases: https://github.com/xtekky/gpt4free/releases
  77. - Issues: https://github.com/xtekky/gpt4free/issues
  78. - Community: Telegram (https://telegram.me/g4f_channel) · Discord News (https://discord.gg/5E39JUWUFa) · Discord Support (https://discord.gg/qXA4Wf4Fsm)
  79. ---
  80. ## Related projects
  81. - [g4f-go](g4f-go/README.md) – Self-contained Go launcher for g4f (downloads CPython + g4f on demand; includes the `g4f-go sandbox` launcher for Docker, Podman and udocker)
  82. - [remote_desktop](projects/remote-desktop/) – WebRTC-based remote desktop host/viewer
  83. - [sandbox-desktop](https://g4f.dev/docs/sandbox-desktop) – TigerVNC + Xfce + noVNC desktop in Docker with preinstalled coding agents ([menu/tool list](docker/sandbox-menu/README.md), [start script](bin/start-sandbox-desktop.sh), [Dockerfile](docker/Dockerfile-sandbox-desktop))
  84. ---
  85. ## Requirements & compatibility
  86. - Python 3.10+ recommended.
  87. - Google Chrome/Chromium for providers using browser automation.
  88. - Docker for containerized deployment.
  89. - Works on x86_64 and arm64 (slim image supports both).
  90. - Some provider adapters may require platform-specific tooling (Chrome/Chromium, etc.). Check provider docs for details.
  91. ---
  92. ## Installation
  93. ### Docker (recommended)
  94. 1. Install Docker: https://docs.docker.com/get-docker/
  95. 2. Create persistent directories:
  96. - Example (Linux/macOS):
  97. ```bash
  98. mkdir -p ${PWD}/har_and_cookies ${PWD}/generated_media
  99. sudo chown -R 1200:1201 ${PWD}/har_and_cookies ${PWD}/generated_media
  100. ```
  101. 3. Pull image:
  102. ```bash
  103. docker pull hlohaus789/g4f
  104. ```
  105. 4. Run container:
  106. ```bash
  107. docker run -p 8080:8080 -p 7900:7900 \
  108. --shm-size="2g" \
  109. -v ${PWD}/har_and_cookies:/app/har_and_cookies \
  110. -v ${PWD}/generated_media:/app/generated_media \
  111. hlohaus789/g4f:latest
  112. ```
  113. Notes:
  114. - Port 8080 serves GUI/API; 7900 can expose a VNC-like desktop for provider logins (optional).
  115. - Increase --shm-size for heavier browser automation tasks.
  116. ### Slim Docker image (x64 & arm64)
  117. ```bash
  118. mkdir -p ${PWD}/har_and_cookies ${PWD}/generated_media
  119. chown -R 1000:1000 ${PWD}/har_and_cookies ${PWD}/generated_media
  120. docker run \
  121. -p 1337:8080 -p 8080:8080 \
  122. -v ${PWD}/har_and_cookies:/app/har_and_cookies \
  123. -v ${PWD}/generated_media:/app/generated_media \
  124. hlohaus789/g4f:latest-slim
  125. ```
  126. Notes:
  127. - The slim image can update the g4f package on startup and installs additional dependencies as needed.
  128. - In this example, the Inference API is mapped to 1337.
  129. ### Sandbox desktop (Docker)
  130. A full Xfce desktop (TigerVNC + noVNC) with the g4f API and a one-click
  131. **one-click** menu for 100+ AI tools and providers — coding agents,
  132. browsers, gateways, local runtimes and assistants. See
  133. [docs/sandbox-desktop](https://g4f.dev/docs/sandbox-desktop) for the start script,
  134. clipboard, scaling, app volume, user id, password and domain-routing options,
  135. and [docker/sandbox-menu/README.md](docker/sandbox-menu/README.md) for the
  136. menu, the tool list and the settings.
  137. ```bash
  138. docker run -d --name g4f-sandbox-desktop \
  139. --cap-add NET_ADMIN \
  140. -p 127.0.0.1:8080:8080 -p 127.0.0.1:5900:5900 \
  141. --shm-size="2gb" \
  142. -v ${PWD}:/app/gpt4free \
  143. -v ${PWD}/sandbox-home/.config:/home/pn/.config \
  144. -v ${PWD}/sandbox-home/.local:/home/pn/.local \
  145. hlohaus789/g4f:latest-sandbox-desktop
  146. ```
  147. - Desktop (browser): http://127.0.0.1:8080/desktop/ · API: http://127.0.0.1:8080/ · Direct VNC: `127.0.0.1:5900`
  148. - The ports bind to `127.0.0.1` by default (localhost only, not every host
  149. interface). Set `SANDBOX_BIND_ADDR=0.0.0.0` to expose the desktop on the LAN;
  150. `bin/start-sandbox-desktop.sh --bind <addr>` does the same.
  151. - The image starts an egress firewall (needs `--cap-add NET_ADMIN`): the
  152. sandbox can reach the public internet, but connections to private,
  153. link-local and reserved networks — the host LAN, other Docker networks and
  154. cloud metadata — are rejected. Loopback inside the container stays usable,
  155. so the g4f API, its `*.g4f.local` router and local gateways keep working.
  156. Replies to connections that come in from the host are allowed, so the
  157. published desktop/API ports stay reachable even though the host address is
  158. in a blocked range; the filter only stops the sandbox from starting such
  159. connections itself. Outbound file-sharing/sync protocols (SMB, NetBIOS,
  160. NFS, AFP, FTP/TFTP, rsync, iSCSI, rpcbind) and common crypto-mining pool
  161. ports are rejected too. Host-side services reached through
  162. `host.docker.internal`, `172.17.0.1` or the host's LAN address are blocked
  163. as well; run them inside the sandbox or set `SANDBOX_BLOCK_LOCAL_NETWORK=0`
  164. to disable the filter for a trusted setup. If the filter cannot be installed
  165. the sandbox still starts with a warning; set `SANDBOX_FIREWALL_STRICT=1` to
  166. make that fatal.
  167. - `-v ${PWD}:/app/gpt4free` mounts your app into the sandbox at the path the
  168. image's editable g4f install points at, so the API serves your code and the
  169. agents can edit it. Mount at `/app/gpt4free`, not `/app`.
  170. - `-v ${PWD}/sandbox-home/.config:/home/pn/.config` and `…/.local:/home/pn/.local`
  171. keep agent configs, credentials, caches and the sandbox settings across
  172. container restarts — without them every new container starts with an empty
  173. home and every tool asks for its login again. Do not mount over `/home/pn`
  174. itself: the embedded Python and g4f runtime live in `/home/pn/.g4f`.
  175. - To give the agents a throwaway profile instead, point `HOME` at a mounted
  176. directory: `-v ${PWD}/agent-home:/home/pn/work` plus **Sandbox Settings** →
  177. `sandbox-cli settings --home /home/pn/work`.
  178. - `bin/start-sandbox-desktop.sh` wraps the same run (and
  179. `docker/docker-compose.sandbox-desktop.yml`) with `--build`, `--pull`,
  180. `--port`, `--bind`, `--app-dir`, `--user-id`, `--api-key`,
  181. `--domain-suffix`, `--no-domain-router`, `shell`, `logs` and `stop`.
  182. `--api-key KEY` protects the desktop/API with a password (any username
  183. works in the browser login); see
  184. [docs/sandbox-desktop](https://g4f.dev/docs/sandbox-desktop).
  185. - The sandbox user (`pn`) runs with uid/gid 1000 by default. On a host whose
  186. user has another id, build the image with
  187. `--build-arg G4F_USER_ID="$(id -u)"` (or run
  188. `bin/start-sandbox-desktop.sh --user-id "$(id -u)"`; it rebuilds when the
  189. existing image was built for a different id). Matching the id keeps the
  190. bind-mounted `sandbox-home` and files written under `/app/gpt4free` owned by
  191. your host user.
  192. #### Sandbox launcher (`g4f-go sandbox`)
  193. Download `g4f-go` from the release assets for Windows, Linux, macOS or Termux
  194. (amd64/arm64). The `sandbox` subcommand requires only Docker, Podman or, on
  195. Termux/Android, udocker; it does not embed the image and pulls it on demand:
  196. ```bash
  197. g4f-go sandbox # small API-only sandbox (latest-slim)
  198. g4f-go sandbox --desktop # full desktop image, pulled on first use
  199. g4f-go sandbox --desktop install chrome
  200. g4f-go sandbox-cli list # shorthand for `g4f-go sandbox --desktop cli`
  201. g4f-go sandbox status
  202. g4f-go sandbox down
  203. ```
  204. The default API-only mode uses the multi-arch `latest-slim` image; `--desktop`
  205. pulls `latest-sandbox-desktop` only when the desktop is requested. Tools are
  206. installed on demand from the sandbox menu or with
  207. `g4f-go sandbox --desktop install <tool>`. On Termux/Android the same command
  208. uses udocker (installed with pip on first use) to run those images without
  209. root; the native API-only backend is still available with `--backend termux`.
  210. See [g4f-go](g4f-go/README.md) and the
  211. [sandbox desktop documentation](https://g4f.dev/docs/sandbox-desktop).
  212. ### Python Installation (pip / from source / partial installs)
  213. Prerequisites:
  214. - Python 3.10+ (https://www.python.org/downloads/)
  215. - Chrome/Chromium for some providers.
  216. Install from PyPI (recommended):
  217. ```bash
  218. pip install -U g4f[all]
  219. ```
  220. Partial installs
  221. - To install only specific functionality, use optional extras groups. See [docs/requirements](https://g4f.dev/docs/requirements) in the project docs.
  222. Install from source:
  223. ```bash
  224. git clone https://github.com/xtekky/gpt4free.git
  225. cd gpt4free
  226. pip install -r requirements.txt
  227. pip install -e .
  228. ```
  229. Notes:
  230. - Some features require Chrome/Chromium or other tools; follow provider-specific docs.
  231. ---
  232. ## Running the app
  233. ### GUI (web client)
  234. - Run via Python:
  235. ```python
  236. from g4f.gui import run_gui
  237. run_gui()
  238. ```
  239. - Or via CLI:
  240. ```bash
  241. python -m g4f.cli gui --port 8080 --debug
  242. ```
  243. - Open: http://localhost:8080/chat/
  244. ### FastAPI / Inference API
  245. - Start FastAPI server:
  246. ```bash
  247. python -m g4f --port 8080 --debug
  248. ```
  249. - If using slim docker mapping, Inference API may be available at `http://localhost:1337/v1`
  250. - Swagger UI: `http://localhost:1337/docs`
  251. ### CLI
  252. - Start GUI server:
  253. ```bash
  254. python -m g4f.cli gui --port 8080 --debug
  255. ```
  256. ### MCP Server
  257. GPT4Free now includes a Model Context Protocol (MCP) server that allows AI assistants like Claude to access web search, scraping, and image generation capabilities.
  258. **Starting the MCP server (stdio mode):**
  259. ```bash
  260. # Using g4f command
  261. g4f mcp
  262. # Or using Python module
  263. python -m g4f.mcp
  264. ```
  265. **Starting the MCP server (HTTP mode):**
  266. ```bash
  267. # Start HTTP server on port 8765
  268. g4f mcp --http --port 8765
  269. # Custom host and port
  270. g4f mcp --http --host 127.0.0.1 --port 3000
  271. ```
  272. HTTP mode provides:
  273. - `POST http://localhost:8765/mcp` - JSON-RPC endpoint
  274. - `GET http://localhost:8765/health` - Health check
  275. **Configuring with Claude Desktop:**
  276. Add to your `claude_desktop_config.json`:
  277. ```json
  278. {
  279. "mcpServers": {
  280. "gpt4free": {
  281. "command": "python",
  282. "args": ["-m", "g4f.mcp"]
  283. }
  284. }
  285. }
  286. ```
  287. **Available MCP Tools:**
  288. - `web_search` - Search the web using DuckDuckGo
  289. - `web_scrape` - Extract text content from web pages
  290. - `image_generation` - Generate images from text prompts
  291. - `polli_publish_app` - Publish a built app from the workspace to
  292. `https://<name>.pollinations.app` with the Pollinations CLI
  293. For detailed MCP documentation, see [g4f/mcp/README.md](g4f/mcp/README.md)
  294. ### Optional provider login (desktop within container)
  295. - Accessible at:
  296. ```
  297. http://localhost:7900/?autoconnect=1&resize=scale&password=secret
  298. ```
  299. - Useful for logging into web-based providers to obtain cookies/HAR files.
  300. ---
  301. ## Using the Python client
  302. Install:
  303. ```bash
  304. pip install -U g4f[all]
  305. ```
  306. Synchronous text example:
  307. ```python
  308. from g4f.client import Client
  309. client = Client()
  310. response = client.chat.completions.create(
  311. model="auto",
  312. messages=[{"role": "user", "content": "Hello, how are you?"}],
  313. web_search=False
  314. )
  315. print(response.choices[0].message.content)
  316. ```
  317. Expected:
  318. ```
  319. Hello! How can I assist you today?
  320. ```
  321. Image generation example:
  322. ```python
  323. from g4f.client import Client
  324. client = Client()
  325. response = client.images.generate(
  326. model="flux",
  327. prompt="a white siamese cat",
  328. response_format="url"
  329. )
  330. print(f"Generated image URL: {response.data[0].url}")
  331. ```
  332. Async client example:
  333. ```python
  334. from g4f.client import AsyncClient
  335. import asyncio
  336. async def main():
  337. client = AsyncClient()
  338. response = await client.chat.completions.create(
  339. model="auto",
  340. messages=[{"role": "user", "content": "Explain quantum computing briefly"}],
  341. )
  342. print(response.choices[0].message.content)
  343. asyncio.run(main())
  344. ```
  345. Notes:
  346. - See the full API reference for streaming, tool-calling patterns, and advanced options: https://g4f.dev/docs/client
  347. ---
  348. ## Using GPT4Free.js (browser JS client)
  349. Use the official JS client in the browser—no backend required.
  350. Example:
  351. ```html
  352. <script type="module">
  353. import Client from 'https://g4f.dev/dist/js/client.js';
  354. const client = new Client();
  355. const result = await client.chat.completions.create({
  356. model: 'auto', // Or "glm-5.3", "kimi-k3", etc.
  357. messages: [{ role: 'user', content: 'Explain quantum computing' }]
  358. });
  359. console.log(result.choices[0].message.content);
  360. </script>
  361. ```
  362. Notes:
  363. - The JS client is distributed via the g4f.dev CDN for easy usage. Review CORS considerations and usage limits.
  364. ---
  365. ## Providers & models (overview)
  366. - GPT4Free integrates many providers including (but not limited to) OpenAI-compatible endpoints, PerplexityLabs, Gemini, MetaAI, Pollinations (media), and local inference backends.
  367. - 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
  368. Provider requirements may include:
  369. - API keys or tokens (for authenticated providers)
  370. - Browser cookies / HAR files for providers scraped via browser automation
  371. - Chrome/Chromium or headless browser tooling
  372. - Local model binaries and runtime (for local inference)
  373. ---
  374. ## Local inference & media
  375. - GPT4Free supports local inference backends. See [docs/local](https://g4f.dev/docs/local) for supported runtimes and hardware guidance.
  376. - Media generation (image, audio, video) is supported through providers (e.g., Pollinations). See [docs/media](https://g4f.dev/docs/media) for formats, options, and sample usage.
  377. ---
  378. ## Configuration & customization
  379. - Configure via environment variables, CLI flags, or config files. See [docs/config](https://g4f.dev/docs/config).
  380. - To reduce install size, use partial requirement groups. See [docs/requirements](https://g4f.dev/docs/requirements).
  381. - Provider selection: learn how to set defaults and override per-request at [docs/selecting_a_provider](https://g4f.dev/docs/selecting_a_provider).
  382. - Persistence: HAR files, cookies, and generated media persist in mapped directories (e.g., har_and_cookies, generated_media).
  383. ---
  384. ## Running on smartphone
  385. - 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](https://g4f.dev/docs/guides/phone).
  386. ---
  387. ## Inference API (OpenAI‑compatible)
  388. - The Inference API enables OpenAI-like workflows routed through GPT4Free provider selection.
  389. - Docs: [docs/interference-api](https://g4f.dev/docs/interference-api)
  390. - Default endpoint (example slim docker): `http://localhost:1337/v1`
  391. - Swagger UI: `http://localhost:1337/docs`
  392. ---
  393. ## Examples & common patterns
  394. - Streaming completions, stopping criteria, system messages, and tool-calling patterns are documented in:
  395. - [docs/client](https://g4f.dev/docs/client)
  396. - [docs/async_client](https://g4f.dev/docs/async_client)
  397. - [docs/requests](https://g4f.dev/docs/requests)
  398. - Integrations (LangChain, PydanticAI): [docs/pydantic_ai](https://g4f.dev/docs/pydantic_ai)
  399. - Legacy examples: [docs/legacy](https://g4f.dev/docs/legacy)
  400. ---
  401. ## Contributing
  402. Contributions are welcome — new providers, features, docs, and fixes are appreciated.
  403. How to contribute:
  404. 1. Fork the repository.
  405. 2. Create a branch for your change.
  406. 3. Run tests and linters.
  407. 4. Open a Pull Request with a clear description and tests/examples if applicable.
  408. Repository: https://github.com/xtekky/gpt4free
  409. ### How to create a new provider
  410. - Read the guide: [docs/guides/create_provider](https://g4f.dev/docs/guides/create_provider)
  411. - Typical steps:
  412. - Implement a provider adapter in `g4f/Provider/`
  413. - Add configuration and dependency notes
  414. - Include tests and usage examples
  415. - Respect third‑party code licenses and attribute appropriately
  416. ### How AI can help you write code
  417. - See: [docs/guides/help_me](https://g4f.dev/docs/guides/help_me) for prompt templates and workflows to accelerate development.
  418. - Automatic development loop: [docs/dev-pipeline](https://g4f.dev/docs/dev-pipeline) explains `bin/dev-pipeline`, which reads tasks from `AGENTS.md` and implements them with working free models from pi-freeflow.
  419. ---
  420. ## Security, privacy & takedown policy
  421. - Do not store or share sensitive credentials. Use per-provider recommended security practices.
  422. - Conversations are stored locally on your device by default; server/cloud synchronization (Secret Storage) is strictly opt-in and client-side encrypted.
  423. - 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.
  424. - For production, secure the server with HTTPS, authentication, and firewall rules. Limit access to provider credentials and cookie/HAR storage.
  425. ---
  426. ## Credits, contributors & attribution
  427. - Core creators: [@xtekky](https://github.com/xtekky) (original), maintained by [@hlohaus](https://github.com/hlohaus).
  428. - Full contributor graph: https://github.com/xtekky/gpt4free/graphs/contributors
  429. Many more contributors are acknowledged in the repository.
  430. ---
  431. ## Powered-by highlights
  432. - Pollinations AI — generative media: https://github.com/pollinations/pollinations
  433. - MoneyPrinter V2 — example project using GPT4Free: https://github.com/FujiwaraChoki/MoneyPrinterV2
  434. - For a full list of projects and sites using GPT4Free, see: [docs/powered-by](https://g4f.dev/docs/powered-by)
  435. ---
  436. ## Changelog & releases
  437. - Releases and full changelog: https://github.com/xtekky/gpt4free/releases
  438. - Subscribe to Discord/Telegram for announcements.
  439. ---
  440. ## Manifesto / Project principles
  441. GPT4Free is guided by community principles:
  442. 1. Open access to AI tooling and models.
  443. 2. Collaboration across providers and projects.
  444. 3. Opposition to monopolistic, closed systems that restrict creativity.
  445. 4. Community-centered development and broad access to AI technologies.
  446. 5. Promote innovation, creativity, and accessibility.
  447. https://g4f.dev/manifesto
  448. ---
  449. ## License
  450. 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
  451. Summary:
  452. - You may redistribute and/or modify under the terms of GPLv3.
  453. - The program is provided WITHOUT ANY WARRANTY.
  454. Copyright notice
  455. ```
  456. xtekky/gpt4free: Copyright (C) 2025 xtekky
  457. This program is free software: you can redistribute it and/or modify
  458. it under the terms of the GNU General Public License as published by
  459. the Free Software Foundation, either version 3 of the License, or
  460. (at your option) any later version.
  461. This program is distributed in the hope that it will be useful,
  462. but WITHOUT ANY WARRANTY; without even the implied warranty of
  463. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  464. GNU General Public License for more details.
  465. ```
  466. ---
  467. ## Contact & sponsorship
  468. - Maintainers: https://github.com/hlohaus
  469. - Community & contact: https://g4f.dev/community
  470. - Sponsorship: https://github.com/sponsors/hlohaus
  471. - Issues & feature requests: https://github.com/xtekky/gpt4free/issues
  472. ---
  473. ## Appendix: Quick commands & examples
  474. Install g4f-go (launcher):
  475. ```bash
  476. curl -fsSL https://raw.githubusercontent.com/xtekky/gpt4free/main/bin/install.sh | bash
  477. ```
  478. Install (pip):
  479. ```bash
  480. pip install -U g4f[all]
  481. ```
  482. Run GUI (Python):
  483. ```bash
  484. python -m g4f.cli gui --port 8080 --debug
  485. # or
  486. python -c "from g4f.gui import run_gui; run_gui()"
  487. ```
  488. Docker (full):
  489. ```bash
  490. docker pull hlohaus789/g4f
  491. docker run -p 8080:8080 -p 7900:7900 \
  492. --shm-size="2g" \
  493. -v ${PWD}/har_and_cookies:/app/har_and_cookies \
  494. -v ${PWD}/generated_media:/app/generated_media \
  495. hlohaus789/g4f:latest
  496. ```
  497. Docker (slim):
  498. ```bash
  499. docker run -p 1337:8080 -p 8080:8080 \
  500. -v ${PWD}/har_and_cookies:/app/har_and_cookies \
  501. -v ${PWD}/generated_media:/app/generated_media \
  502. hlohaus789/g4f:latest-slim
  503. ```
  504. Python usage patterns:
  505. - `client.chat.completions.create(...)`
  506. - `client.images.generate(...)`
  507. - Async variants via `AsyncClient`
  508. Docs & deeper reading
  509. - Full docs: https://g4f.dev/docs
  510. - Client API docs: https://g4f.dev/docs/client
  511. - Async client docs: https://g4f.dev/docs/async_client
  512. - Provider guides: https://g4f.dev/docs/providers
  513. - Local inference: https://g4f.dev/docs/local
  514. ---
  515. Thank you for using and contributing to GPT4Free — together we make powerful AI tooling accessible, flexible, and community-driven.
bin/setup-openclaw.sh · Bundled script · 162 lines · 1 finding marked
  1. #!/bin/bash
  2. # gpt4free-style OpenClaw route setup
  3. # Works on: macOS, Linux, Windows (WSL/Git Bash/MSYS2)
  4. # Usage: curl -fsSL https://raw.githubusercontent.com/xtekky/gpt4free/main/bin/setup-openclaw.sh | bash -s -- <POLLINATIONS_API_KEY>
    • Note: Pipes a downloaded script directly into a shell (curl | sh / wget | bash)
    • Line 5 on GitHub
  5. set -e
  6. if [ -z "$1" ]; then
  7. echo "No API key provided. Proceeding without an API key."
  8. API_KEY=""
  9. else
  10. API_KEY="$1"
  11. fi
  12. if ! command -v python >/dev/null 2>&1; then
  13. echo "Python not found. Please install Python 3.10+ first."
  14. exit 1
  15. fi
  16. if ! python -m g4f --help >/dev/null 2>&1; then
  17. echo "g4f not installed. Installing with pip..."
  18. python -m pip install -U g4f[all]
  19. fi
  20. CONFIG_DIR="${HOME}/.g4f/cookies"
  21. CONFIG_FILE="${CONFIG_DIR}/config.yaml"
  22. ENV_FILE="${CONFIG_DIR}/.env"
  23. mkdir -p "${CONFIG_DIR}"
  24. cat > "${CONFIG_FILE}" <<'EOF'
  25. models:
  26. - name: "openclaw"
  27. providers:
  28. - provider: "GeminiCLI"
  29. model: "gemini-3-flash-preview"
  30. condition: "quota.models.gemini-3-flash-preview.remainingFraction > 0 and error_count < 3"
  31. - provider: "Antigravity"
  32. model: "gemini-3-flash"
  33. condition: "quota.models.gemini-3-flash.quotaInfo.remainingFraction > 0 and error_count < 3"
  34. - provider: "PollinationsAI"
  35. model: "openai"
  36. condition: "balance > 0 or error_count < 3"
  37. EOF
  38. cat > "${ENV_FILE}" <<EOF
  39. POLLINATIONS_API_KEY=${API_KEY}
  40. OPENAI_API_KEY=
  41. GEMINI_API_KEY=
  42. EOF
  43. # OpenClaw onboarding and configuration (if available)
  44. if command -v openclaw >/dev/null 2>&1; then
  45. echo "OpenClaw CLI found. Configuring OpenClaw..."
  46. OPENCLAW_CONFIG_FILE="${HOME}/.openclaw/openclaw.json"
  47. mkdir -p "${HOME}/.openclaw"
  48. if [ ! -f "${OPENCLAW_CONFIG_FILE}" ]; then
  49. echo "Fresh install — running OpenClaw setup..."
  50. openclaw onboard \
  51. --non-interactive \
  52. --accept-risk \
  53. --mode local \
  54. --flow quickstart \
  55. --auth-choice custom-api-key \
  56. --custom-base-url "http://localhost:8080/v1" \
  57. --custom-provider-id gpt4free \
  58. --custom-model-id openclaw \
  59. --custom-api-key "${API_KEY}" \
  60. --secret-input-mode plaintext \
  61. --skip-channels \
  62. --skip-daemon \
  63. --skip-skills \
  64. --skip-ui \
  65. --skip-health \
  66. 2>&1 | grep -v "^$" || true
  67. else
  68. echo "OpenClaw config already exists at ${OPENCLAW_CONFIG_FILE}, skipping onboard."
  69. fi
  70. echo "Patching OpenClaw provider and model list..."
  71. echo "using Python to patch OpenClaw config..."
  72. python - <<PYEOF
  73. import json, sys, os
  74. config_file = os.path.expanduser("~/.openclaw/openclaw.json")
  75. provider = {
  76. "baseUrl": "http://localhost:8080/v1",
  77. "api": "openai-completions",
  78. "models": [
  79. {
  80. "id": "openclaw",
  81. "name": "Custom GPT4Free",
  82. "reasoning": True,
  83. "input": ["text", "image"],
  84. "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
  85. "contextWindow": 256000,
  86. "maxTokens": 8192,
  87. }
  88. ],
  89. }
  90. try:
  91. with open(config_file) as f:
  92. cfg = json.load(f)
  93. except (FileNotFoundError, json.JSONDecodeError):
  94. cfg = {}
  95. cfg.setdefault("models", {})["providers"] = cfg.get("models", {}).get("providers", {})
  96. cfg["models"]["providers"]["gpt4free"] = provider
  97. cfg["models"]["providers"]["g4f-perplexity"] = {
  98. "baseUrl": "https://perplexity.g4f-dev.workers.dev",
  99. "api": "openai-completions",
  100. "models": [
  101. {
  102. "id": "turbo",
  103. "name": "perplexity"
  104. }
  105. ]
  106. }
  107. cfg["tools"] = cfg.get("tools", {})
  108. cfg["tools"]["web"] = cfg["tools"].get("web", {})
  109. cfg["tools"]["web"]["search"] = {
  110. "provider": "g4f-perplexity",
  111. }
  112. with open(config_file, "w") as f:
  113. json.dump(cfg, f, indent=2)
  114. print("OpenClaw config patched via Python.")
  115. PYEOF
  116. # apply models with openclaw commands if available
  117. openclaw models set gpt4free/openclaw >/dev/null 2>&1 || true
  118. openclaw gateway restart >/dev/null 2>&1 || true
  119. else
  120. echo "OpenClaw CLI not found; skipping OpenClaw setup steps."
  121. fi
  122. printf "\n🚀 OpenClaw route configured in %s\n" "${CONFIG_FILE}"
  123. printf "✅ .env written to %s\n" "${ENV_FILE}"
  124. cat <<'INFO'
  125. Next steps:
  126. g4f client "Hello OpenClaw" --model openclaw
  127. or use python:
  128. from g4f.client import Client
  129. client = Client()
  130. resp = client.chat.completions.create(model='openclaw', messages=[{'role':'user','content':'Hello'}])
  131. print(resp.choices[0].message.content)
  132. Start the server:
  133. g4f api --debug --port 8080
  134. And auth into Antigravity and GeminiCLI (or any other provider you wish to use).
  135. For more setting options, edit config.yaml and add other providers or condition values.
  136. INFO
etc/examples/openaichat.py · Bundled script · 20 lines · 1 finding marked
  1. from g4f.client import Client
  2. from g4f.Provider import OpenaiChat, RetryProvider
  3. # compatible countries: https://pastebin.com/UK0gT9cn
    • Note: Quoted as data in code: Links to a paste site (pastebin.com), a common place to stage installer commands or send stolen data
    • Line 4 on GitHub
  4. client = Client(
  5. proxies={
  6. "http": "http://username:password@host:port", # MUST BE WORKING OPENAI COUNTRY PROXY ex: USA
  7. "https": "http://username:password@host:port", # MUST BE WORKING OPENAI COUNTRY PROXY ex: USA
  8. },
  9. provider=RetryProvider([OpenaiChat], single_provider_retry=True, max_retries=5),
  10. )
  11. messages = [{"role": "user", "content": "Hello"}]
  12. response = client.chat.completions.create(
  13. model="gpt-3.5-turbo", messages=messages, stream=True
  14. )
  15. for message in response:
  16. print(message.choices[0].delta.content or "")

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.