Skip to content
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

227 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ChatMock
Stars Badge Forks Badge Pull Requests Badge Issues Badge GitHub contributors License Badge

Production-ready OpenAI & Ollama compatible API powered by your ChatGPT plan.

Use your ChatGPT Plus/Pro account to call OpenAI models from code or alternate chat UIs.

Now with high-performance server, web dashboard, and automatic HTTPS support.


⚠️ Fork Notice: This is a personal fork of RayBytes/ChatMock maintained for personal use only. For feature requests, bug reports, and general support, please visit the original repository and contact the original author.

πŸš€ What's New

Performance Improvements

  • ⚑ 3-5x Faster: Gunicorn with gevent workers (200-500+ RPS vs 50 RPS)
  • πŸ”„ High Concurrency: Handle 1000+ concurrent connections
  • πŸ“ˆ Production-Ready: Battle-tested WSGI server with automatic worker management

Web Dashboard

  • πŸ“Š Real-time Statistics: Monitor usage, rate limits, and analytics
  • βš™οΈ Configuration UI: Change settings via web interface
  • πŸ” Model Browser: Explore all available models and capabilities
  • Access: http://localhost:8000/webui

Traefik Integration

  • πŸ”’ Automatic HTTPS: Let's Encrypt SSL certificates
  • 🌐 Reverse Proxy: Production-ready deployment
  • βš–οΈ Load Balancing: Horizontal scaling support

πŸ“š Complete Documentation | 🎨 WebUI Guide | πŸš€ Production Setup | πŸ”’ Traefik Guide

What It Does

ChatMock runs a local server that creates an OpenAI/Ollama compatible API, and requests are then fulfilled using your authenticated ChatGPT login with the oauth client of Codex, OpenAI's coding CLI tool. This allows you to use GPT-5, GPT-5-Codex, and other models right through your OpenAI account, without requiring an api key. You are then able to use it in other chat apps or other coding tools.
This does require a paid ChatGPT account.

Quickstart

Mac Users

GUI Application

If you're on macOS, you can download the GUI app from the GitHub releases.

Note: Since ChatMock isn't signed with an Apple Developer ID, you may need to run the following command in your terminal to open the app:

xattr -dr com.apple.quarantine /Applications/ChatMock.app

More info here.

Command Line (Homebrew)

You can also install ChatMock as a command-line tool using Homebrew:

brew tap RayBytes/chatmock
brew install chatmock

Python

If you wish to just simply run this as a python flask server, you are also freely welcome too.

Clone or download this repository, then cd into the project directory. Then follow the instrunctions listed below.

  1. Sign in with your ChatGPT account and follow the prompts
python chatmock.py login

You can make sure this worked by running python chatmock.py info

  1. After the login completes successfully, you can just simply start the local server
python chatmock.py serve

Then, you can simply use the address and port as the baseURL as you require (http://127.0.0.1:8000 by default)

Reminder: When setting a baseURL in other applications, make you sure you include /v1/ at the end of the URL if you're using this as a OpenAI compatible endpoint (e.g http://127.0.0.1:8000/v1)

Docker (Recommended)

Quick Start:

# 1. Clone repository
git clone https://github.com/thebtf/ChatMock.git
cd ChatMock

# 2. Copy environment file
cp .env.example .env

# 3. Login with ChatGPT account
docker-compose --profile login up chatmock-login

# 4. Start server
docker-compose up -d

# 5. Access WebUI
# Open http://localhost:8000/webui in your browser

Production Deployment with Traefik (Automatic HTTPS):

# Configure domain in .env
echo "CHATMOCK_DOMAIN=chatmock.example.com" >> .env
echo "TRAEFIK_ACME_EMAIL=admin@example.com" >> .env

# Deploy with Traefik
docker-compose -f docker-compose.traefik.yml up -d

# Access at https://chatmock.example.com/webui

πŸ“– Complete Docker Documentation | πŸš€ Production Guide | πŸ”’ Traefik Setup

Examples

Python

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:8000/v1",
    api_key="key"  # ignored
)

