Skip to content

fix: send x-opencode-session header to OpenCode providers - #4190

Open
IsmaelMartinez wants to merge 1 commit into
docker:mainfrom
IsmaelMartinez:fix/opencode-session-header
Open

fix: send x-opencode-session header to OpenCode providers#4190
IsmaelMartinez wants to merge 1 commit into
docker:mainfrom
IsmaelMartinez:fix/opencode-session-header

Conversation

@IsmaelMartinez

@IsmaelMartinez IsmaelMartinez commented Sep 7, 2026

Copy link
Copy Markdown

OpenCode's docs ask clients to send a stable ID per conversation in x-opencode-session, which they use to optimise routing and prompt caching. The reporter of #4164 additionally quotes an OpenCode email saying requests missing the header may error from 2026-09-06; the docs themselves state no date, so treat the deadline as their account rather than a documented one.

A middleware on the OpenAI client, the same shape as the existing chatgptAuthMiddleware, sets the header on every request to opencode.ai, covering both built-in aliases and custom providers. The value is a UUIDv5 derived from the session ID already on the request context, salted so it cannot be correlated with the local session store or the gateway's X-Cagent-Session-Id. Requests with no session on the context fall back to a per-client UUID, and a value pinned through provider_opts.http_headers always wins.

This supersedes an earlier version of this PR that set the header once at client construction. @yunus25jmi1 pointed out in #4191 that the client is built once per process in serve a2a, serve mcp and the TUI, so a construction-time value collapses to one ID per deployment in exactly the multiplexed cases the issue is about. The implementation here is theirs, carried over with the commit co-authored; my part is the docs wording and the accuracy corrections against OpenCode's published text.

Custom Anthropic or Google providers pointed at OpenCode are still not covered, since those clients have no custom-header support today.

Fixes #4164

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qyjba1txhq3QsrpcGUt3FM

@aheritier aheritier added area/docs Documentation changes area/providers/openai For features/issues/fixes related to the usage of OpenAI models kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Sep 7, 2026
@IsmaelMartinez
IsmaelMartinez force-pushed the fix/opencode-session-header branch from 9e1feea to 733ec47 Compare September 7, 2026 18:52
@IsmaelMartinez
IsmaelMartinez marked this pull request as ready for review September 7, 2026 19:03
@IsmaelMartinez
IsmaelMartinez requested a review from a team as a code owner September 7, 2026 19:03
@IsmaelMartinez
IsmaelMartinez force-pushed the fix/opencode-session-header branch from 733ec47 to 7a0b20e Compare September 7, 2026 19:07
@IsmaelMartinez
IsmaelMartinez marked this pull request as draft September 7, 2026 19:08
@IsmaelMartinez
IsmaelMartinez marked this pull request as ready for review September 7, 2026 20:55
@IsmaelMartinez
IsmaelMartinez force-pushed the fix/opencode-session-header branch from 7a0b20e to c45be64 Compare September 8, 2026 07:03
OpenCode asks clients to send a stable session ID per conversation, which it
uses to optimise routing and prompt caching. A middleware derives the value
from the session already on the request context, so multiplexed deployments
get one ID per conversation rather than one per client.

Fixes docker#4164

Co-Authored-By: Md Yunus <admin@yunuscollege.eu.org>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qyjba1txhq3QsrpcGUt3FM
@IsmaelMartinez
IsmaelMartinez force-pushed the fix/opencode-session-header branch 2 times, most recently from c45be64 to d4fa155 Compare September 8, 2026 07:21
@yunus25jmi1

Copy link
Copy Markdown
Contributor

Thanks @IsmaelMartinez, c45be640 matches #4191 apart from the wording, and the co-author credit is appreciated. The softened phrasing is fair given OpenCode's docs. Closing #4191 so the review stays in one place; LGTM from my side.

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

Labels

area/docs Documentation changes area/providers/openai For features/issues/fixes related to the usage of OpenAI models kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode Go/Zen do not send an x-opencode-session header (required by OpenCode from 2026-09-06)

3 participants