Skip to content

Commit 6a79c42

Browse files
committed
fix(providers): add official opencode client User-Agent to opencode-free
OpenCode's Zen gateway requires the official client User-Agent prefix ('opencode') alongside the client marker, answering 429/403 to generic fetch User-Agents. Keep the desktop tier identity and add the canonical User-Agent header.
1 parent 70e8bab commit 6a79c42

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/providers/registry.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,7 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
24352435
note: "No key needed — public desktop tier. OpenCode currently advertises about 200 Big Pickle/free-model requests per 5 hours. The same Zen gateway can also short-window rate-limit free models at roughly 15-20 requests/minute, and may return generic 429s without Retry-After (opencodex synthesizes backoff only when that header is omitted). Free models are discovered live from Zen. Data use: per OpenCode's Zen docs (https://opencode.ai/docs/zen/), prompts sent to free models may be retained and used for training/improvement — do not send confidential material through this provider.",
24362436
dashboardUrl: "https://opencode.ai",
24372437
staticHeaders: {
2438+
"User-Agent": "opencode",
24382439
"x-opencode-client": "desktop",
24392440
},
24402441
modelReasoningEfforts: Object.fromEntries(OPENCODE_FREE_DEEPSEEK_MODELS.map(id => [id, deepseekThinkingEffortsFor(id)])),

‎tests/management-provider-validation.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,11 +2888,11 @@ describe("provider management validation", () => {
28882888
};
28892889

28902890
// Clearing user-managed headers must not delete the registry-owned static
2891-
// metadata (opencode-free's x-opencode-client marker) the transport relies on.
2891+
// metadata (opencode-free's User-Agent and x-opencode-client markers) the transport relies on.
28922892
expect((await patch("opencode-free", { headers: null }))?.status).toBe(200);
2893-
expect(liveConfig.providers["opencode-free"].headers).toEqual({ "x-opencode-client": "desktop" });
2893+
expect(liveConfig.providers["opencode-free"].headers).toEqual({ "User-Agent": "opencode", "x-opencode-client": "desktop" });
28942894
const saved = JSON.parse(readFileSync(join(TEST_DIR, "config.json"), "utf8")) as OcxConfig;
2895-
expect(saved.providers["opencode-free"]?.headers).toEqual({ "x-opencode-client": "desktop" });
2895+
expect(saved.providers["opencode-free"]?.headers).toEqual({ "User-Agent": "opencode", "x-opencode-client": "desktop" });
28962896
});
28972897
test("concurrent provider PATCHes merge different headers", async () => {
28982898
if (existsSync(TEST_DIR)) rmSync(TEST_DIR, { recursive: true });

‎tests/opencode-free-provider.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ describe("opencode-free provider", () => {
2929

3030
test("static headers include only the public client marker", () => {
3131
expect(entry?.staticHeaders?.["Authorization"]).toBeUndefined();
32+
expect(entry?.staticHeaders?.["User-Agent"]).toBe("opencode");
3233
expect(entry?.staticHeaders?.["x-opencode-client"]).toBe("desktop");
3334
});
3435

3536
test("providerConfigSeed propagates static headers", () => {
3637
const seed = providerConfigSeed(entry!);
3738
expect(seed.headers?.["Authorization"]).toBeUndefined();
39+
expect(seed.headers?.["User-Agent"]).toBe("opencode");
3840
expect(seed.headers?.["x-opencode-client"]).toBe("desktop");
3941
expect(seed.keyOptional).toBe(true);
4042
expect(seed.liveModels).toBe(true);
@@ -55,6 +57,7 @@ describe("opencode-free provider", () => {
5557
const req = adapter.buildRequest(minimalRequest());
5658
const headers = req.headers as Record<string, string>;
5759
expect(headers["Authorization"]).toBeUndefined();
60+
expect(headers["User-Agent"]).toBe("opencode");
5861
expect(headers["x-opencode-client"]).toBe("desktop");
5962
expect(req.url).toBe("https://opencode.ai/zen/v1/chat/completions");
6063
});

0 commit comments

Comments
 (0)