resp = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "hello world"}]
)

print(resp.choices[0].message.content)

curl

curl http://127.0.0.1:8000/v1/chat/completions \
  -H "Authorization: Bearer key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5",
    "messages": [{"role":"user","content":"hello world"}]
  }'

Web Dashboard

ChatMock now includes a modern web dashboard for monitoring and configuration.

Access the WebUI:

Features:

  • πŸ“Š Real-time Statistics: View total requests, tokens, and usage patterns
  • πŸ“ˆ Rate Limit Monitoring: Visual progress bars for 5-hour and weekly limits
  • πŸ“‰ Analytics Charts: Requests by model and date
  • 🎨 Model Browser: Explore all available models with capabilities
  • βš™οΈ Configuration Management: Change settings via UI (runtime only)
  • πŸ” Authentication Status: View your ChatGPT account info and plan

API Endpoints (also available for custom integrations):

  • GET /api/status - Authentication and user info
  • GET /api/stats - Usage statistics and rate limits
  • GET /api/models - Available models with details
  • GET /api/config - Current configuration
  • POST /api/config - Update runtime settings

πŸ“– WebUI Documentation

Performance

Benchmarks (4 CPU cores, 8GB RAM)

Configuration Requests/Sec Avg Latency P95 Latency Memory
Flask Dev Server 50 100ms 200ms 150MB
Gunicorn (4 workers) 200 80ms 150ms 600MB
Gunicorn (8 workers) 350 60ms 120ms 1.2GB
Gunicorn (16 workers) 500 50ms 100ms 2.4GB

Production Configuration:

USE_GUNICORN=1              # Enable Gunicorn (default)
GUNICORN_WORKERS=8          # Number of worker processes

πŸ“Š Production Deployment Guide

What's supported

  • Tool/Function calling
  • Vision/Image understanding
  • Thinking summaries (through thinking tags)
  • Responses API (experimental)
  • Thinking effort
  • Web search (OpenAI native)
  • High-performance production server
  • Real-time monitoring dashboard
  • Automatic HTTPS with Traefik

Notes & Limits

  • Requires an active, paid ChatGPT account.
  • Some context length might be taken up by internal instructions (but they dont seem to degrade the model)
  • Use responsibly and at your own risk. This project is not affiliated with OpenAI, and is a educational exercise.

Supported models

  • gpt-5
  • gpt-5.1
  • gpt-5.2
  • gpt-5-codex
  • gpt-5.2-codex
  • gpt-5.1-codex
  • gpt-5.1-codex-max
  • gpt-5.1-codex-mini
  • codex-mini

Configuration

ChatMock can be configured via environment variables (Docker) or command-line parameters (Python).

Quick Configuration

Via Environment Variables (Docker)

Copy .env.example to .env and customize:

# Server
PORT=8000
USE_GUNICORN=1                    # Enable production server
GUNICORN_WORKERS=4                # Number of workers

# Reasoning
CHATGPT_LOCAL_REASONING_EFFORT=medium      # minimal|low|medium|high|xhigh
CHATGPT_LOCAL_REASONING_SUMMARY=auto       # auto|concise|detailed|none
CHATGPT_LOCAL_REASONING_COMPAT=think-tags  # legacy|o3|think-tags|current

# Features
CHATGPT_LOCAL_ENABLE_WEB_SEARCH=false      # Enable web search
CHATGPT_LOCAL_EXPOSE_REASONING_MODELS=false # Expose reasoning as models
VERBOSE=false                              # Enable verbose logging

# Traefik (Production)
CHATMOCK_DOMAIN=chatmock.example.com
TRAEFIK_ACME_EMAIL=admin@example.com

πŸ“– Complete .env.example Reference

Via Web Dashboard

Access http://localhost:8000/webui to change settings in real-time:

  • Reasoning effort and summary
  • Web search enablement
  • Verbose logging
  • Model exposure

