Skip to content

Expose x-request-id in SSE streaming responses for Java SDK聽#593

Open

Description

@lxyyukiko0206-cloud

Description

We need access to the x-request-id header to debug API requests with the OpenAI team, as described in the official docs:
馃憠 https://platform.openai.com/docs/api-reference/debugging-requests

Although x-request-id can be obtained when using:

OpenAIClientAsync.withRawResponse()

We are using SSE streaming in our project, below is example code:

OpenAIClientAsync currentClient = OpenAIOkHttpClientAsync.builder().build();

currentClient.responses().createStreaming(params)
    .subscribe(event -> {
        // business logic
    })
    .onCompleteFuture()
    .thenAccept(result -> {
        // handle completion
    })
    .exceptionally(ex -> {
        // handle error
        return null;
    });

Feature request

Please provide a way to access the x-request-id header in SSE streaming responses (e.g., via callback, metadata, or event property).
This would make debugging and support much easier without requiring a full switch to withRawResponse().

Activity

  1. bhawnapannu2701 commented on Sep 3, 2025

    @bhawnapannu2701

    Hi! I鈥檇 like to pick this up.

    Plan: capture the initial OkHttp Response during SSE start, expose x-request-id via a new optional accessor on the stream/event surface, and add MockWebServer tests (header present/absent). This will be an additive, non-breaking change.

    If this scope/layer is acceptable, I鈥檒l open a PR with tests and docs.

  2. TomerAberbach commented on Sep 3, 2025

    @TomerAberbach
    Contributor

    I think you won't want to start at the OkHttp layer. We expose the method for this here so you should be able to grab it from that.

    I think it'd probably make sense to include the requestId method on the StreamResponse and AsyncStreamResponse interfaces (the event object seems wrong because the request ID is associated with the response, not each event)

    So then people could do this:

    OpenAIClientAsync currentClient = OpenAIOkHttpClientAsync.builder().build();
    
    AsyncStreamResponse<...> response = currentClient.responses().createStreaming(params);
    response
        .subscribe(event -> {
    		// use response.requestId()
        })
        .onCompleteFuture()
        .thenAccept(result -> {
    		// use response.requestId()
        })
        .exceptionally(ex -> {
    		// use response.requestId()
            return null;
        });

    If that all sounds good, then feel free to work on!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions