Skip to content

feat: Add rawResponse property to OrchestrationStreamResponse& getRequestId-helpers#1464

Merged
ZhongpinWang merged 11 commits intomainfrom
davidkna-sap_rawstream
Feb 16, 2026
Merged

feat: Add rawResponse property to OrchestrationStreamResponse& getRequestId-helpers#1464
ZhongpinWang merged 11 commits intomainfrom
davidkna-sap_rawstream

Conversation

@davidkna-sap
Copy link
Member

Context

Closes SAP/ai-sdk-js-backlog#457.

What this PR does and why it is needed

Copy link
Member Author

Choose a reason for hiding this comment

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

I called it rawHttpResponse instead of rawResponse to stress that it doesn't contain the actual data being streamed.

Choose a reason for hiding this comment

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

It breaks namespace consistency across the API.
The stream use case is orthogonal, so the collision is not a concern here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jerome-benoit Please clarify what you mean with "namespace consistency across the API" in this context. Would you prefer it being called rawResponse? Given the other review comments I will be renaming it to rawResponse.

Copy link

@jerome-benoit jerome-benoit Jan 26, 2026

Choose a reason for hiding this comment

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

@jerome-benoit Please clarify what you mean with "namespace consistency across the API" in this context. Would you prefer it being called rawResponse? Given the other review comments I will be renaming it to rawResponse.

Two different transport layers - slightly -, same overall semantic expected on both content => the namespace should match.

@davidkna-sap davidkna-sap marked this pull request as ready for review January 22, 2026 15:32
@davidkna-sap davidkna-sap marked this pull request as draft January 22, 2026 15:42
@davidkna-sap davidkna-sap changed the title feat: Add rawHttpResponse property to OrchestrationStreamResponse feat: Add rawHttpResponse property to OrchestrationStreamResponse& getRequestId-helpers Jan 22, 2026
@davidkna-sap
Copy link
Member Author

The initial streaming HTTP response does not actually contain a X-Request-ID, so I also additionally also added getRequestId()-helpers for the orchestration client response objects, which just read this._data.request_id.

@davidkna-sap davidkna-sap marked this pull request as ready for review January 22, 2026 16:28
Copy link
Member Author

Choose a reason for hiding this comment

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

This file did not have tests yet, the AI decided to generate a bunch for things that were not covered.
I kept these to increase overall code coverage, but I would be glad to remove additional tests unrelated to the primary PR objective to ease reviewing.

Copy link
Contributor

Choose a reason for hiding this comment

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

[pp] I prefer adding this test file in a separate PR. This file is a bit too much to be considered as a small improvement. But thanks for considering the test coverage and please do create a follow-up for this. 👍

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

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

The idea if I understand correctly, is just to expose the HttpResponse as part of the OrchestrationStreamResponse object. HttpResponse contains headers, status, data, and every other things that is returned and set by Axios. In case of streaming, data property contains a Node.js Readable object, which users can parse by themselves. (Need to check though if the stream is for sure not consumed by us if user does not iterate the async iterable causing the Readable object been consumed and SSE been parsed.)

Copy link
Contributor

@ZhongpinWang ZhongpinWang Jan 26, 2026

Choose a reason for hiding this comment

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

This HttpResponse contains data property, which is a Node.js Readable stream object set by Axios.

See how we are parsing the SSE.

SseStream.transformToSseStream<CompletionPostResponseStreaming>(

const iter = response.data;

The idea is to expose this HttpResponse object in OrchestrationStreamResponse so that users can parse the data SSE by themselves. And if they do parse by themselves, then OrchestrationStreamResponse cannot be used but then it is user's choice.

But please double check, if data is consumable. My understanding is that if user consumes the stream by running a for await loop, then the stream is not consumable any more. So please check if it is not consumed by a for await, then can the Readable object still be consumed directly from the raw response.

Copy link
Member Author

@davidkna-sap davidkna-sap Jan 26, 2026

Choose a reason for hiding this comment

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

I have confirmed data can be streamed, but decided against adding an e2e-test for this feature for now. Edit: I added a unit test for this.

),
new OrchestrationStreamResponse()
new OrchestrationStreamResponse({} as any)
);
Copy link
Contributor

@ZhongpinWang ZhongpinWang Jan 26, 2026

Choose a reason for hiding this comment

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

[pp/req] Unfortunately, we have exposed OrchestrationStreamResponse not just as a type. Adding an additional required property in the constructor is a breaking change. Please consider using setter later.

Or perhaps we accept this as a compatibility note. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did add a compatibility note.

I decided on doing it this way because it means that the new property does not have to be optional, and OrchestrationResponse also add the raw response via a constructor argument.
And while this is a breaking change at the type-level, it doesn't break anything at runtime.

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense. Would of course be nicer if we have exported this as a type only

export { OrchestrationStreamResponse } from './orchestration-stream-response.js';

Perhaps something you can consider doing, also for other response types.

Copy link
Member Author

@davidkna-sap davidkna-sap Jan 26, 2026

Choose a reason for hiding this comment

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

I've changed the code to handle this gracefully by deprecating the constructor without the OrchestrationResponse, and throwing if OrchestrationResponse is undefined when rawResponse is accessed.

Copy link
Contributor

Choose a reason for hiding this comment

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

[pp] I prefer adding this test file in a separate PR. This file is a bit too much to be considered as a small improvement. But thanks for considering the test coverage and please do create a follow-up for this. 👍

Copy link
Contributor

@ZhongpinWang ZhongpinWang Jan 26, 2026

Choose a reason for hiding this comment

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

