{"id":51026601,"url":"https://github.com/gitstq/token-xiaohao","last_synced_at":"2026-06-21T20:02:06.880Z","repository":{"id":363293324,"uuid":"1262678282","full_name":"gitstq/token-xiaohao","owner":"gitstq","description":"用于真实消耗闲置 AI Token 的单页网页工具，支持 GPT / Claude / CC 兼容接口与模型 ID 获取","archived":false,"fork":false,"pushed_at":"2026-06-08T10:12:51.000Z","size":842,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-08T10:15:34.503Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://gitstq.github.io/token-xiaohao/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gitstq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-08T08:05:38.000Z","updated_at":"2026-06-08T10:12:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gitstq/token-xiaohao","commit_stats":null,"previous_names":["gitstq/token-xiaohao"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/gitstq/token-xiaohao","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Ftoken-xiaohao","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Ftoken-xiaohao/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Ftoken-xiaohao/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Ftoken-xiaohao/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gitstq","download_url":"https://codeload.github.com/gitstq/token-xiaohao/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Ftoken-xiaohao/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34623906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-21T20:02:05.972Z","updated_at":"2026-06-21T20:02:06.863Z","avatar_url":"https://github.com/gitstq.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Token 在线消耗器\n\n\u003e 一个专门用于**消耗闲置 AI Token** 的在线网页工具。很多账号、代理站或兼容接口里的 token 用不完时，可以用 Token 面板在可控预算内批量消耗，并实时观察吞吐、请求状态与消耗曲线。\n\n[![GitHub Pages](https://img.shields.io/badge/GitHub%20Pages-在线预览-5b62f4?style=for-the-badge\u0026logo=github)](https://gitstq.github.io/token-xiaohao/)\n[![Open Source](https://img.shields.io/badge/GitHub-开源地址-181717?style=for-the-badge\u0026logo=github)](https://github.com/gitstq/token-xiaohao)\n[![Docker](https://img.shields.io/badge/GHCR-token--xiaohao-2496ed?style=for-the-badge\u0026logo=docker)](https://github.com/gitstq/token-xiaohao/pkgs/container/token-xiaohao)\n[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/gitstq/token-xiaohao)\n[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/gitstq/token-xiaohao)\n\n![Token 面板桌面截图](assets/screenshot-desktop.png)\n\n## ✨ 功能亮点\n\n- 🔥 **核心用途明确**：就是为了在线消耗用不完的 token，适合额度清理、接口压测前的轻量验证和消耗曲线观察。\n- 🎛️ **一个页面完成全部操作**：URL、KEY、模型、线程数、预算、轮次、输出上限和主题切换都在同一页面内完成。\n- 🚀 **兼容 OpenAI 与 Anthropic**：内置 OpenAI Chat Completions 风格请求体，也支持 Anthropic Messages 风格接口。\n- 🧩 **一键获取模型 ID**：填写 URL 和 KEY 后可点击「获取模型」，从兼容接口拉取模型列表并选择模型 ID。\n- 📈 **实时数据监控**：总 Token、平均速度、请求状态和 ECharts 实时图表同步刷新。\n- 🛡️ **预算保护**：默认启用预算保护，达到 Token 预算后自动停止。\n- 🌙 **深浅色模式**：支持右上角手动切换，并自动适配系统主题。\n- 🖥️ **保持后台运行**：支持浏览器 Screen Wake Lock，运行时尽量避免设备休眠。\n- 🔁 **本地代理回退**：接口未开放浏览器 CORS 时，可通过本地代理使用当前电脑网络环境转发请求。\n- ✅ **真实消耗**：不做模拟请求，启动前会校验 URL、KEY 和模型 ID，确认齐全后才会向接口发起真实请求。\n- 🔐 **密钥不落盘**：KEY 只存在当前浏览器页面状态中，不会写入仓库或本地文件。\n- 🎨 **NetworkPanel 风格 UI**：对齐 `ljxi/NetworkPanel` 的面板布局、开关、滑条、ECharts 图表和中央启动按钮风格。\n\n## 🖼️ 移动端效果\n\n![Token 面板移动端截图](assets/screenshot-mobile.png)\n\n## 🌐 在线使用\n\n打开在线页面：\n\n```text\nhttps://gitstq.github.io/token-xiaohao/\n```\n\n使用步骤：\n\n1. 选择接口类型：`OpenAI`、`Anthropic` 或 `自定义`。\n2. 填写接口地址和 KEY。\n3. 点击「获取模型」，从「模型 ID」下拉框选择模型。\n4. 设置线程数、预算保护、Token 预算和高级参数。\n5. 点击中央播放按钮开始消耗，再次点击可停止。\n6. 点击右下角图表按钮可展开 Token 图表；图表展开后页面区域支持滚动查看。\n\n\u003e 页面只做真实请求，会调用你填写的接口并产生用量。若供应商拦截浏览器跨域请求，请填写支持 CORS 的兼容接口地址或自建转发 URL。最终计费以供应商后台为准。\n\n## 💻 本地启动教程\n\n### 1. 准备环境\n\n本项目是静态页面，本地预览只需要 Python 或任意静态文件服务器。\n如果要使用本地代理，需要安装 Node.js 18 或更高版本。\n\n检查环境：\n\n```powershell\npython --version\nnode --version\n```\n\n### 2. 启动网页\n\n```powershell\ngit clone https://github.com/gitstq/token-xiaohao.git\ncd token-xiaohao\npython -m http.server 5173\n```\n\n浏览器访问：\n\n```text\nhttp://127.0.0.1:5173/index.html\n```\n\n### 3. 启动本地代理\n\n如果你的接口不支持浏览器 CORS，点击「获取模型」可能会失败。\n可以另开一个 PowerShell 终端，在项目目录运行：\n\n```powershell\nnode local-proxy.js\n```\n\n代理默认监听：\n\n```text\nhttp://127.0.0.1:8787\n```\n\n页面里仍然填写原始接口地址，例如：\n\n```text\nhttps://你的接口域名\n```\n\n页面会先尝试直连；如果浏览器 CORS 拦截失败，会自动走本地代理，由本机网络环境转发请求。\n\n### 4. Docker 运行\n\nDocker 方式会启动一个 Node 服务，同时提供网页和同源 `/proxy` 转发接口。相比普通静态页面，Docker 部署可以直接处理 CORS 转发，不依赖访问者电脑上的本地代理。\n\n使用 GHCR 镜像：\n\n```powershell\ndocker run -d --name token-xiaohao -p 8080:8080 ghcr.io/gitstq/token-xiaohao:latest\n```\n\n浏览器访问：\n\n```text\nhttp://127.0.0.1:8080\n```\n\n使用 docker compose：\n\n```powershell\ndocker compose up -d\n```\n\n本地构建镜像：\n\n```powershell\ndocker build -t token-xiaohao:local .\ndocker run --rm -p 8080:8080 token-xiaohao:local\n```\n\n如果你想发布到 Docker Hub，可以在本地重新打 tag 后推送：\n\n```powershell\ndocker tag ghcr.io/gitstq/token-xiaohao:latest gitstq/token-xiaohao:latest\ndocker push gitstq/token-xiaohao:latest\n```\n\n健康检查：\n\n```powershell\nInvoke-WebRequest http://127.0.0.1:8080/healthz\n```\n\n### 5. 常见本地启动问题\n\n- `请先启动本地代理：node local-proxy.js，或使用 Docker 运行`：说明接口被 CORS 拦截，并且当前页面没有可用代理。\n- `端口 5173 被占用`：换一个端口，例如 `python -m http.server 5174`。\n- `端口 8787 被占用`：用 `PORT` 指定代理端口，例如 `$env:PORT=8788; node local-proxy.js`，同时页面代码里的代理地址也需要对应调整。\n- `端口 8080 被占用`：Docker 运行时换端口，例如 `docker run -d -p 8081:8080 ghcr.io/gitstq/token-xiaohao:latest`。\n- 获取模型成功但启动失败：确认已选择模型 ID，并检查接口类型是否与请求体兼容。\n\n## 🔌 接口兼容说明\n\n| 类型 | 默认接口 | 鉴权方式 | 请求格式 |\n| --- | --- | --- | --- |\n| OpenAI | `https://api.openai.com/v1` | `Authorization: Bearer \u003cKEY\u003e` | Chat Completions |\n| Anthropic | `https://api.anthropic.com/v1` | `x-api-key: \u003cKEY\u003e` | Messages |\n| 自定义 | 任意兼容 `/v1` 地址 | `Authorization: Bearer \u003cKEY\u003e` | OpenAI 兼容 |\n\n模型获取会根据当前 URL 自动推导模型接口，例如 `/v1/chat/completions` 会推导为 `/v1/models`。不同代理站的模型列表格式可能略有差异，页面会尽量兼容 `data`、`models` 或数组格式。\n\n## 🔁 CORS 与代理说明\n\n浏览器请求带有 `Authorization`、`x-api-key` 等请求头时，会触发 CORS 预检。\n如果接口服务端没有正确处理 `OPTIONS` 请求，页面会看到 `Failed to fetch` 或「接口未开放浏览器 CORS」。\n\n解决方式：\n\n- 本地使用：启动 `node local-proxy.js`。\n- Docker 使用：容器内置同源 `/proxy` 转发，不需要额外本地代理。\n- 线上使用：部署一个公网代理服务，例如 Cloudflare Worker、Vercel Functions 或自己的服务器反代。\n- 服务端修复：让目标接口正确返回 CORS 响应头。\n\n需要允许的请求头通常包括：\n\n```text\nauthorization\ncontent-type\nx-api-key\nanthropic-version\n```\n\n`OPTIONS` 预检请求应直接返回 `200` 或 `204`，不要要求鉴权。\n\n## ☁️ 线上部署\n\n### GitHub Pages\n\nFork 本仓库后，在 GitHub Pages 中选择 `main` 分支发布即可。\n当前仓库的线上地址：\n\n```text\nhttps://gitstq.github.io/token-xiaohao/\n```\n\n### Vercel / Netlify\n\n可以直接点击 README 顶部的一键部署按钮，也可以手动导入仓库。\n这是纯静态项目，不需要构建命令，发布目录为仓库根目录。\n\n### Docker / 服务器\n\n服务器上推荐使用 Docker 镜像部署：\n\n```bash\ndocker run -d --name token-xiaohao -p 8080:8080 --restart unless-stopped ghcr.io/gitstq/token-xiaohao:latest\n```\n\n如果需要放到域名后面，可以用 Nginx、Caddy 或反向代理平台转发到容器的 `8080` 端口。\n\n### Docker 镜像发布\n\n本仓库包含 `.github/workflows/docker.yml`，推送到 `main` 后会自动构建并发布多架构镜像：\n\n```text\nghcr.io/gitstq/token-xiaohao:latest\nghcr.io/gitstq/token-xiaohao:sha-\u003ccommit\u003e\n```\n\n如果你想同步发布到 Docker Hub，可以基于当前工作流新增 Docker Hub 登录和第二个镜像标签。\n\n### 线上代理\n\n线上页面不能使用访问者电脑上的 `127.0.0.1:8787` 作为公共代理。\n如果使用 GitHub Pages、Vercel、Netlify 这类纯静态部署，要让所有访问者都能稳定跨域请求，需要部署公网代理，并将页面中的代理地址改成你的公网代理地址。\n\n如果使用本项目 Docker 镜像部署，页面会优先尝试同源 `/proxy`，一般不需要额外配置公网代理。\n\n安全建议：\n\n- 不要把 KEY 写进代理代码。\n- 不要记录 `Authorization`、`x-api-key` 等敏感请求头。\n- 建议限制允许访问的前端域名。\n- 真实消耗会产生费用，最终以接口供应商后台为准。\n\n## 🗂️ 项目结构\n\n```text\ntoken-xiaohao/\n├─ Dockerfile          # Docker 镜像构建文件\n├─ docker-compose.yml  # Docker Compose 示例\n├─ index.html          # 主页面，所有 UI 与请求逻辑\n├─ local-proxy.js      # 本地 CORS 转发代理\n├─ server.js           # Docker 服务端，提供静态页面和同源代理\n├─ README.md           # 项目文档\n└─ assets/             # 截图资源\n```\n\n## 🧭 设计取向\n\nToken 在线消耗器把复杂参数收纳在轻量设置区，把高频操作集中在一个主按钮上，把实时状态压缩为三张指标卡和一条 ECharts 曲线。它不是复杂后台，而是一个即开即用、干净利落的 Token 消耗面板。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitstq%2Ftoken-xiaohao","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitstq%2Ftoken-xiaohao","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitstq%2Ftoken-xiaohao/lists"}