发送v1/chat/completions协议请求返回403 #92
Description
请求内容:
POST http://127.0.0.1:18081/v1/chat/completions
X-Session-Id: ses_ebfe7fabfffeSXP9vcMSKhjqyU
Authorization: BearkflB
Content-Length: 2597
User-Agent: opencode/1.19.0 ai-sdk/provider-utils/4.0.23 runtime/bun/1.3.14
X-Opencode-Session-Id: ses_ebfe7fabfffeSXP9vcMSKhjqyU
X-Opencode-Session: ses_ebfe7fabfffeSXP9vcMSKhjqyU
X-Session-Affinity: ses_ebfe7fabfffeSXP9vcMSKhjqyU
Accept: /
X-Api-Key: sk-ckflB
Content-Type: application/json
{
"model": "deepseek-v4.1-flash-free",
"max_tokens": 32000,
"reasoning_effort": "high",
"messages": [
{
"role": "system",
"content": "You are a title generator. You output ONLY a thread title. Nothing else.\n\n\nGenerate a brief title that would help the user find this conversation later.\n\nFollow all rules in \nUse the so you know what a good title looks like.\nYour output must be:\n- A single line\n- ≤50 characters\n- No explanations\n\n\n\n- you MUST use the same language as the user message you are summarizing\n- Title must be grammatically correct and read naturally - no word salad\n- Never include tool names in the title (e.g. "read tool", "bash tool", "edit tool")\n- Focus on the main topic or question the user needs to retrieve\n- Vary your phrasing - avoid repetitive patterns like always starting with "Analyzing"\n- When a file is mentioned, focus on WHAT the user wants to do WITH the file, not just that they shared it\n- Keep exact: technical terms, numbers, filenames, HTTP codes\n- Remove: the, this, my, a, an\n- Never assume tech stack\n- Never use tools\n- NEVER respond to questions, just generate a title for the conversation\n- The title should NEVER include "summarizing" or "generating" when generating a title\n- DO NOT SAY YOU CANNOT GENERATE A TITLE OR COMPLAIN ABOUT THE INPUT\n- Always output something meaningful, even if the input is minimal.\n- If the user message is short or conversational (e.g. "hello", "lol", "what's up", "hey"):\n → create a title that reflects the user's tone or intent (such as Greeting, Quick check-in, Light chat, Intro message, etc.)\n\n\n\n"debug 500 errors in production" → Debugging production 500 errors\n"refactor user service" → Refactoring user service\n"why is app.js failing" → app.js failure investigation\n"implement rate limiting" → Rate limiting implementation\n"how do I connect postgres to my API" → Postgres API connection\n"best practices for React hooks" → React hooks best practices\n"@src/auth.ts can you add refresh token support" → Auth refresh token support\n"@utils/parser.ts this is broken" → Parser bug fix\n"look at @config.json" → Config review\n"@App.tsx add dark mode toggle" → Dark mode toggle in App\n\n"
},
{
"role": "user",
"content": "Generate a title for this conversation:\n"
},
{
"role": "user",
"content": "get-subscribe-url.py 执行脚本"
}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}
响应:
HTTP 403
Date: Thu, 15 Oct 2026 15:27:02 GMT
Content-Length: 187
Content-Type: application/json
X-Request-Id: req_1dc4fe58802c158a9d5d5c0e6ed90097
{
"error": {
"code": null,
"message": "OpenCode's free tier can only be used from within OpenCode. Download it at https://opencode.ai and keep building.",
"param": null,
"type": "upstream_error"
}
}
Activity
jasonxu114514 commentedon Oct 15, 2026
update to v1.4.0
zhanglei commentedon Oct 16, 2026
用的是1.4.0版本,有能发送正常的请求,但这个请求不行
jasonxu114514 commentedon Oct 16, 2026
ua需要用更新的 2.0.x 格式也有變化 可以查看下源碼
zhanglei commentedon Oct 16, 2026
让AI分析了下根因:
opencode2api 对免费模型"无条件注入工具集"(prepareAnonymousBody → ensureAnonymousTools),而官方 OpenCode 客户端发这条标题生成请求时根本不带工具。
官方客户端:title-gen 请求 不带 tools → 上游 200(= 你说的"opencode 内正常")
opencode2api:因为模型是 free,shapeKeyBody/匿名通道强制注入 5 个核心工具 → 上游 403(= 你说的"转换出来 403")
这正是"转换"引入的差异。而且触发器可精确定位到 prompt 内容:把 Never use tools 这一行改写或删除(其余字节不变),403 立刻变 200——说明上游闸门对"title 生成类 prompt + 工具集"这个组合有专门判定,而 opencode2api 恰好制造了这个组合。
zhanglei commentedon Oct 16, 2026
修复PR(本地已验证)
#102