Sign inSign up

xyhelper/chatgpt2api

By xyhelper

•Updated 9 months ago

Image
6

3.7K

xyhelper/chatgpt2api repository overview

⁠ChatGPT2API

基于 GoFrame 的 ChatGPT API 代理服务,支持后台管理、账号轮循、Codex 透传等能力,可直接兼容 OpenAI 官方 API。

⁠✨ 功能亮点

  • 后台管理:可视化管理账号、授权码与 Codex 队列
  • OpenAI 兼容:直接替换 API Base 即可调用聊天、模型列表等接口
  • 账号轮循:同一授权码可绑定多账号,自动均衡负载
  • Codex 透传:为标记为付费的账号维护独立队列,自动剔除失效 token
  • 流式压缩:请求采用压缩流,减少带宽占用
  • 图片增强:支持生图、进度回调、base64 与 URL 图片上传
  • 本地缓存:图片结果可缓存至挂载目录,通过外网地址访问

⁠🚀 快速开始

⁠拉取镜像
docker pull xyhelper/chatgpt2api:latest
⁠使用 docker run
docker run -d \
  --name chatgpt2api \
  -p 8080:8080 \
  -e PORT=8080 \
  -e TZ=Asia/Shanghai \
  -e CHATPROXY=https://your-gateway.domain.com \
  -e AUTHORIZATION=your-auth-code \
  -e FILE_SERVER_PREFIX=https://your-domain.com \
  -v /path/to/data:/app/data \
  xyhelper/chatgpt2api:latest
⁠使用 Docker Compose
services:
  chatgpt2api:
    image: xyhelper/chatgpt2api:latest
    ports:
      - "8080:8080"
    environment:
      PORT: 8080
      TZ: Asia/Shanghai
      CHATPROXY: https://your-gateway.domain.com
      AUTHORIZATION: your-auth-code
      FILE_SERVER_PREFIX: https://your-domain.com
      DELETE_HISTORY: "false"
    volumes:
      - ./data:/app/data
    restart: always

启动后访问 http://服务器IP:8080/admin 进入管理后台,默认账号为 admin,密码即 AUTHORIZATION。

⁠🔧 环境变量

变量名必填默认值说明
PORT否8080服务监听端口
TZ否Asia/Shanghai容器时区
CHATPROXY是-xyhelper 网关地址,用于透传官方请求
AUTHORIZATION是-管理后台登录 & API 调用的授权码
FILE_SERVER_PREFIX否-可被外网访问的服务地址,配置后会缓存生成图片并返回完整链接
DELETE_HISTORY否false是否在会话结束后删除历史记录

⁠📡 API 兼容性

设置请求头 Authorization: Bearer your-auth-code 后即可直接调用下列 OpenAI 兼容接口:

  • /v1/chat/completions:标准聊天补全
  • /v1/models:模型列表
  • /v1/response:Codex 透传(自动挑选付费账号 token)
⁠聊天补全示例
curl https://your-domain.com/v1/chat/completions \
  -H 'Authorization: Bearer your-auth-code' \
  -H 'Content-Type: application/json' \
  -d '{
        "model": "gpt-5",
        "messages": [
          {"role": "user", "content": "你好!"}
        ],
        "stream": true
      }'
⁠Codex 透传示例
curl https://your-domain.com/v1/responses \
  -H 'Authorization: Bearer your-auth-code' \
  -H 'Content-Type: application/json' \
  -d '{
        "model": "gpt-5-codex",
        "input": "请用Go语言编写一个快速排序函数,并解释关键步骤。",
        "stream": true
      }'

⁠🩺 健康检查

  • 访问 http://<host>:<port>/healthz
  • 返回示例:
    {
      "status": "ok"
    }
    

⁠📂 数据持久化

  • /app/data:默认数据目录;挂载后可持久化账号信息与文件缓存
  • 图片生成功能在配置 FILE_SERVER_PREFIX 时,会在 data/files 下缓存生成的图片

⁠🧪 运行与日志

  • 日志默认输出到容器标准输出,可使用 docker logs chatgpt2api 查看
  • 推荐结合反向代理或监控系统对 /healthz 持续探活

⁠🤝 支持

升级镜像后建议重启容器:

docker pull xyhelper/chatgpt2api:latest
docker stop chatgpt2api && docker rm chatgpt2api
# 重新执行 docker run / docker compose

Tag summary

Content type

Image

Digest

sha256:d60eeb013…

Size

29.7 MB

Last updated

9 months ago

docker pull xyhelper/chatgpt2api