From 946f871762372b2c66423baae3711550a0890b05 Mon Sep 17 00:00:00 2001 From: Roman | RyzenAdvanced Date: Mon, 25 May 2026 16:52:51 +0400 Subject: [PATCH] Fix Freebuff: correct User-Agent, metadata fields, session body, preset aliases - User-Agent: ai-sdk/openai-compatible/1.0.25/codebuff (matches official SDK) - metadata: freebuff_instance_id (not codebuff_instance_id) + client_id field - Session POST: empty body {} (not {model: ...}) - Add Freebuff/FreeBuff preset aliases for backward compat --- src/codex-launcher-gui | 18 ++++++++++++++++++ src/translate-proxy.py | 19 ++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/codex-launcher-gui b/src/codex-launcher-gui index 1ab4286..c7870d6 100755 --- a/src/codex-launcher-gui +++ b/src/codex-launcher-gui @@ -400,6 +400,24 @@ PROVIDER_PRESETS = { "moonshotai/kimi-k2.6", "minimax/minimax-m2.7", ], }, + "Freebuff (Free DeepSeek/Kimi)": { + "backend_type": "codebuff", + "base_url": "https://www.codebuff.com", + "oauth_provider": "codebuff", + "models": [ + "deepseek/deepseek-v4-pro", "deepseek/deepseek-v4-flash", + "moonshotai/kimi-k2.6", "minimax/minimax-m2.7", + ], + }, + "FreeBuff": { + "backend_type": "codebuff", + "base_url": "https://www.codebuff.com", + "oauth_provider": "codebuff", + "models": [ + "deepseek/deepseek-v4-pro", "deepseek/deepseek-v4-flash", + "moonshotai/kimi-k2.6", "minimax/minimax-m2.7", + ], + }, } def safe_name(name): diff --git a/src/translate-proxy.py b/src/translate-proxy.py index b000613..76d18a9 100755 --- a/src/translate-proxy.py +++ b/src/translate-proxy.py @@ -331,11 +331,11 @@ def _codebuff_get_session(token, model): return sc["instance_id"] try: url = f"{_CODEBUFF_API_URL}/api/v1/freebuff/session" - body = json.dumps({"model": model}).encode() + body = json.dumps({}).encode() req = urllib.request.Request(url, data=body, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {token}", - "User-Agent": "codex-launcher/3.10.5", + "User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff", "x-codebuff-model": model, }) try: @@ -383,7 +383,7 @@ def _codebuff_start_run(token, agent_id): req = urllib.request.Request(url, data=body, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {token}", - "User-Agent": "codex-launcher/3.10.5", + "User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff", }) try: resp = urllib.request.urlopen(req, timeout=15) @@ -416,7 +416,7 @@ def _codebuff_finish_run(token, run_id, status="completed"): req = urllib.request.Request(url, data=body, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {token}", - "User-Agent": "codex-launcher/3.10.5", + "User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff", }) try: urllib.request.urlopen(req, timeout=10) @@ -5324,9 +5324,10 @@ class Handler(http.server.BaseHTTPRequestHandler): metadata = { "run_id": run_id, "cost_mode": "free", + "client_id": secrets.token_hex(7)[:13], } if instance_id: - metadata["codebuff_instance_id"] = instance_id + metadata["freebuff_instance_id"] = instance_id chat_body = { "model": model, @@ -5348,7 +5349,7 @@ class Handler(http.server.BaseHTTPRequestHandler): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {token}", - "User-Agent": "codex-launcher/3.10.5", + "User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff", "x-codebuff-model": model, } if instance_id: @@ -5496,9 +5497,9 @@ class Handler(http.server.BaseHTTPRequestHandler): instance_id = _codebuff_get_session(token, model) messages = _cb_input_to_messages(input_data, instructions) _codebuff_hard_disable_reasoning(messages) - metadata = {"run_id": run_id, "cost_mode": "free"} + metadata = {"run_id": run_id, "cost_mode": "free", "client_id": secrets.token_hex(7)[:13]} if instance_id: - metadata["codebuff_instance_id"] = instance_id + metadata["freebuff_instance_id"] = instance_id chat_body = { "model": model, "messages": messages, "stream": stream, "max_tokens": max(body.get("max_output_tokens", 0), 64000), @@ -5514,7 +5515,7 @@ class Handler(http.server.BaseHTTPRequestHandler): if body.get("tool_choice"): chat_body["tool_choice"] = body["tool_choice"] target = f"{_CODEBUFF_API_URL}/api/v1/chat/completions" - headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}", "User-Agent": "codex-launcher/3.10.5", "x-codebuff-model": model} + headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}", "User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff", "x-codebuff-model": model} if instance_id: headers["x-codebuff-instance-id"] = instance_id print(f"[codebuff] retry POST {target} model={model} stream={stream} run={run_id} (thinking disabled via DeepSeek native)", file=sys.stderr)