Skip to content

Support custom headers or stable chat session identifiers for BYOK/OpenAI-compatible model providers #316794

Description

I would like VS Code / GitHub Copilot BYOK model configuration to support either custom static request headers for OpenAI-compatible providers, or a stable per-chat session identifier that is sent with every request in the same chat session.

Background

I am using locally deployed OpenAI-compatible models with BYOK in both VS Code and VS Code Insiders. In my setup, the local inference server is backed by vLLM, and request-level metadata can be useful for cache management, routing, and session-aware behavior.

For example, when using vLLM or a proxy in front of it, I can enable more effective cache usage by sending stable headers such as a tenant/session/cache key header. Some other extensions that support custom OpenAI-compatible providers already allow this. For example, Kilo Code lets users configure custom headers when adding a custom OpenAI-compatible provider.

When I inspected the requests sent by Copilot, I could see request/completion identifiers that change per prompt, but I could not find a stable value that remains the same for all prompts in the same chat window/session. This makes it difficult for local providers or proxies to associate related requests with the same chat session for caching or routing purposes.

Proposed solution

It would be helpful if VS Code supported one or both of the following for BYOK/OpenAI-compatible providers:

  1. Allow users to configure custom static headers per model/provider.

    Example:

    {
      "X-Cache-Key": "my-local-vscode-model",
      "X-Provider-Mode": "local"
    }
    
  2. Automatically generate and send a stable chat/session identifier for each chat window or conversation.

    X-VSCode-Chat-Session-Id: <stable-id-for-this-chat>

    This value would remain stable for all prompts in the same chat session, but change for a new chat session.

Why this would be useful

This would make BYOK more practical for local and self-hosted model deployments, especially when the provider or proxy needs stable metadata for:

  • prompt/prefix cache management
  • vLLM-backed local deployments
  • request routing
  • per-session observability
  • debugging local provider behavior
  • integrating OpenAI-compatible proxies that support custom headers

Since VS Code appears to be investing more in BYOK and custom model provider support, this would make the feature more flexible for local/self-hosted model users without requiring provider-specific hardcoding.

Existing behavior in other tools

Some extensions already support this kind of configuration. For example, Kilo Code allows custom headers when configuring a custom OpenAI-compatible provider. A similar capability in VS Code's native BYOK support would be very useful.

Alternatives considered

A provider-side proxy can sometimes infer or generate its own session keys, but without a stable identifier from the client, it cannot reliably group requests from the same chat session. Per-request completion IDs are not enough for this use case because they change with every prompt.

Kilo Code Implementation

Image Image

Activity

  1. albayrakonur commented on May 18, 2026

    @albayrakonur
    Author

    I re-examined the headers sent by Copilot Chat requests and noticed the following: it always sends a header named cookie, but within the same chat window, this value may not remain constant.

    cookie: 0e31969188bd30aee89be6c9340fab86=f531a50b5863e68d3d3470b3ab2b347b

    Vritant Bhardwaj (@vritant24) This might be useful for you.

  2. CezaryKlus commented on Jul 9, 2026

    @CezaryKlus

    My use case is actually to support a stable session identifier as a variable to be used in chatLanguageModels.json
    Context: Fireworks AI models via Custom Endpoint and prompt caching

    https://docs.fireworks.ai/guides/prompt-caching#optimizing-inference-request-for-caching

    I would like to specify this:

    "requestHeaders": {
    	"x-session-affinity": "${sessionId}",
    	"x-prompt-cache-isolation-key": "${sessionId}"
    }
    
  3. brenwhyte commented on Jul 23, 2026

    @brenwhyte

    PortKey user here and we need to be able to set x-portkey-api-key header to auth to the Gateway.

  4. albayrakonur commented on Aug 4, 2026

    @albayrakonur
    Author

    PortKey user here and we need to be able to set x-portkey-api-key header to auth to the Gateway.

    you can user requestHeaders parameters inside customendpoint definition. see https://code.visualstudio.com/docs/agent-customization/language-models#_add-a-custom-endpoint-model

  5. albayrakonur commented on Aug 4, 2026

    @albayrakonur
    Author

    Vritant Bhardwaj (@vritant24) if you should provide each chat session has unique session-id value , it will be good for session based api usage stats.

  6. BIT-Orange commented on Sep 24, 2026

    @BIT-Orange

    +1 on the stable-session-identifier variable — and it is worth noting that without it a whole class of gateways simply cannot be configured, because requestHeaders values are static today.

    Concrete case: OpenCode Go requires a session header on every inference request and rejects the request otherwise (400 MissingSessionID, tracked in #334186). The only user-side way to satisfy it now is to hardcode one UUID per model:

    "requestHeaders": { "x-opencode-session": "ses_<one-fixed-uuid>" }

    which makes every conversation on that model share one affinity/prompt-cache bucket — the opposite of what the header is for. (The other dynamic token that exists is ${apiKey} in CustomEndpointOAIEndpoint._interpolateApiKey(), extensions/copilot/src/extension/byok/vscode-node/customEndpointProvider.ts:315.)

    Proposed shape

    Support ${sessionId} (name TBD) in requestHeaders values, exactly as Cezary Klus (@CezaryKlus) sketched:

    "requestHeaders": {
      "x-session-affinity": "${sessionId}",
      "x-prompt-cache-isolation-key": "${sessionId}",
      "x-opencode-session": "${sessionId}"
    }

    Semantics I'd suggest:

    • substituted per request, not at model-load time (today _customHeaders is computed once in the OpenAIEndpoint constructor, extensions/copilot/src/extension/byok/node/openAIEndpoint.ts:141, and getExtraHeaders() at :408 takes no context);
    • identical value for all turns of one conversation, new value for a new conversation;
    • header omitted (rather than sent empty) when no conversation can be determined, e.g. utility/title flows, so gateways never receive a blank session id.

    Where the value can come from: the chat session identity, or — equivalent for routing and prompt-cache grouping — a memoized hash of the conversation's first user message. The community provider extensions that exist purely to add this one header (ltmoerdani/opencode-copilot-chat, OnesoftQwQ/opencode-go-copilot-provider) implement the latter, which shows the behaviour is achievable inside the current provider API without new core plumbing.

    A token is preferable to hardcoding a provider-specific header, but if the VS Code team prefers a single built-in contract, an opt-in setting that always sends x-vscode-chat-session-id: <stable-id> on BYOK requests would solve the same problem in one shot — providers that recognise it (OpenCode already recognises other clients' native session headers) get it for free, at the cost of needing per-gateway adoption.

  7. PawelWos1987 commented on Nov 17, 2026

    @PawelWos1987

    +1 on the stable-session-identifier variable

  8. added
    feature-request
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestmodel-byok

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions