GPT4Free Documentation Hub
Welcome to the official docs for GPT4Free β free and convenient AI endpoints you can use directly in your apps, scripts, and browser. Here youβll find clear overviews, quick examples, and entry points to deeper docs for every major feature.
Installation & Setup
For full install guides β choose your method:
For rapid starts, you can use either Python or JavaScript (web).
Getting Started
π Text Generation
Python example for chat completion (with and without web search):
from g4f.client import Client
client = Client()
response = client.chat.completions.create(
model="gpt-4.1", # Try "gpt-4o", "deepseek-v3", etc.
messages=[{"role": "user", "content": "Hello"}],
web_search=False
)
print(response.choices.message.content)
Output:
Hello! How can I assist you today?
π¨ Image Generation
Generate images with a single call (returns URLs or base64):
from g4f.client import Client
client = Client()
response = client.images.generate(
model="flux", # Other models: 'dalle-3', 'gpt-image', etc.
prompt="a white siamese cat",
response_format="url"
)
print(f"Generated image URL: {response.data.url}")
More Python client info β and Async client β
π§ββοΈ Using GPT4Free.js
Use the official JS client right in the browserβno backend needed.
For text generation:
<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', // Or "gpt-4o", "deepseek-v3"
messages: [{ role: 'user', content: 'Explain quantum computing' }]
});
console.log(result.choices[0].message.content);
</script>
And for image generation:
<script type="module">
import Client from 'https://g4f.dev/dist/js/client.js';
const client = new Client();
const response = await client.images.generate({
model: "flux", // Or "dalle-3", "gpt-image"
prompt: "a white siamese cat"
});
const imageUrl = response.data.url;
console.log(`Generated Image URL: ${imageUrl}`);
// Example: document.body.innerHTML += `<img src="${imageUrl}" />`;
</script>
π» Using CLI Client
$ g4f client "Explain quantum computing"
Deep Dives
- Available Providers & Models
- Selecting a Provider
- API docs (full spec)
- File API Documentation (Files and Documents)
- Media Documentation (Audio, Image and Video)
- Vision Support (Image Upload)
- Image Editing Variation Documentation
- Authentication, Configuration Guide (.har and cookies)
- Advanced: Create your own Provider
- Integrations: LangChain, PydanticAI
- GUI/WebUI, Phone, Backend API
- Troubleshooting
Community & Links
-
Open Source: GitHub: gpt4free/g4f.dev
-
Contribute & Report Bugs: PRs & issues are welcome!
-
Project Website: https://g4f.dev/
-
Pollinations AI:
GitHub: pollinations/pollinations
GPT4Free and g4f.dev are continuously improving. Have fun building, and let the bots do the heavy lifting for you!