xtekky/gpt4free — gpt4free: Universal AI Access Layer
Transcript
QuickFacts
Welcome! Today we're diving into gpt4free, a really clever Python project that lets you talk to dozens of AI models—ChatGPT, Claude, Gemini, Perplexity—through one simple interface, without juggling API keys or subscriptions.
PlainEnglish
Think of gpt4free as a universal adapter for AI. You write your code once using a familiar OpenAI-style API, and it figures out which service to use, how to authenticate, and how to translate responses back into a format you can work with.
QuickFacts
Let's look at the tech stack. It's Python-based with a heavy focus on async IO, so it can talk to multiple AI services in parallel. The network layer uses curl with browser impersonation to avoid bot detection, and even includes a headless browser for sites that need interactive logins. On top, you've got FastAPI serving OpenAI-compatible REST endpoints, and Flask powering a friendly web chat UI.
Architecture
Here's the architecture at a glance. Your code talks to a client, which asks the service router to figure out which provider can handle your chosen model. The router picks an adapter, which grabs credentials from the auth layer and sends the request to the upstream API. Responses stream back through the same path, normalized into a consistent format you can use.
Architecture
The heart of the system is the provider adapters. There are over thirty-five of them, one for each AI service. Each adapter knows how to speak that service's language—whether it's a WebSocket connection, server-sent events, or even scraping HTML. They all inherit from a common base class that enforces one rule: you give it a model and messages, and it hands back an async generator yielding response chunks.
Architecture
Let's trace a request from start to finish. You call chat completions create with a model name and messages. The client asks the router to figure out which provider handles that model. The router picks an adapter, which makes the actual HTTP or WebSocket call to the upstream service. As the response streams back, the adapter normalizes each chunk into a typed object, the client wraps it in an OpenAI-compatible format, and you get your final result.
Architecture
Authentication is really flexible. One common flow uses HAR files. You log into a service in your browser, save a network recording, drop the HAR file into a specific folder, and g4f reads it to extract your cookies and headers. Now the provider can reuse those credentials to make authenticated requests without you having to log in every time.
Architecture
And here's where it gets exciting. gpt4free connects to over thirty-five different AI services. We're talking OpenAI, Microsoft Copilot, Perplexity, Pollinations for images, Google Gemini, HuggingFace, Cloudflare's worker AI, DeepInfra, and many more. You pick a model, and g4f routes your request to the right service behind the scenes.
Architecture
You can use gpt4free in two ways. As a Python library, you just import the client and call create—perfect for scripts or apps. Or, you can run it as an API server using Docker or the CLI. It exposes OpenAI-compatible REST endpoints, so you can point tools like LangChain or Cursor at it without changing a line of code.
PlainEnglish
Here's what it looks like in practice. You install g4f with pip, import the client, and call create with a model name and messages. Want to switch from GPT-4 to Claude? Just change the model string. g4f handles all the routing, authentication, and response formatting automatically.
Community
Let's check in on the community. The repo is actively maintained, with a commit as recent as yesterday. The primary maintainer, Tekky, is keeping the project alive and responding to the ever-changing landscape of AI provider APIs. With multiple branches and steady activity, this is a project that's very much in motion.
PlainEnglish
So there you have it. gpt4free is your universal adapter for the AI ecosystem. One consistent API, access to dozens of models, and you never have to juggle subscriptions or API keys. It's open, it's flexible, and it's ready to plug into your projects today. Thanks for exploring with us!
How this was made
Lenzon read xtekky/gpt4free and generated this walkthrough automatically. The narration above is the transcript of what it says.
Explain a pull request from your own repo
Point Lenzon at a repo or a pull request and get a narrated walkthrough like this one.
Try it