Skip to content

kodelyx/chatgpt-free-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Free ChatGPT API Banner

πŸ”“ Free ChatGPT API

A high-performance, OpenAI-compatible API server written in Go that gives you free access to ChatGPT β€” including GPT-5.5, GPT-4o, GPT Image Generation, and more. No API key required. Fully automated session authentication via a lightweight Chrome extension.


πŸ€” Why Use This?

Problem Solution
OpenAI API costs $20+/month This is 100% free
API keys get leaked and abused No API keys needed
Rate limits on free tiers Uses your own ChatGPT session
Complex auth setup One-click Chrome extension auto-syncs cookies
Want OpenAI-compatible endpoints Drop-in replacement for /v1/chat/completions

✨ Features

  • πŸ’¬ OpenAI Chat Completions β€” Standard /v1/chat/completions endpoint, works with any OpenAI client library
  • 🎨 Image Generation β€” Generate images via ChatGPT's built-in DALL-E, auto-downloaded to output/
  • πŸ”„ Conversation Persistence β€” Same conversation continues across requests (no rate limit issues from new chats)
  • πŸ”Œ Chrome Cookie Bridge β€” Lightweight extension auto-syncs your ChatGPT session cookies via WebSocket
  • ⚑ Zero Config β€” Just set port and model in .env, everything else is hardcoded for reliability
  • 🧠 Multi-Model Support β€” GPT-5.5, GPT-4o, GPT-4o-mini, o3, o4-mini and more

πŸ—οΈ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Your App    │────▢│  Go API Server   │────▢│  ChatGPT Web    β”‚
β”‚  (curl/SDK)  │◀────│  (localhost:9225) │◀────│  (chatgpt.com)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β–²
                           β”‚ WebSocket (cookies)
                    β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Chrome     β”‚
                    β”‚  Extension   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. Chrome Extension captures your ChatGPT session cookies and sends them to the Go server via WebSocket
  2. Go Server receives your API request at /v1/chat/completions
  3. Server forwards the request to ChatGPT's web backend using your session cookies
  4. Response is formatted as a standard OpenAI API response and returned to your app

πŸš€ Quick Start & Docker Deployment

1. Build and Run in Docker (Recommended)

You can run the API server inside a Docker container:

# Build the Docker image
docker build -t chatgpt-free-api:latest .

# Run the container (binds to host port 9225)
docker run -d \
  --name chatgpt-free-api \
  -p 9225:9225 \
  --restart unless-stopped \
  chatgpt-free-api:latest

To build/run locally without Docker:

go run .

2. Install Chrome Extension

  1. Open chrome://extensions/ in Chrome.
  2. Enable Developer mode (top right toggle).
  3. Click Load unpacked (top left button) β†’ select the gpt-extension/ folder in this repository.
  4. Open chatgpt.com and log in.
  5. Click on the extension icon. By default, it connects to port 9225.

    [!TIP] If you configured the server to run on a different port, you can change the Server Port inside the extension popup UI directly. It will dynamically save and reconnect to the new port without reloading the extension.

3. Start Using

# Chat (OpenAI-compatible)
curl -X POST http://localhost:9225/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

πŸ“‘ API Reference

POST /v1/chat/completions (OpenAI-Compatible)

Request:

{
  "model": "gpt-5-5",
  "messages": [
    {"role": "user", "content": "Your prompt here"}
  ],
  "conversation_id": "optional-to-continue-chat"
}

Response:

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "gpt-5-5",
  "conversation_id": "6a404fee-921c-83ee-850e-f2a582c56e7c",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "Hello!"},
      "finish_reason": "stop"
    }
  ]
}

POST /api/chat (Native Endpoint)

{
  "prompt": "Your message",
  "conversation_id": "",
  "model": "gpt-5-5"
}

Other Endpoints

Endpoint Method Description
/v1/chat/completions POST OpenAI-compatible chat
/api/chat GET/POST Native chat endpoint
/api/chat/bulk POST Batch multiple prompts
/api/chat/edit POST Edit last message
/api/sniffs GET View request logs
/health GET Server health check

βš™οΈ Configuration

Only 2 values in .env β€” everything else is hardcoded for stability:

LISTEN_ADDR=127.0.0.1:9225
DEFAULT_MODEL=gpt-5-5
Variable Default Description
LISTEN_ADDR 127.0.0.1:9225 Server address and port
DEFAULT_MODEL gpt-5-5 Default ChatGPT model

πŸ“‚ Project Structure

chatgpt-free-api/
β”œβ”€β”€ main.go                 # Entry point
β”œβ”€β”€ .env                    # Server config (port + model)
β”œβ”€β”€ chatgpt/                # Core Go source code
β”‚   β”œβ”€β”€ agent.go            # Server bootstrap & routing
β”‚   β”œβ”€β”€ handlers.go         # HTTP request handlers
β”‚   β”œβ”€β”€ chatgpt.go          # ChatGPT web client & WebSocket bridge
β”‚   β”œβ”€β”€ config.go           # .env config loader
β”‚   β”œβ”€β”€ cookies.go          # Cookie management
β”‚   β”œβ”€β”€ api_bridge.go       # Image download bridge
β”‚   β”œβ”€β”€ extension.go        # Chrome extension WebSocket handler
β”‚   β”œβ”€β”€ helpers.go          # Utility functions
β”‚   └── sniff.go            # Request logging/sniffing
β”œβ”€β”€ gpt-extension/          # Chrome extension
β”‚   β”œβ”€β”€ manifest.json
β”‚   β”œβ”€β”€ background.js
β”‚   β”œβ”€β”€ popup.html
β”‚   └── popup.js
└── output/                 # Auto-downloaded generated images

πŸ”’ Security Note

This tool uses your own ChatGPT session β€” it does not share credentials with any third party. All communication happens between your local machine and ChatGPT's servers. The Chrome extension only sends cookies to localhost.


πŸ“œ License

MIT License β€” free to use, modify, and distribute.

About

πŸ”“ Use ChatGPT for FREE β€” Chat, Image Generation & Code. OpenAI-compatible API. No API key needed. Built in Go.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors