chatgpt2api README

The project's README from github.com/basketikun/chatgpt2api. As one markdown file: README.md.

ChatGPT2API

ChatGPT2API 主要是对 ChatGPT 官网相关能力进行逆向整理与封装,提供面向 ChatGPT 图片生成、图片编辑、多图组图编辑场景的 OpenAI 兼容图片 API / 代理,并集成在线画图、号池管理、多种账号导入方式与 Docker 自托管部署能力。

[!WARNING] 免责声明:

本项目涉及对 ChatGPT 官网文本生成、图片生成与图片编辑等相关接口的逆向研究,仅供个人学习、技术研究与非商业性技术交流使用。

  • 严禁将本项目用于任何商业用途、盈利性使用、批量操作、自动化滥用或规模化调用。
  • 严禁将本项目用于破坏市场秩序、恶意竞争、套利倒卖、二次售卖相关服务,以及任何违反 OpenAI 服务条款或当地法律法规的行为。
  • 严禁将本项目用于生成、传播或协助生成违法、暴力、色情、未成年人相关内容,或用于诈骗、欺诈、骚扰等非法或不当用途。
  • 使用者应自行承担全部风险,包括但不限于账号被限制、临时封禁或永久封禁以及因违规使用等所导致的法律责任。
  • 使用本项目即视为你已充分理解并同意本免责声明全部内容;如因滥用、违规或违法使用造成任何后果,均由使用者自行承担。
  • 本项目基于对 ChatGPT 官网相关能力的逆向研究实现,存在账号受限、临时封禁或永久封禁的风险。请勿使用你自己的重要账号、常用账号或高价值账号进行测试。

赞助商

Atlas Cloud Atlas Cloud is a full-modal AI inference platform that gives developers a single AI API to access video generation, image generation, and LLM APIs. Instead of managing multiple vendor integrations, you connect once and get unified access to 300+ curated models across all modalities. Check out Atlas Cloud's new coding plan promotion for more budget-friendly API access.

快速开始

Docker 运行

git clone [email protected]:basketikun/chatgpt2api.git
cd chatgpt2api
docker compose up -d

启动前请先在 config.json 中设置 auth-key,也可以在 docker-compose.yml 中通过 CHATGPT2API_AUTH_KEY 覆盖。

WARP / FlareSolverr 稳定代理部署

如果图片链路经常遇到 Cloudflare 拦截,可以启用附带的 WARP + Privoxy + FlareSolverr 方案:

cp .env.example .env
docker compose -f docker-compose.warp.yml up -d --build

该 compose 会启动:

默认只让上游 OpenAI / ChatGPT 请求走稳定代理,账号邮箱、CPA 等辅助链路不会被强制接管。账号自身配置的代理优先级最高,其次是稳定代理运行时,再其次是显式代理和旧版全局代理。

可在 .env 中调整端口和代理运行时参数,也可在后台设置页的「稳定代理运行时」面板手动保存、测试代理和测试 clearance。

本地开发

启动后端:

git clone [email protected]:basketikun/chatgpt2api.git
cd chatgpt2api
uv sync
uv run main.py

启动前端:

cd chatgpt2api/web
bun install
bun run dev

后续更新新版本:

docker pull ghcr.io/basketikun/chatgpt2api:latest
docker-compose down
docker-compose up -d

存储后端配置

支持通过环境变量 STORAGE_BACKEND 切换存储方式:

示例:使用 PostgreSQL

environment:
  - STORAGE_BACKEND=postgres
  - DATABASE_URL=postgresql://user:password@host:5432/dbname

功能

API 兼容能力

在线画图功能

号池管理功能

实验性 / 规划中

效果展示

image image edit
chery studio account pool
new api

API

所有 AI 接口都需要请求头:

Authorization: Bearer <auth-key>
GET /v1/models

返回当前暴露的图片模型列表。

curl http://localhost:8000/v1/models \
  -H "Authorization: Bearer <auth-key>"
说明
字段 说明
返回模型 gpt-image-2、codex-gpt-image-2、auto、gpt-5、gpt-5-1、gpt-5-2、gpt-5-3、gpt-5-3-mini、gpt-5-mini
接入场景 可接入 Cherry Studio、New API 等上游或客户端

POST /v1/images/generations

OpenAI 兼容图片生成接口,用于文生图。

curl http://localhost:8000/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <auth-key>" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "一只漂浮在太空里的猫",
    "n": 1,
    "response_format": "b64_json"
  }'
字段说明
字段 说明
model 图片模型,当前可用值以 /v1/models 返回结果为准,推荐使用 gpt-image-2
prompt 图片生成提示词
n 生成数量,当前后端限制为 1-4
response_format 当前请求模型中包含该字段,默认值为 b64_json

POST /v1/images/edits

OpenAI 兼容图片编辑接口,可上传图片文件,也可按官方 JSON 格式传入图片链接并生成编辑结果。

curl http://localhost:8000/v1/images/edits \
  -H "Authorization: Bearer <auth-key>" \
  -F "model=gpt-image-2" \
  -F "prompt=把这张图改成赛博朋克夜景风格" \
  -F "n=1" \
  -F "image=@./input.png"

也可以直接传图片 URL:

curl http://localhost:8000/v1/images/edits \
  -H "Authorization: Bearer <auth-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "把这张图改成赛博朋克夜景风格",
    "images": [
      {"image_url": "https://example.com/input.png"}
    ]
  }'
字段说明
字段 说明
model 图片模型, gpt-image-2
prompt 图片编辑提示词
n 生成数量,当前后端限制为 1-4
image 需要编辑的图片文件,使用 multipart/form-data 上传
images JSON 图片引用数组,支持 {"image_url": "https://..."}
image_url 表单模式下也可直接传图片链接,支持重复字段传多张图

POST /v1/chat/completions

面向文本、网页搜索与图片场景的 Chat Completions 兼容接口,不是完整通用聊天代理。

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <auth-key>" \
  -d '{
    "model": "gpt-image-2",
    "messages": [
      {
        "role": "user",
        "content": "生成一张雨夜东京街头的赛博朋克猫"
      }
    ],
    "n": 1
  }'
字段说明
字段 说明
model 文本、搜索或图片模型;搜索模型会触发网页搜索兼容逻辑
messages 消息数组,支持文本、搜索和图片请求内容
n 图片生成数量,按当前实现解析为图片数量
stream 文本、搜索和图片场景均支持,仍在测试
tools 文本场景支持 web_search / web_search_preview / web_search_preview_2025_03_11
web_search_options 传入时会触发网页搜索兼容逻辑

POST /v1/responses

面向文本、网页搜索和图片生成工具调用的 Responses API 兼容接口,不是完整通用 Responses API 代理。

curl http://localhost:8000/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <auth-key>" \
  -d '{
    "model": "gpt-5",
    "input": "生成一张未来感城市天际线图片",
    "tools": [
      {
        "type": "image_generation"
      }
    ]
  }'
字段说明
字段 说明
model 响应中会回显该模型字段,搜索和图片生成会走对应兼容逻辑
input 输入内容;搜索使用最后一条用户文本,图片生成需能解析出提示词
tools 支持 image_generation、web_search、web_search_preview、web_search_preview_2025_03_11
stream 已实现,但仍在测试

社区支持

学 AI , 上 L 站:LinuxDO

Contributors

感谢所有为本项目做出贡献的开发者:

Contributors

Star History

Star History Chart

chatgpt2api (basketikun/chatgpt2api)

Searching Database…

What is this?ChatGPT2API reverse-engineers ChatGPT's web endpoints to give you a self-hosted, OpenAI-compatible API for image generation, image editing and text completions, plus a dashboard for managing a pool of ChatGPT accounts.
Is this a library or a standalone server I run myself?It is a standalone self-hosted server with a web admin panel and OpenAI-style HTTP endpoints, not a library you import into code — you deploy it (typically with Docker) and point OpenAI-compatible clients at it.
How do I get it running?Set your auth-key in config.json (or override it with CHATGPT2APIAUTHKEY in docker-compose.yml), then start it; this brings up a web panel, the API endpoint and a ./data storage directory.
Do I need actual ChatGPT accounts to use it?Yes — it does not work on its own, you feed it ChatGPT accounts via a local CPA JSON file, a remote CPA server, a sub2api server, or raw access tokens, and it pools and rotates them to serve requests.
Is it safe to use my main ChatGPT account with this?No — the project is explicitly an unofficial reverse-engineering effort, so accounts plugged into it risk being rate-limited, temporarily restricted, or permanently banned; the README also bans commercial or large-scale automated use.
Where do I deploy this?It's built to run in Docker (a docker-publish CI workflow builds images), with an optional extra Compose stack bundling WARP, Privoxy and FlareSolverr to keep Cloudflare from blocking the image generation pipeline.
What image models are exposed through the API?The /v1/models endpoint lists gpt-image-2, codex-gpt-image-2, auto, and several gpt-5 variants (gpt-5, gpt-5-1, gpt-5-2, gpt-5-3, gpt-5-3-mini, gpt-5-mini) usable for text-to-image generation, editing and chat.
Can it produce editable design files, not just images?Yes — besides raw image output it can generate editable PowerPoint (PPT) and Photoshop (PSD) files from the image generation pipeline.
How does the account pool stay healthy over time?It auto-refreshes account quotas and recovery windows, drops tokens that fail, re-checks rate-limited accounts on a schedule, and can re-login with saved passwords to revive broken accounts.
What storage backends can I use for accounts and config?You switch via the STORAGE_BACKEND env var between local JSON files (default), SQLite, an external PostgreSQL database, or a private Git repository.
Creator
basketikun
Size
5.2 MB
Stars
6.7K
Age
6mo
Commits · 90 Days