背景
Codebuff 是一个 AI 编程助手,旗下免费层 Freebuff 提供了一批可免费调用的模型(Gemini、DeepSeek、GLM、Kimi 等)。官方只提供 CLI 客户端,没有公开 API。
目标:把 Freebuff 的免费模型逆向成标准的 /v1/chat/completions(OpenAI 协议)和 /v1/messages(Claude 协议),让任意兼容客户端(LobeChat、NextChat、Claude Code、Codex 等)直接可用拾光网。
一、协议全貌:四个关键端点
通过抓包 CLI 的真实流量,梳理出 Freebuff 后端的完整调用链。所有请求都带 Authorization: Bearer <authToken>。
| 1 | POST /api/v1/freebuff/session | 创建/保活免费会话,返回 instanceId 和 expiresAt |
| 2 | POST /api/v1/agent-runs (action=START) | 启动一个 agent run,返回 runId |
| 3 | POST /api/v1/chat/completions | 真正的聊天请求,载荷里注入 codebuff_metadata |
| 4 | POST /api/v1/agent-runs (action=FINISH) | 结束 run,上报 steps/credits |
1. 会话创建
POST /api/v1/freebuff/session Authorization: Bearer <token> x-freebuff-model: deepseek/deepseek-v4-flash Content-Type: application/json {}
响应:
{ \”status\”: \”active\”, \”instanceId\”: \”xxxx\”, \”model\”: \”…\”, \”expiresAt\”: \”2026-07-27T…\”, \”rateLimit\”: {…} }
注意是 POST 带 {} 空体 +&nbs