Note: WebUI changes are runtime only and reset on restart. For persistent changes, update environment variables.

Via Command Line (Python)

python chatmock.py serve \
  --reasoning-effort high \
  --reasoning-summary detailed \
  --enable-web-search \
  --expose-reasoning-models

All parameters: python chatmock.py serve --help

Configuration Options

Server Configuration

  • PORT - Server port (default: 8000)
  • USE_GUNICORN - Enable Gunicorn for production (default: 1)
  • GUNICORN_WORKERS - Number of worker processes (default: CPU Γ— 2 + 1)
  • VERBOSE or CHATGPT_LOCAL_VERBOSE - Enable verbose request/response logging
  • DEBUG_LOG or CHATGPT_LOCAL_DEBUG - Enable compact debug logging
  • API_KEY or CHATGPT_LOCAL_API_KEY - Require API key for all /v1/* endpoints

API Key Authentication

Protect your ChatMock instance with API key authentication:

# Via environment variable
API_KEY=your-secret-key python chatmock.py serve

# Or via CLI argument
python chatmock.py serve --api-key your-secret-key

Clients must include the key in requests:

curl http://127.0.0.1:8000/v1/models \
  -H "Authorization: Bearer your-secret-key"

Note: Health endpoints (/, /health) and WebUI (/webui/*, /api/*) remain unprotected.

Thinking Controls

  • CHATGPT_LOCAL_REASONING_EFFORT (minimal|low|medium|high|xhigh)

    • Controls computational effort for reasoning
    • Higher effort = slower but potentially smarter responses
    • Default: medium
    • Note: gpt-5.1 family supports low, medium, and high while gpt-5.1-codex-max adds xhigh; neither offers a minimal variant
  • CHATGPT_LOCAL_REASONING_SUMMARY (auto|concise|detailed|none)

    • Controls how reasoning summaries are presented
    • none provides fastest responses
    • Default: auto
  • CHATGPT_LOCAL_REASONING_COMPAT (legacy|o3|think-tags|current)

    • Controls reasoning output format
    • think-tags: Returns in message text with thinking tags
    • legacy: Returns in separate reasoning field
    • Default: think-tags

Feature Toggles

  • CHATGPT_LOCAL_ENABLE_WEB_SEARCH - Enable web search tool by default
  • CHATGPT_LOCAL_EXPOSE_REASONING_MODELS - Expose reasoning levels as separate models (e.g., gpt-5-high, gpt-5-low)
  • CHATGPT_LOCAL_DEBUG_MODEL - Force specific model for all requests
  • CHATGPT_LOCAL_ENABLE_RESPONSES_API - Enable experimental Responses API at /v1/responses
  • CHATGPT_LOCAL_RESPONSES_NO_BASE_INSTRUCTIONS - Forward client instructions as-is (don't inject base prompt)

Web Search Usage

Enable web search globally:

CHATGPT_LOCAL_ENABLE_WEB_SEARCH=true

Or per-request via API:

{
  "model": "gpt-5",
  "messages": [{"role":"user","content":"Find current METAR rules"}],
  "responses_tools": [{"type": "web_search"}],
  "responses_tool_choice": "auto"
}

Supported tools:

  • {"type": "web_search"} - Standard web search
  • {"type": "web_search_preview"} - Preview mode

Tool choice: "auto" (let model decide) or "none" (disable)

Responses API (Experimental)

ChatMock supports the OpenAI Responses API at /v1/responses. Enable it with:

python chatmock.py serve --enable-responses-api

Or via environment variable:

CHATGPT_LOCAL_ENABLE_RESPONSES_API=true

Important: This proxies to ChatGPT's internal endpoint, which has limitations compared to the official OpenAI Platform API:

  • store=true is handled locally only (upstream requires store=false)
  • previous_response_id is simulated locally (not supported upstream)
  • ChatMock provides local polyfills for these features

Streaming example:

curl -sN http://127.0.0.1:8000/v1/responses \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-5",
    "stream": true,
    "input": [
      {"role":"user","content":[{"type":"input_text","text":"hello world"}]}
    ]
  }'

Non-streaming with storage:

curl -s http://127.0.0.1:8000/v1/responses \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-5",
    "stream": false,
    "store": true,
    "input": [{"role":"user","content":[{"type":"input_text","text":"Say hi"}]}]
  }'

Retrieve stored response:

curl -s http://127.0.0.1:8000/v1/responses/{response_id}

Supported features:

  • Streaming and non-streaming modes
  • Function tools and web_search
  • store (local storage for GET /v1/responses/{id})
  • previous_response_id (local threading simulation)
  • Input formats: Responses input, Chat-style messages, or prompt string

Production Settings

For optimal production performance:

# High performance
USE_GUNICORN=1
GUNICORN_WORKERS=8
CHATGPT_LOCAL_REASONING_EFFORT=medium
CHATGPT_LOCAL_REASONING_SUMMARY=auto

# Fastest responses
USE_GUNICORN=1
GUNICORN_WORKERS=16
CHATGPT_LOCAL_REASONING_EFFORT=minimal
CHATGPT_LOCAL_REASONING_SUMMARY=none

πŸ“Š Performance Tuning Guide

Notes

  • Fastest responses: Set reasoning_effort=minimal and reasoning_summary=none
  • Context size: Larger than regular ChatGPT interface
  • Thinking tags: Use reasoning_compat=legacy to avoid thinking tags in response text
  • Model variants: Enable expose_reasoning_models for easy model picker selection in chat apps

πŸ“š Complete Documentation

Deployment Options

ChatMock supports multiple deployment strategies for different use cases:

1. Local Development (Python)

Simple Python server for local testing:

python chatmock.py serve
# Access: http://localhost:8000

2. Docker (Recommended)

Production-ready deployment with Gunicorn:

docker-compose up -d
# Access: http://localhost:8000
# WebUI: http://localhost:8000/webui

Features:

  • ⚑ High-performance Gunicorn server
  • πŸ”„ Automatic worker management
  • πŸ“¦ Persistent data storage
  • πŸ”§ Easy configuration via .env

3. Docker with Traefik (Production)

Full production stack with automatic HTTPS:

docker-compose -f docker-compose.traefik.yml up -d
# Access: https://chatmock.example.com
# WebUI: https://chatmock.example.com/webui

Features:

  • πŸ”’ Automatic SSL/TLS certificates (Let's Encrypt)
  • 🌐 Reverse proxy with health monitoring
  • βš–οΈ Load balancing ready
  • πŸ“Š Traefik dashboard integration

πŸ”’ Traefik Setup Guide

4. Kubernetes

Scale horizontally with Kubernetes:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: chatmock
spec:
  replicas: 3
  # ... see docs/PRODUCTION.md for complete example

Features:

  • πŸ“ˆ Horizontal auto-scaling
  • πŸ₯ Health checks and liveness probes
  • πŸ”„ Rolling updates
  • πŸ“Š Resource limits and monitoring

πŸš€ Complete Production Guide

Comparison

Method Performance Complexity Best For
Python Low Simple Development
Docker High Easy Production (single server)
Traefik High Medium Production (HTTPS)
Kubernetes Very High Advanced Enterprise / High-scale

Documentation

Complete guides for all aspects of ChatMock:

Troubleshooting

WebUI not loading?

  1. Verify server is running: docker-compose ps
  2. Check logs: docker-compose logs chatmock
  3. Ensure port 8000 is accessible

Performance issues?

  1. Increase workers: GUNICORN_WORKERS=8
  2. Check resources: docker stats chatmock
  3. See Performance Guide

SSL certificate issues?

  1. Verify DNS points to server
  2. Check Traefik logs: docker logs traefik
  3. See Traefik Guide

For more help, check the documentation or open an issue.

Star History

Star History Chart

About

Access OpenAI models programmatically through your ChatGPT subscription.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages