Files
magpie/internal/provider/testdata/opencode-2.2.5-chat.json
T
yetone 9feb1024c7 zen: free models are asked as OpenCode 2.2.5 asks them (#3491)
laomao04_65777 on Discord: Zen's free models answered 429 "Free usage limit
reached. Free models work in OpenCode" to the built-in OpenCode Zen provider,
while real OpenCode 2 on the same machine was served. magpie sent OpenCode
1.x's shape. It now sends what OpenCode 2.2.5 sent in a captured request
(internal/provider/testdata/opencode-2.2.5-chat.json, from a recording proxy),
as the zen-free plugin does since plugins d62193c and 8501988:

- User-Agent opencode/latest/<v>/cli. <v> is the version OpenCode's updater
  (opencode.ai/update/api/latest/cli/npm) names, never below 2.2.5 and never
  anything but a plain x.y.z. It is read in the background at most every 6h,
  with a 3s timeout and no redirects.
- x-opencode-project is OpenCode's project id for the folder the agent says it
  works in: sha1 of git-remote:host/path (origin, else the first remote;
  worktree .git files followed), else of directory:<root or folder>. It is no
  longer "global".
- b3 and traceparent: one trace a conversation, a new span a request.
- The session id goes in x-opencode-session, x-opencode-session-id,
  x-session-affinity and x-session-id. Accept is */*, and x-opencode-request
  is gone.
- On a free request the agent's own headers (Claude Code's x-stainless-*,
  Codex's originator) are dropped. Only Content-Type and Anthropic-Version
  and Anthropic-Beta are kept.
- The core tools are edit, glob, grep, read and shell with 2.2.5's schemas,
  strict false on Chat. Claude Code's Read, Edit, Glob and Grep are offered
  under those names. Its Bash is no longer bash: shell is a stub.
- OpenCode's <env> block, word for word, for the agent's folder, is added to
  the system prompt unless it has one already (OpenCode's own).
- Paths are the v2 catalog's: /inference/openai/v1 for Chat and Responses,
  and /inference/anthropic/v1 for Messages. The models list is unchanged.

Every route takes this: chat, responses and messages through forwardOnce, the
Test button's probe (tiny/zenFreeProbe), and the models list
(listHeadersAt: UA and x-opencode-client).

Sibling: paid Zen and OpenCode Go share OpenCodeClient, so they get 2.2.5's
headers. Their /zen/v1 and /zen/go/v1 paths are left as they are: #4740.

Run on mote (mote-run) at this tree:
- gofmt -l . is clean.
- GOOS=darwin and windows go vet ./... pass. GOOS=linux go vet passes for
  internal/provider and internal/gateway. The whole-tree Linux vet stops in
  Wails' cgo when run from macOS, and in WSL for want of gtk4, before it
  reaches this change.
- go test ./internal/provider ./internal/gateway -count=1 -timeout 45m:
  ok provider (154s) and ok gateway (715s) on base 788057340. After the
  rebase onto a5a9cdf7b, which touched gateway.go and ir.go, the same
  tree passed again: ok provider (138s) and ok gateway (816s), with GOOS
  darwin, linux and windows go vet of both packages.
- Rebased again onto 4c815ac2a, which touched search.go and provider.go.
  At that head gofmt and the three-OS vet of both packages are clean, and
  -run 'OpenCode|Zen|Search|Searcher' passes in both packages. The full
  suites were not rerun after this last rebase.

Broken by hand, each turning a test red (provider and gateway, -run
'OpenCode|Zen', on mote):
- version 1.19.0: TestOpenCodeClientIs225 and TestOpenCodeVersionFromUpdater.
- the old /inference/v1 path: TestOpenCodeFreeURL, TestZenFreeAsOpenCode225,
  TestZenFreeAtInferenceURL and TestZenPublicTestAsksFreeModels.
- caller headers kept: TestZenFreeAsOpenCode225.
- no env block: TestZenFreeAsOpenCode225.
- no strict: TestZenFreeAtInferenceURL.
- project "global": TestOpenCodeClientIs225, TestOpenCodeClientHeaders and
  TestZenFreeAsOpenCode225.
- the same span on every request: TestOpenCodeClientIs225 and
  TestOpenCodeClientHeaders.
- no 2.2.5 floor: TestOpenCodeVersionFromUpdater.
- a changed read schema: TestOpenCodeToolsAre225s.

Not tried:
- A real 200 from a free model: this egress IP's free allowance is spent.
  The captured 2.2.5 request itself got 429.
- Header order and case: Go's HTTP/1 writes headers sorted, and HTTP/2
  lowercases them, so OpenCode's order cannot be copied.
- Windows' project id against real OpenCode on Windows.
2026-11-01 14:48:19 +08:00

264 lines
6.6 KiB
JSON

{
"captured": "OpenCode 2.2.5 release binary (@opencode/cli), sandbox HOME on mote, at a recording proxy, 2026-11-01T05:33Z: its primary chat request for deepseek-v4.1-flash-free",
"method": "POST",
"url": "/inference/v1/chat/completions",
"status": 429,
"headers": [
[
"Authorization",
"Bearer public"
],
[
"Content-Type",
"application/json"
],
[
"User-Agent",
"opencode/latest/2.2.5/cli"
],
[
"b3",
"6a693d4fc42bc0b0c04fd83712a03bae-f076ef33aef71e8e-1-4727dea9e05b5761"
],
[
"traceparent",
"00-6a693d4fc42bc0b0c04fd83712a03bae-f076ef33aef71e8e-01"
],
[
"x-opencode-client",
"cli"
],
[
"x-opencode-project",
"1132ded9876e9dc00df57eea7de251c155550345"
],
[
"x-opencode-session",
"ses_e6a66888dffe4VGjh70Dg9k6f3"
],
[
"x-opencode-session-id",
"ses_e6a66888dffe4VGjh70Dg9k6f3"
],
[
"x-session-affinity",
"ses_e6a66888dffe4VGjh70Dg9k6f3"
],
[
"x-session-id",
"ses_e6a66888dffe4VGjh70Dg9k6f3"
],
[
"Connection",
"keep-alive"
],
[
"Accept",
"*/*"
],
[
"Host",
"127.0.0.1:47811"
],
[
"Accept-Encoding",
"gzip, deflate, br, zstd"
],
[
"Content-Length",
"22720"
]
],
"bodyKeys": [
"model",
"messages",
"tools",
"stream",
"stream_options",
"max_completion_tokens"
],
"stream_options": {
"include_usage": true
},
"environment": "Here is some useful information about the environment you are running in:\n<env>\n Working directory: /Users/yetone/runs/zencap/home/work\n Workspace root folder: /Users/yetone/runs/zencap/home/work\n Is directory a git repo: no\n Platform: darwin\n Prefer /private/tmp/opencode over generic system temporary directories such as /tmp; it is pre-created and approved for external access.\n</env>",
"tools": [
{
"type": "function",
"function": {
"name": "edit",
"description": "(OpenCode description left out)",
"parameters": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "File to edit"
},
"oldString": {
"type": "string",
"description": "Exact text to find and replace"
},
"newString": {
"type": "string",
"description": "Text to replace oldString with (must differ from oldString)"
},
"replaceAll": {
"type": "boolean",
"description": "Whether to replace every occurrence of oldString. When false, oldString must match exactly once. Defaults to false."
}
},
"required": [
"path",
"oldString",
"newString"
],
"additionalProperties": false
},
"strict": false
}
},
{
"type": "function",
"function": {
"name": "glob",
"description": "(OpenCode description left out)",
"parameters": {
"type": "object",
"properties": {
"pattern": {
"type": "string",
"description": "Glob pattern to match files against"
},
"path": {
"type": "string",
"description": "Directory to search. Defaults to the current working directory."
},
"hidden": {
"type": "boolean",
"description": "Include hidden files and directories (default: false)."
},
"limit": {
"type": "integer",
"exclusiveMinimum": 0,
"description": "Maximum number of matching files to return (default: 100)"
}
},
"required": [
"pattern"
],
"additionalProperties": false
},
"strict": false
}
},
{
"type": "function",
"function": {
"name": "grep",
"description": "(OpenCode description left out)",
"parameters": {
"type": "object",
"properties": {
"pattern": {
"type": "string",
"minLength": 1,
"description": "Regular expression or literal text to match in file contents."
},
"path": {
"type": "string",
"description": "File or directory to search. Defaults to the current working directory."
},
"include": {
"type": "string",
"description": "Glob pattern to filter files (for example, \"*.js\" or \"*.{ts,tsx}\")"
},
"literal": {
"type": "boolean",
"description": "Treat `pattern` as exact text instead of a regular expression (default: false)."
},
"caseSensitive": {
"type": "boolean",
"description": "Use case-sensitive matching (default: true)."
},
"limit": {
"type": "integer",
"exclusiveMinimum": 0,
"description": "Maximum number of matching lines to return (default: 100)"
}
},
"required": [
"pattern"
],
"additionalProperties": false
},
"strict": false
}
},
{
"type": "function",
"function": {
"name": "read",
"description": "(OpenCode description left out)",
"parameters": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "File or directory to read"
},
"offset": {
"type": "integer",
"minimum": 0,
"description": "The line or directory entry to start reading from (1-based)"
},
"limit": {
"type": "integer",
"minimum": 0,
"description": "The maximum number of lines or directory entries to read (defaults to and capped at 2000)"
}
},
"required": [
"path"
],
"additionalProperties": false
},
"strict": false
}
},
{
"type": "function",
"function": {
"name": "shell",
"description": "(OpenCode description left out)",
"parameters": {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "Shell command string to execute"
},
"workdir": {
"type": "string",
"description": "Working directory to execute the command in. Defaults to the current working directory. When possible, avoid changing directories in the command and set the working directory here instead."
},
"timeout": {
"type": "integer",
"minimum": 0,
"description": "Timeout in milliseconds. Set to 0 to disable the timeout. Defaults to 120000 for foreground commands. Background commands have no timeout by default."
},
"background": {
"type": "boolean",
"description": "Run the command in the background and return immediately (useful for dev servers and long-running builds). You do not need to use '&' at the end of the command when using this parameter. You will be notified when it completes. DO NOT poll for completion."
}
},
"required": [
"command"
],
"additionalProperties": false
},
"strict": false
}
}
]
}