Skip to content

feat(openrouter): forward session_id and add app category header - #10868

Merged
alexhancock merged 1 commit into
aaif-goose:mainfrom
Lee-Si-Yoon:feat/openrouter-session-id
Aug 20, 2026
Merged

alexhancock merged 1 commit into
aaif-goose:mainfrom
Lee-Si-Yoon:feat/openrouter-session-id

Conversation

@Lee-Si-Yoon

Copy link
Copy Markdown
Contributor

Summary

OpenRouter dashboard provides per-session grouping via a non-standard session_id field in the request body. Goose was sending user (OpenAI standard end-user field) and agent-session-id header (goose telemetry), but neither triggers OpenRouter session grouping or sticky routing.

This PR:

  • Injects session_id into the request JSON body top-level alongside the existing user field
  • Adds X-OpenRouter-Categories: cli-agent,productivity header for marketplace category attribution
  • Removes stale comment that described only the user field

Background

OpenRouter's session_id is a proprietary extension field (not part of OpenAI Chat Completions spec). When present, OpenRouter groups requests by session in the dashboard and uses it for sticky routing to maximize prompt cache hits. Without it, only per-request view is available.

HTTP-Referer and X-Title headers were already implemented. X-OpenRouter-Categories was missing.

Changes

crates/goose/src/providers/openrouter.rs:

  1. from_env(): add .with_header("X-OpenRouter-Categories", "cli-agent,productivity")
  2. stream(): add obj.insert("session_id", ...) next to existing user field injection

Verification

  • cargo build -p goose ✅
  • cargo test -p goose --lib -- openrouter ✅ (20 passed, 0 failed)
  • cargo clippy -p goose --lib -- -D warnings ✅
  • cargo fmt ✅

OpenRouter dashboard session grouping requires a top-level
field in the request body. Goose was sending  (OpenAI standard
end-user field) and  header (goose telemetry), but
neither triggers OpenRouter session grouping or sticky routing.

- Inject  into request body alongside existing  field
- Add  header for
  marketplace category attribution
@Lee-Si-Yoon

Lee-Si-Yoon commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor Author

@jamadeo

Would appreciate a review when you get a chance. This PR adds OpenRouter session_id body field forwarding and the missing X-OpenRouter-Categories app attribution header.

@michaelneale

Copy link
Copy Markdown
Collaborator

🤖 Flagging a collision before either of these lands, since this PR has been open 19 days without review.

#11334 overlaps this PR and is already approved. Both modify the same if !session_id.is_empty() block in crates/goose/src/providers/openrouter.rs. I verified they conflict rather than assuming it — git merge-tree on their merge base produces two conflict regions in that block:

So there's a real semantic disagreement underneath the textual conflict: whether user should still be sent. That's a maintainer call, not something a merge resolution should decide silently.

Two things in this PR are not in #11334 and would be lost if #11334 simply lands first:

  1. The X-OpenRouter-Categories: cli-agent,productivity header
  2. Keeping the user field for attribution/rate-limiting

Conversely, #11334 adds a wiremock test asserting the body field, which this PR has no test for.

Worth someone deciding explicitly: either close this as superseded, or rebase it onto #11334 to keep just the category header. Not asking for a change — just making sure a 19-day-old contribution doesn't get quietly overwritten.

I have no stake in which way this goes; I'm triaging unreviewed PRs and this was the clearest duplicate.

@alexhancock
alexhancock added this pull request to the merge queue Aug 20, 2026
Merged via the queue into aaif-goose:main with commit f70cb64 Aug 20, 2026
24 checks passed
@Lee-Si-Yoon
Lee-Si-Yoon deleted the feat/openrouter-session-id branch August 20, 2026 13:44
alexhancock added a commit that referenced this pull request Aug 20, 2026
…bined

