You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
X-Session-Id not recognized by LiteLLM / observability tools — should follow x-<vendor>-session-id convention #39912
OpenCode sends X-Session-Id (and x-session-affinity) with every LLM request so providers
can correlate calls across sessions. I confirmed both headers reach the server — but neither
one is recognized by LiteLLM (the most widely used open-source LLM proxy) for session grouping.
Root cause
LiteLLM auto-detects session IDs from headers following this pattern:
x--session-id e.g., x-claude-code-session-id
"Any header matching the pattern x-<vendor>-session-id (for example, x-claude-code-session-id)
is auto-detected as the session id if neither explicit LiteLLM header is present."
— LiteLLM Request Headers docs
Neither of OpenCode's headers match:
Header
Why it fails
x-session-affinity
Doesn't end in -session-id
X-Session-Id
x-session-id — missing vendor name
If the header were X-Opencode-Session-Id, LiteLLM would pick it up automatically.
Same for any other proxy or observability tool that follows this convention.
What happens today
Every OpenCode request through a LiteLLM proxy gets logged as a separate, ungrouped session.
This breaks per-session cost tracking, conversation tracing, agent loop debugging, and
session-based budget limits.
Proposed fix
In packages/opencode/src/session/llm/request.ts, add one line after line 198:
Additive — X-Session-Id stays untouched, no breakage for anyone relying on it today
One line — zero risk
Self-documenting — X-Opencode-Session-Id tells any tool exactly what it is and where it comes from
Follows RFC 6648 — incorporates the organization name in custom headers
Why this isn't LiteLLM-specific
The x-<vendor>-session-id pattern isn't owned by LiteLLM — it's an emerging convention in
LLM infrastructure. A header named X-Opencode-Session-Id also helps any custom proxy,
gateway, or observability stack identify where session traffic originates from, without
cross-referencing other headers.
Reacted by Julien Roncaglia, TomSeestern, Anthony Byrne and amellouli-mgmtp
Could this also add x-opencode-parent-session-id alongside the proposed x-opencode-session-id?
OpenCode already sends x-parent-session-id for child/subagent sessions. Namespacing both fields would let gateways preserve the complete session hierarchy under one x-opencode-* header family:
x-opencode-session-id: the current session's own ID, including for a child session.
x-opencode-parent-session-id: its immediate parent's ID, omitted for root sessions.
We're integrating this metadata into Dynamo's agent context and would like the same identity headers on custom-provider requests, not just the opencode* provider path. Keeping the existing generic headers and x-opencode-session as compatibility aliases would avoid breaking current integrations.
Please cover both the provider-aware request builder and the core session runner, which both currently emit the generic parent header. This only requests consistent names for existing identity metadata, without changing session or routing behavior.
Activity
ishandhanani commentedon Sep 29, 2026
Could this also add
x-opencode-parent-session-idalongside the proposedx-opencode-session-id?OpenCode already sends
x-parent-session-idfor child/subagent sessions. Namespacing both fields would let gateways preserve the complete session hierarchy under onex-opencode-*header family:x-opencode-session-id: the current session's own ID, including for a child session.x-opencode-parent-session-id: its immediate parent's ID, omitted for root sessions.We're integrating this metadata into Dynamo's agent context and would like the same identity headers on custom-provider requests, not just the
opencode*provider path. Keeping the existing generic headers andx-opencode-sessionas compatibility aliases would avoid breaking current integrations.Please cover both the provider-aware request builder and the core session runner, which both currently emit the generic parent header. This only requests consistent names for existing identity metadata, without changing session or routing behavior.