Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-deduplicate-openai-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/ai-openai": patch
---

fix(ai-openai): deduplicate response.output items to prevent invalid JSON concatenation
9 changes: 9 additions & 0 deletions packages/ai/openai/src/OpenAiLanguageModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,16 @@ const makeResponse: (
timestamp: DateTime.formatIso(DateTime.unsafeFromDate(createdAt))
})

// Deduplicate output items by ID to handle OpenAI Responses API bug
// where duplicate OutputMessage items appear in response.output
const seenOutputIds = new Set<string>()
for (const part of response.output) {
if (part.id && seenOutputIds.has(part.id)) {
continue
}
if (part.id) {
seenOutputIds.add(part.id)
}
switch (part.type) {
case "message": {
for (const contentPart of part.content) {
Expand Down
Loading