Also please call this property rawResponse same as in the non-streaming response. (I see that we have some inconsistency between embedding and chat client... embedding response calls this response instead of rawResponse... But let's be at least consistent within one client.)

Copy link
Contributor

@ZhongpinWang ZhongpinWang Jan 26, 2026

Choose a reason for hiding this comment

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

[pp] If you want, consider deprecate response in embedding client and rename it to rawResponse and check docs. Cosmetic stuff cc @KavithaSiva WDYT?

@davidkna-sap davidkna-sap changed the title feat: Add rawHttpResponse property to OrchestrationStreamResponse& getRequestId-helpers feat: Add rawResponse property to OrchestrationStreamResponse& getRequestId-helpers Jan 26, 2026
Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

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

The pull request adds rawResponse property and getRequestId() helpers to orchestration response classes. I identified three related issues around type consistency and defensive programming for the getRequestId() implementations. The streaming version returns string | undefined while the non-streaming versions return string, but all read from the same field that could theoretically be missing until data is received. This inconsistency should be addressed to prevent potential runtime errors.

PR Bot Information

Version: 1.17.50 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Correlation ID: fbca84c0-01c3-11f1-911c-0616ae270023
  • Event Trigger: issue_comment.created
  • LLM: anthropic--claude-4.5-sonnet

@hyperspace-insights hyperspace-insights bot deleted a comment from davidkna-sap Feb 4, 2026
Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

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

lgtm

Co-authored-by: Zhongpin Wang <zhongpin.wang@sap.com>
Co-authored-by: Zhongpin Wang <zhongpin.wang@sap.com>
@ZhongpinWang ZhongpinWang merged commit 6b49479 into main Feb 16, 2026
11 checks passed
@ZhongpinWang ZhongpinWang deleted the davidkna-sap_rawstream branch February 16, 2026 08:09
davidkna-sap added a commit that referenced this pull request Feb 16, 2026
…-streaming

* origin/main:
  feat: Support orchestration prompt module fallback (#1454)
  v2.7.0
  chore: Fix pnpm-lockfile refresh merge condition handling (#1497)
  feat: Add `rawResponse` property to `OrchestrationStreamResponse`& `getRequestId`-helpers (#1464)
  chore: Combine ai client type headers (#1545)
  chore(deps-dev): Bump @sap/cds-dk from 9.7.1 to 9.7.2 (#1548)
  chore: update pnpm transitive dependencies (#1544)
davidkna-sap added a commit that referenced this pull request Feb 16, 2026
…uet-cloud-sdk

* origin/main: (38 commits)
  feat: Support orchestration prompt module fallback (#1454)
  v2.7.0
  chore: Fix pnpm-lockfile refresh merge condition handling (#1497)
  feat: Add `rawResponse` property to `OrchestrationStreamResponse`& `getRequestId`-helpers (#1464)
  chore: Combine ai client type headers (#1545)
  chore(deps-dev): Bump @sap/cds-dk from 9.7.1 to 9.7.2 (#1548)
  chore: update pnpm transitive dependencies (#1544)
  chore(deps-dev): Bump glob from 13.0.2 to 13.0.3 (#1541)
  chore(deps-dev): Bump dotenv from 17.2.4 to 17.3.1 (#1540)
  chore(deps): Bump the langchain group with 3 updates (#1538)
  feat: Update ai-api specification (#1489)
  feat: Advertise AbortSignal support for HTTP request cancellation (#1480)
  chore(deps-dev): Bump orval from 8.2.0 to 8.3.0 (#1536)
  chore(deps): Bump the langchain group with 3 updates (#1535)
  feat: Added support for custom headers in document grounding and open ai clients (#1519)
  chore: Fix rpt (#1533)
  chore(deps-dev): Bump @types/node from 22.19.10 to 22.19.11 (#1532)
  chore(deps-dev): Bump glob from 13.0.1 to 13.0.2 (#1530)
  chore(deps-dev): Bump nock from 14.0.10 to 14.0.11 (#1529)
  chore(deps): Bump the langchain group with 3 updates (#1528)
  ...
davidkna-sap added a commit that referenced this pull request Feb 17, 2026
* origin/main: (39 commits)
  chore: Improve test coverage on `OrchestrationStreamResponse` (#1478)
  feat: Support orchestration prompt module fallback (#1454)
  v2.7.0
  chore: Fix pnpm-lockfile refresh merge condition handling (#1497)
  feat: Add `rawResponse` property to `OrchestrationStreamResponse`& `getRequestId`-helpers (#1464)
  chore: Combine ai client type headers (#1545)
  chore(deps-dev): Bump @sap/cds-dk from 9.7.1 to 9.7.2 (#1548)
  chore: update pnpm transitive dependencies (#1544)
  chore(deps-dev): Bump glob from 13.0.2 to 13.0.3 (#1541)
  chore(deps-dev): Bump dotenv from 17.2.4 to 17.3.1 (#1540)
  chore(deps): Bump the langchain group with 3 updates (#1538)
  feat: Update ai-api specification (#1489)
  feat: Advertise AbortSignal support for HTTP request cancellation (#1480)
  chore(deps-dev): Bump orval from 8.2.0 to 8.3.0 (#1536)
  chore(deps): Bump the langchain group with 3 updates (#1535)
  feat: Added support for custom headers in document grounding and open ai clients (#1519)
  chore: Fix rpt (#1533)
  chore(deps-dev): Bump @types/node from 22.19.10 to 22.19.11 (#1532)
  chore(deps-dev): Bump glob from 13.0.1 to 13.0.2 (#1530)
  chore(deps-dev): Bump nock from 14.0.10 to 14.0.11 (#1529)
  ...
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.

4 participants

Comments