Skip to content

bug: pi doesn't set x-opencode-session header parameter when calling opencode go and zen providers #4847

@markokocic

Description

@markokocic

What happened?

According to opencode documentation and source code, it uses the x-opencode-session header parameter so it can route requests from the same session to the same provider to improve token caching and thus reduce costs for the user.

pi coding agent should send this parameter with every request to opencode go and zen. It should use a unique and unchangeable id for current session.

Workaround is to hardcode header in models.json like this:

{
  "providers": {
    "opencode": {
      "headers": {
        "x-opencode-session": "wsl"
      }
    },
    "opencode-go": {
      "headers": {
        "x-opencode-session": "wsl"
      }
    },
...

This would pin all incoming requests from the same pi installation to the same provider, but the issue with this approach is that it's bound to the installation and not to the actual session.

Steps to reproduce

Set /model to some of opencode models.
do random request.
go to opencode Zen usage page
check the list of requests
SESSION is missing

Expected behavior

pi should set x-opencode-session header parameters.

Optionally, it may play a good citizen and also set x-opencode-client to "pi", for opencode stats purposes.

Version

0.75.4

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginprogressIssue is being worked on

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions