opencode zen free 模型,三方 api 调用报错问题初步解决方案

saqjs-ld 2026-09-17 10:32 1

今天早上准备继续快乐白嫖的时候突然报错:


HTTP 403
{"type":"error","error":{"type":"FreeTierError","message":"Error from provider (Console): OpenCode's free tier can only be used from within OpenCode"}}

抓包简单折腾下发现:现在必须完整的 header ,其中 x-opencode-request, x-opencode-session 是 opencode cli 本地算出来的,乱填是不可以的


headers:
User-Agent: opencode/1.18.31 ai-sdk/provider-utils/4.0.40 runtime/bun/1.3.14
x-opencode-client: cli
x-opencode-project: global
x-opencode-request: msg_0ada1b968001cxm5rgh28JxlDH
x-opencode-session: ses_f525e4699ffe5hmrr6t1FiPVca

介于有部分佬友生成的 x-opencode-request, x-opencode-session 有问题,这里给出 opencode 源码生成机制的 js 的脚本,可以 nodejs 或者复制到浏览器控制台执行


function gen(desc) {
let last = 0, ctr = 0;
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const ts = Date.now();
ctr = (ts !== last) ? 1 : ctr + 1; last = ts;
let v = BigInt(ts) * 0x1000n + BigInt(ctr);
if (desc) v = ~v;
let time = "";
for (let i = 0; i < 6; i++) time += Number((v >> BigInt(40 - 8 * i)) & 0xffn).toString(16).padStart(2, "0");
const rnd = [...crypto.getRandomValues(new Uint8Array(14))].map(b => chars[b % 62]).join("");
return time + rnd;
}
function getKey() {
const ses = "ses_" + gen(true), msg = "msg_" + gen(false);
console.log("ses:", ses);
console.log("msg:", msg);
}
getKey()
最新回复 (19)
  • chensanse 09-17 10:37
    1

    蹲一手大佬的反馈。呜呜,全靠反代zen生活了

  • ShenQiT 09-17 10:38
    2

    WC佬 我去试试 等你这一手 很久了

  • Xiwis Homed 09-17 10:45
    3

    测试了一下不行



  • ShenQiT 09-17 10:48
    4

    不行嘛 我还没开始测试呢

  • Xuyufenfei 09-17 10:50
    5

    可以了,这个值不能乱填,格式要像,之前我都是乱填的

  • saqjs-ld 楼主 09-17 10:50
    6

    现在 oc 检测还挺严格,UA 也测了,而有些客户端 UA 不会遵守,比如 CPA 的 codex 配置不会遵守自己填的

  • _Rain 09-17 10:52
    7

    按照你这个改完确实可以了

  • ShenQiT 09-17 10:52
    8

    用啥格式啊 佬 分享一下

  • Xuyufenfei 09-17 10:54
    9

    就是他写的session类似uuid的东西改几个字母,以前都是乱填的,现在不行了

  • saqjs-ld 楼主 09-17 10:55
    10

    意思是长度一样,里面的东西随意?

  • Xuyufenfei 09-17 10:55
    11

    对的,现在开始校验格式了

  • kt8tqbhvk 09-17 10:55
    12

    我直接用opencode客户端,方便好用,没这些麻烦,功能实际上和codex很接近了。

  • ShenQiT 09-17 10:55
    13
     "x-opencode-session": "ses_5d6fe2b289114dcdbccc8a0646",

    意思是要这种固定格式了是吧?

  • Selah 09-17 10:56
    14

    佬免费模型不是量化过的吗

  • Xuyufenfei 09-17 10:56
    15

    对的,session和request的值改一下,其他不动就行

  • ShenQiT 09-17 10:58
    16

    明白了 谢谢佬。

  • starpipi 09-17 11:03
    17

    应该是计算出来的,改了就不行了。。。 不改可以通。。。去看看opencode源码去-。-



    看起来是userId和sessionId

  • 布鲁斯-侯恩 09-17 11:05
    18

    感谢实测可用


    {
    "User-Agent": "opencode/1.18.31 ai-sdk/provider-utils/4.0.40 runtime/bun/1.3.14",
    "x-opencode-client": "cli",
    "x-opencode-project": "global",
    "x-opencode-request": "msg_7c4d9a1e00295K83LlhFrHv9Wb",
    "x-opencode-session": "ses_b8120d3e4ffe8rCHj92Xb61kY6"
    }
  • phonics 09-17 11:05
    19

    同样问题。我先去试一下、感谢

* 帖子来源Linux.do
返回