Skip to content

Commit 1cb09a5

Browse files
fix(openai): don't send reasoning summaries or other output IDs when ZDR is enabled
1 parent 378d476 commit 1cb09a5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

libs/langchain-openai/src/chat_models.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,11 @@ function _convertMessagesToOpenAIResponsesParams(
510510
if (role === "assistant") {
511511
// if we have the original response items, just reuse them
512512
if (
513+
!zdrEnabled &&
513514
lcMsg.response_metadata.output != null &&
514515
Array.isArray(lcMsg.response_metadata.output) &&
515516
lcMsg.response_metadata.output.length > 0 &&
516-
lcMsg.response_metadata.output.every(
517-
(item) => "type" in item && "id" in item
518-
)
517+
lcMsg.response_metadata.output.every((item) => "type" in item)
519518
) {
520519
return lcMsg.response_metadata.output;
521520
}
@@ -525,7 +524,7 @@ function _convertMessagesToOpenAIResponsesParams(
525524
const input: ResponsesInputItem[] = [];
526525

527526
// reasoning items
528-
if (lcMsg.additional_kwargs.reasoning != null) {
527+
if (!zdrEnabled && lcMsg.additional_kwargs.reasoning != null) {
529528
type FindType<T, TType extends string> = T extends { type: TType }
530529
? T
531530
: never;
@@ -561,7 +560,7 @@ function _convertMessagesToOpenAIResponsesParams(
561560
input.push({
562561
type: "message",
563562
role: "assistant",
564-
...(lcMsg.id ? { id: lcMsg.id } : {}),
563+
...(lcMsg.id && !zdrEnabled ? { id: lcMsg.id } : {}),
565564
content:
566565
typeof content === "string"
567566
? content
@@ -598,7 +597,7 @@ function _convertMessagesToOpenAIResponsesParams(
598597
name: toolCall.name,
599598
arguments: JSON.stringify(toolCall.args),
600599
call_id: toolCall.id!,
601-
id: functionCallIds?.[toolCall.id!],
600+
...(zdrEnabled ? { id: functionCallIds?.[toolCall.id!] } : {}),
602601
})
603602
)
604603
);
@@ -609,7 +608,7 @@ function _convertMessagesToOpenAIResponsesParams(
609608
type: "function_call",
610609
name: toolCall.function.name,
611610
call_id: toolCall.id,
612-
id: functionCallIds?.[toolCall.id],
611+
...(zdrEnabled ? { id: functionCallIds?.[toolCall.id] } : {}),
613612
arguments: toolCall.function.arguments,
614613
})
615614
)
@@ -1863,7 +1862,14 @@ export class ChatOpenAI<
18631862
useResponsesApi = false;
18641863

18651864
/**
1866-
* Should be set to `true` in tenancies with Zero Data Retention
1865+
* Must be set to `true` in tenancies with Zero Data Retention. Setting to `true` will disable
1866+
* output storage in the Responses API, but this DOES NOT enable Zero Data Retention in your
1867+
* OpenAI organization or project. This must be configured directly with OpenAI.
1868+
*
1869+
* See:
1870+
* https://help.openai.com/en/articles/10503543-data-residency-for-the-openai-api
1871+
* https://platform.openai.com/docs/api-reference/responses/create#responses-create-store
1872+
*
18671873
* @default false
18681874
*/
18691875
zdrEnabled?: boolean | undefined;
@@ -2110,6 +2116,7 @@ export class ChatOpenAI<
21102116
})(),
21112117
parallel_tool_calls: options?.parallel_tool_calls,
21122118
max_output_tokens: this.maxTokens === -1 ? undefined : this.maxTokens,
2119+
...(this.zdrEnabled ? { store: false } : {}),
21132120
...this.modelKwargs,
21142121
};
21152122

0 commit comments

Comments
 (0)