feat(session): expose LLM response headers on assistant messages#26090
feat(session): expose LLM response headers on assistant messages#26090jtbnz wants to merge 5 commits into
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Update: rebased and restructured to follow the LLMEvent pipelineAfter reviewing the codebase architecture, the original approach of reading What changed:
Verified: |
Adds an optional responseHeaders field to the Assistant message schema and populates it from the HTTP response headers captured on each finish-step event. This lets plugins (e.g. a LiteLLM auto-router) read headers such as x-litellm-model-api-base to identify which model was actually selected behind the proxy. Headers flow through the shared LLMEvent pipeline (StepFinish schema -> ai-sdk adapter -> processor) following the same pattern as providerMetadata. The field is optional so existing messages and providers are unaffected.
da31490 to
6352455
Compare
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
|
Please reopen, as I am still waiting on this functionality to expose model selected when using an auto router model. as model costs increase it is more important for me to make sure the right model is selected for each task. I have kept this uptodate with the dev branch. |
Issue for this PR
Closes #26091
Type of change
What does this PR do?
When using a LiteLLM proxy with an auto router, the actual model selected is only in the HTTP response headers (
x-litellm-model-api-base,llm_provider-x-ms-deployment-name). The AI SDK captures these onfinish-stepevents viavalue.response.headers, butprocessor.tsdiscards them.This adds an optional
responseHeadersfield to theAssistantmessage schema and capturesvalue.response.headersin thefinish-stephandler. The pattern already exists forAPIErrorin the same file.Two files changed:
packages/opencode/src/session/message-v2.ts— addedresponseHeaders: Schema.optional(Schema.Record(Schema.String, Schema.String))packages/opencode/src/session/processor.ts— readvalue.response.headerswhen non-empty and store on the assistant messageThe field is optional and messages are stored as JSON, so no migration is needed and existing messages are unaffected. Providers that don't return headers simply won't have the field set.
Example plugin using this: opencode-routed-model
How did you verify your code works?
bun turbo typecheck— all 12 packages passbun test test/session/frompackages/opencode— 296 pass, 0 failx-litellm-model-api-baseandllm_provider-x-ms-deployment-nameheaders appear on the assistant message and are visible to plugins viamessage.updatedbus eventsScreenshots / recordings
Not a UI change.
Checklist