Python: fix(python): preserve CostControl budget failures in hosted Responses - #8488
banibrata-de wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 99113cf0-df56-4e0f-979a-a7d39a173e4d
There was a problem hiding this comment.
Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.
There was a problem hiding this comment.
Could we preserve headers from the wrapped raw response before entering _open_event_stream? With Azure GenAI tracing enabled, raw_create_response is an AsyncStreamWrapper with no headers; the headers remain on its stream_async_iter, so _chat_client.py:940 records None and a later budget SSE error is still wrapped without x-ms-budget-cause. The hosted adapter then emits server_error instead of budget_exceeded. Could header extraction inspect the same inner raw response that _open_event_stream unwraps, and apply that to the retrieve path at _chat_client.py:880 too?
Motivation & Context
Foundry-hosted Responses agents currently lose CostControl budget classification when a streaming model response ends with an error event. The raw response headers identify
budget_exceeded, but the OpenAI SDK raises a generic streamAPIError, and the hosting adapter emitsresponse.failedwithserver_error.Description & Review Guide
response.failed.error.codeasbudget_exceeded.response.metadata.costControl.server_errorbehavior.Related Issue
Fixes #8487
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.