Skip to content

feat: add response headers to message metadata#511

Merged
cotovanu-cristian merged 2 commits intomainfrom
feat/header-traces
Feb 4, 2026
Merged

feat: add response headers to message metadata#511
cotovanu-cristian merged 2 commits intomainfrom
feat/header-traces

Conversation

@andreiancuta-uipath
Copy link
Contributor

@andreiancuta-uipath andreiancuta-uipath commented Feb 3, 2026

In the on_llm_end callback, we need to read response headers from LLM Gateway and add them to the usage span attribute.

To access the headers, they must be added to the AIMessage's response_metadata dict.

  • ChatBedrockConverse and AzureChatOpenAi already store the response headers in this dict, either by default or when a flag is enabled.
  • ChatGenerativeGoogleAi and ChatBedrock do not. This PR adds a HeaderCapture utility that can store a header value in a context var and apply it to a ChatResult's message response_metadata.
    • Headers are captured at the transport layer, and applied in the chat class's generate/stream method.

Tested with all providers.

@andreiancuta-uipath andreiancuta-uipath changed the title feat: add response headers in trace attributes feat: add response headers to message metadata Feb 3, 2026
@cotovanu-cristian cotovanu-cristian enabled auto-merge (squash) February 4, 2026 20:03
@cotovanu-cristian cotovanu-cristian merged commit a48b8d6 into main Feb 4, 2026
39 checks passed
@cotovanu-cristian cotovanu-cristian deleted the feat/header-traces branch February 4, 2026 20:04
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.

2 participants