Skip to content

fix: expose OpenAI Realtime request IDs - #6917

Closed
chenghao-mou wants to merge 1 commit into
mainfrom
chenghao/fix/AGT-3314-expose-openai-request-ids
Closed

fix: expose OpenAI Realtime request IDs#6917
chenghao-mou wants to merge 1 commit into
mainfrom
chenghao/fix/AGT-3314-expose-openai-request-ids

Conversation

@chenghao-mou

Copy link
Copy Markdown
Member

OpenAI support needs connection-level request IDs to diagnose Realtime failures. Capture the server x-request-id, send a unique X-Client-Request-Id, and expose both through structured logs, realtime error events, assistant metrics, and agent_turn spans.

Retry logs retain the applicable connection IDs.

Addresses AGT-3314

Initial prompt and agent context

Model: GPT-5.6

The customer is experiencing network issues between OpenAI and ICE servers, resulting in disconnected peer connections, and is asking if the LiveKit agent will attempt to reconnect to OpenAI, if LiveKit surfaces failure events from OpenAI, and if the request ID from OpenAI is logged somewhere. The customer is also inquiring about how to alert on such failure logs and where to find the logs in the LiveKit dashboard, specifically looking for logs related to OpenAI request IDs, reattempts, and network failures.

https://linear.app/livekit/issue/AGT-3314/openai-x-request-id-not-exposed-in-otel-traces-for-realtime-model

can you create a PR?

@chenghao-mou
chenghao-mou requested a review from a team as a code owner August 19, 2026 17:37

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

# aiohttp does not expose WebSocket upgrade headers publicly.
response = getattr(ws, "_response", None)
if response is not None:
self._openai_request_id = response.headers.get("x-request-id")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems x-request-id is not existed in the response during my testing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The doc https://developers.openai.com/api/reference/overview#debugging-requests only mentions this as a HTTP response header, and it doesn't seem to support websocket/realtime endpoints. I will close the PR instead.

"""

_openai_request_id: str | None = None
_openai_client_request_id: str | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicates with that in __init__?

else:
headers["Authorization"] = f"Bearer {self._opts.api_key}"
self._openai_client_request_id = str(uuid.uuid4())
headers["X-Client-Request-Id"] = self._openai_client_request_id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: does xAI support this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. they have an undocumented x-trace-id instead.

Comment on lines +3833 to +3838
provider_request_ids: list[str] = []
if generation_ev.response_id:
provider_request_ids.append(generation_ev.response_id)
for request_id in generation_ev.provider_request_ids:
if request_id and request_id not in provider_request_ids:
provider_request_ids.append(request_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe just use list(dict.fromkeys(filter(None, [generation_ev.response_id, *generation_ev.provider_request_ids])))

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