Skip to content

feat: expose request_id on ImageResponse - #185

Closed
aheze wants to merge 1 commit into
xai-org:mainfrom
aheze:azheng/image-request-id
Closed

feat: expose request_id on ImageResponse#185
aheze wants to merge 1 commit into
xai-org:mainfrom
aheze:azheng/image-request-id

Conversation

@aheze

@aheze aheze commented Jul 25, 2026

Copy link
Copy Markdown

Summary

  • ImageResponse (sync and aio) now exposes a request_id property, populated from the x-request-id header on the gRPC response's initial metadata of image.sample() / image.sample_batch(). Returns None if the header is absent.
  • This is the id xAI can look up in server logs, so API customers can include it when reporting a failed or moderated generation. Today the SDK discards the gRPC call object, so the header is dropped and customers have no way to reference their request.
  • Sync uses GenerateImage.with_call(...), aio awaits call.initial_metadata(); a shared _extract_request_id helper in image.py handles both metadata formats.

Test plan

  • Test gRPC server now sends x-request-id initial metadata on GenerateImage; new sync + aio tests assert response.request_id round-trips for sample and sample_batch, plus a default-None unit test.
  • Full suite: 769 passed. ruff check, ruff format --check, and pyright clean on changed files.

Made with Cursor

Capture the x-request-id from the gRPC response initial metadata in
image.sample() / image.sample_batch() (sync and aio) and expose it as
ImageResponse.request_id, so callers can reference the server-side
request in bug reports. Mirrors the request-id extraction the chat
client uses internally.

Co-authored-by: Cursor <cursoragent@cursor.com>
@aheze
aheze requested a review from a team as a code owner July 25, 2026 16:56
@aheze aheze closed this Jul 27, 2026
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.

1 participant