Skip to content

Bug: OpenCode CLI v2.3.0 triggers 429 FreeUsageLimitError due to title request misidentification #178

Closed

Description

@threegod3

描述 (Description)
Hello, first of all, thank you for the great project! I am using opencode2api as a local proxy for my API relay station.

I'm encountering a 429 FreeUsageLimitError issue specifically when using the official OpenCode CLI v2.3.0. However, the exact same upstream endpoint and keys work perfectly when called via Python (OpenAI SDK), which means the IP pool and quotas are fine. I suspect the issue is related to how v2.3.0 generates Session Title Requests and how the 2api proxy injects system prompts.

复现步骤 (Steps to Reproduce)
Start opencode2api locally at http://127.0.0.1:8080.

Configure OpenCode CLI to use this local endpoint (/v1).

Launch opencode (v2.3.0) and send a normal message to a free model (e.g., deepseek-v4.1-flash-free).

The CLI immediately errors out with:
Error: Free usage limit reached. Free models work in OpenCode...

I using in other tools like deepseek harness and claude code,they all come back 429 error

对比测试 (Comparison Test)
✅ Python Call (Works):

python
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="sk-...")
resp = client.chat.completions.create(
model="longcat-2.5-free",
messages=[{"role": "user", "content": "你好,你是谁"}]
)

Returns 200 OK, correct response.

❌ OpenCode CLI v2.3.0 (Fails):
Fails immediately with 429.

根本原因推测 (Root Cause Analysis)
I read your recent changelog regarding "修正:OpenCode 會話標題請求" (Fix: OpenCode session title requests). You mentioned:

"判定要求無工具、至多 3 條消息且無 assistant / tool 輪次,代理流量不會被誤判。"

It seems that OpenCode v2.3.0 might have changed the structure of its title generation request (e.g., sending extra history messages, or altering the system prompt format).
Because it fails to match your strict identification logic (<= 3 messages and no tools), 2api mistakenly treats the title request as a standard coding request and injects the official toolset (shell, grep, etc.). The upstream OpenCode server detects tools in a title-generation request and immediately rejects it with 429 FreeUsageLimitError (or 403 FreeTierError).

Activity

  1. jasonxu114514 commented on Nov 16, 2026

    @jasonxu114514
    Owner

    Fixed a confirmed classification inconsistency in main 14faec7: 14faec7 . Title detection now runs before prompt/message mutations. Adding a system message or folding system/developer messages can no longer change the classification used for tool injection versus retries/fallback. Existing title phrases, no-tools/history restrictions, retry budgets and session IDs are unchanged. Offline v1/v2 three/four-message boundary regressions passed. The commit also preserves upstream HTTP errors and Retry-After across later transport failures. Keeping this issue open: the reported OpenCode 2.3.0 payload was not available and no live upstream request was made, so this is not proof its 429 is resolved. Please retest an updated binary; only share a minimal sanitized reproduction, never credentials/auth headers or private prompts.

  2. unrayed commented on Nov 16, 2026

    @unrayed
    Contributor

    This is the same cause as #181: the free tier refuses the literal clint_ wire-name prefix, which the gateway prepends to every renamed client tool on a shaped free-model request. It is not the session, the title request, or the injected prompt.

    Evidence, one identical official-CLI chat body (75,654 B, 20 tools), same session id, project id and egress, two builds of 14faec7 differing only in that constant:

    wire-name prefix result
    clint_ (current main) 429 FreeUsageLimitError in 3.4 s
    mcp_ 200 in 2.6 s, tool call restored to shell, follow-up with the tool result → 200 with the final answer
    CLINT_ 429
    clint (no underscore) 200
    client_, copilot_, mcp_, srv_, fn_, zz_ 200
    client names passed through, shaping bypassed, prompt injection only 200

    Your Python SDK call works for exactly that reason: with no tools array (or with a body that is not shaped), no clint_ name is ever generated.

    Fix is #182, head 75bb45d — ClientToolPrefix becomes mcp_, response restoration reads the same constant, so nothing else moves. It is verified live on both the /v1/messages and official-CLI chat paths. A retest with the commit hash is what would close this out; no credentials or private prompts needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions