GPT4Free (g4f) is a tool that provides access to GPT-4/5, Claude, Gemini, and DeepSeek models via reverse engineering of public APIs.
⚠️ Note: for educational and testing purposes only. May violate some services’ terms.
Installation
Requirements
- Computer with internet access
- Python 3.10+ (check “Add to PATH” during installation)
Install command
pip install -U g4f[all]
Launch
Option 1: Web UI
python -m g4f.cli gui --port 8080
Interface: http://localhost:8080/chat/
Option 2: Local API
python -m g4f --port 1337
After launch, applications supporting the OpenAI API can connect to it.
First Script
Create test.py:
from g4f.client import Client
client = Client()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Why is potato a state of mind?"}]
)
print(response.choices[0].message.content)
Run:
python test.py
Image Generation
from g4f.client import Client
client = Client()
img = client.images.generate(
model="flux",
prompt="Cyberpunk potato in a neon city",
response_format="url"
)
print(f"Done: {img.data[0].url}")
Available Models (March 2026)
| Model | Status | Purpose |
|---|---|---|
gpt-4o-mini | ✅ Stable | Fast responses, chat |
gpt-4o | ✅ Stable | Complex tasks |
deepseek-v3 | ✅ Stable | Code, math, logic |
gemini-2.5-pro | ⚠️ Intermittent | Multimodal tasks |
llama-3.3-70b | ✅ Stable | Open-source alternative |
gpt-5 | 🔶 Experimental | May not work |
💡 The list changes frequently. Get the current list via the web interface or request:
GET http://localhost:8080/backend-api/models
Connecting to OpenAI-compatible Apps
After running python -m g4f --port 1337:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:1337/v1",
api_key="doesnt-matter" # any value works
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Tell me a potato joke"}]
)
print(response.choices[0].message.content)
Compatible with LibreChat, Flowise, AnythingLLM, and others.
Diagnostics
# Update library
pip install -U g4f
# Install errors on Windows
pip install --upgrade pip setuptools wheel
# Model not responding
# → Try a different model
# → Enable VPN
# → Wait 10-30 seconds (some providers are slow)
# When using Docker, add more shared memory for the browser:
docker run -p 8080:8080 --shm-size="2g" hlohaus789/g4f:latest
Docker
docker run -p 8080:8080 --shm-size="2g" hlohaus789/g4f:latest
- Web UI:
http://localhost:8080 - API:
http://localhost:8080/v1