anomalyco / anomalyco/opencode

X-Session-Id not recognized by LiteLLM / observability tools — should follow x-<vendor>-session-id convention

Open
#39,912 0 comments 3 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Jul 31, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Problem

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:

            "x-session-affinity": input.sessionID,
            "X-Session-Id": input.sessionID,
+           "X-Opencode-Session-Id": input.sessionID,
            ...(input.parentSessionID ? { "x-parent-session-id": input.parentSessionID } : {}),

This is:

  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.