Skip to content

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

Closed

Description

@lucasferraro

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.

Activity

  1. ishandhanani commented on Sep 29, 2026

    @ishandhanani

    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.

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

Metadata

Metadata

Assignees

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