Skip to content
Source
Sign inSign up
TanStack/ai

fix(openai-base): finish a Responses max_output_tokens cutoff with finishReason length instead of RUN_ERROR #1929

Mergedpcbeingused33(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/1929/headmerged by AlemTuzlak View on GitHub

Showing 7 changed files with 83 additions and 36 deletions (loading 3).

x
0 of 7 viewed, 7 left
7 additions and 0 deletions.changeset/responses-incomplete-finish-reason.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/openai-base': patch
+---
+​
+A Responses stream that ends with `response.incomplete` because of `max_output_tokens` or `content_filter` now finishes with `RUN_FINISHED` carrying the response's usage and `finishReason` `'length'` or `'content_filter'`, like the Chat Completions adapter, instead of `RUN_ERROR`. `response.failed` and an incomplete response with another or no reason still end in `RUN_ERROR`.
+​
+The stream also emits partial assistant text that OpenAI sends only in the terminal response.
5 additions and 0 deletionsdocs/adapters/openai.mdModified
View file
@@ -127,6 +127,11 @@
​
You now have a streaming GPT chat. [Tools](../tools/tools) and [Structured Outputs](../structured-outputs/overview) work the same as with every adapter.
​
+If an OpenAI Responses stream reaches its output token limit, the final
+`RUN_FINISHED` event reports `finishReason: 'length'`. If OpenAI stops the
+stream for content filtering, it reports `finishReason: 'content_filter'`.
+Both cases preserve partial text and include token usage when OpenAI supplies it.
+​
## Images
​
```typescript
71 additions and 36 deletionspackages/openai-base/src/adapters/responses-text.tsModified
View file
@@ -62,6 +62,7 @@
ResponseFunctionWebSearch,
ResponseInput,
ResponseInputContent,