* origin/main: (85 commits)
  feat(desktop): sort configured providers to the top of the provider list (#11409)
  fix(cli): refuse symlink diagnostics outputs (#11398)
  test(plugins): isolate GOOSE_PATH_ROOT in discovery tests (#11407)
  fix(config): serialize secret mutations (#11388)
  fix: decouple source file and tool response limits (#11391)
  chore(deps): bump pctx_code_mode from 0.4.1 to 0.5.0 (#11245)
  fix(security): suppress sensitive OTLP traces (#11381)
  feat(openrouter): forward session_id and add app category header (#10868)
  feat(acp): derive and forward thinking effort from the ACP harness (#10949)
  fix(aws_bedrock): replace flat model list with routing table, add Gemma 4 Mantle support (#10297)
  Add GPT-5.6 follow-up support for Codex and Responses API (#10460)
  fix(update): fetch attestation bundles from bundle_url (#10557)
  fix(security): fail closed on invalid default GCP credentials (#11363)
  fix(codex): reject socket-backed MCP extensions (#11304)
  fix: pass complete response to stop hooks (#11366)
  fix: contain and bound skill supporting file reads (#11342)
  chore(deps): bump the ui-minor-and-patch group across 1 directory with 53 updates (#11386)
  fix(security): bound call graph traversal (#11193)
  fix: pin arrayref to known-good commit (#11389)
  feat(providers): add SayGM as declarative OpenAI-compatible provider (#11267)
  ...

# Conflicts:
#	crates/goose/src/agents/agent.rs
lifeizhou-ap added a commit that referenced this pull request Aug 21, 2026
* main: (70 commits)
  cli: remove recipe secret discovery (#11435)
  fix(openrouter): escape Gemini tool response ref keys (#11276)
  fix(security): honor MCP tool model visibility in Code Mode (#11425)
  fix(providers): estimate cost for Azure Foundry models via inferred catalog pricing (#11264)
  feat(providers): add Gondola as declarative OpenAI-compatible provider (#11421)
  feat(otel): add request params, response metadata, tool call parity, and agent identification (#11261)
  fix(providers): coalesce consecutive Thinking blocks in collect_stream (#11317)
  feat(hooks): add PreToolUseResult event and stable tool_call_id across tool lifecycle (#11120)
  add MCP conformance tests to goose CI (combines #10800 + #10801) (#10940)
  feat(desktop): sort configured providers to the top of the provider list (#11409)
  fix(cli): refuse symlink diagnostics outputs (#11398)
  test(plugins): isolate GOOSE_PATH_ROOT in discovery tests (#11407)
  fix(config): serialize secret mutations (#11388)
  fix: decouple source file and tool response limits (#11391)
  chore(deps): bump pctx_code_mode from 0.4.1 to 0.5.0 (#11245)
  fix(security): suppress sensitive OTLP traces (#11381)
  feat(openrouter): forward session_id and add app category header (#10868)
  feat(acp): derive and forward thinking effort from the ACP harness (#10949)
  fix(aws_bedrock): replace flat model list with routing table, add Gemma 4 Mantle support (#10297)
  Add GPT-5.6 follow-up support for Codex and Responses API (#10460)
  ...
lifeizhou-ap added a commit to Wolfe-Jam/goose that referenced this pull request Aug 21, 2026
* main: (107 commits)
  fix(providers): inform user of clipboard copy and remove copilot auth retry on timeout (aaif-goose#11160)
  feat(desktop): select saved recipes when creating a schedule (aaif-goose#10892)
  More provider test scripts (aaif-goose#10515)
  cli: remove recipe secret discovery (aaif-goose#11435)
  fix(openrouter): escape Gemini tool response ref keys (aaif-goose#11276)
  fix(security): honor MCP tool model visibility in Code Mode (aaif-goose#11425)
  fix(providers): estimate cost for Azure Foundry models via inferred catalog pricing (aaif-goose#11264)
  feat(providers): add Gondola as declarative OpenAI-compatible provider (aaif-goose#11421)
  feat(otel): add request params, response metadata, tool call parity, and agent identification (aaif-goose#11261)
  fix(providers): coalesce consecutive Thinking blocks in collect_stream (aaif-goose#11317)
  feat(hooks): add PreToolUseResult event and stable tool_call_id across tool lifecycle (aaif-goose#11120)
  add MCP conformance tests to goose CI (combines aaif-goose#10800 + aaif-goose#10801) (aaif-goose#10940)
  feat(desktop): sort configured providers to the top of the provider list (aaif-goose#11409)
  fix(cli): refuse symlink diagnostics outputs (aaif-goose#11398)
  test(plugins): isolate GOOSE_PATH_ROOT in discovery tests (aaif-goose#11407)
  fix(config): serialize secret mutations (aaif-goose#11388)
  fix: decouple source file and tool response limits (aaif-goose#11391)
  chore(deps): bump pctx_code_mode from 0.4.1 to 0.5.0 (aaif-goose#11245)
  fix(security): suppress sensitive OTLP traces (aaif-goose#11381)
  feat(openrouter): forward session_id and add app category header (aaif-goose#10868)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants