anomalyco / anomalyco/opencode
feat: inject session_id for OpenRouter session grouping
@jlongster is already working on this.
Since Aug 1, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Problem
OpenRouter supports session-level grouping via a session_id field in the request body. This allows upstream providers to attribute and group requests by session, which is useful for analytics, billing, and debugging across multi-turn conversations.
Currently, opencode does not pass session_id to OpenRouter requests, so all requests from the same conversation are ungrouped at the provider level.
Proposed solution
Inject session_id into the request extraBody when the model API provider is @openrouter/ai-sdk-provider. This leverages the existing extraBody mechanism in the AI SDK to pass the field through without requiring provider-specific request restructuring.
Scope
packages/opencode/src/provider/transform.ts— addextraBody.session_idfor OpenRouter modelspackages/opencode/test/provider/transform.test.ts— test coverage
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.