Skip to content

fix(ai-gateway): emit finish_reason before [DONE] for Pi streaming#3616

Merged
louis030195 merged 1 commit into
screenpipe:mainfrom
Anshgrover23:fix/finish-test-reason
May 26, 2026
Merged

fix(ai-gateway): emit finish_reason before [DONE] for Pi streaming#3616
louis030195 merged 1 commit into
screenpipe:mainfrom
Anshgrover23:fix/finish-test-reason

Conversation

@Anshgrover23
Copy link
Copy Markdown
Contributor

Description:

fixes the gateway stream shape so Pi chat/pipes stop failing after auth succeeds.

  • before:
Screenshot 2026-05-26 133931

Fix: Pi expects an OpenAI-style terminal chunk with finish_reason before data: [DONE]; Anthropic and OpenAI adapters only sent content/usage, so clients threw Stream ended without finish_reason on Claude and GPT models.

Test passing:

image

Files changed:

  • packages/ai-gateway/src/providers/anthropic.ts — map stop_reason → OpenAI finish_reason; emit terminal chunk; add network_error on stream errors
  • packages/ai-gateway/src/providers/openai.ts — capture upstream finish_reason, emit terminal chunk before [DONE]; fix stream typing + ChatCompletionMessageParam
  • packages/ai-gateway/src/handlers/models.ts — remove duplicate curated gpt-5.5 / gpt-5.4 / gpt-5.4-mini entries
  • packages/ai-gateway/src/test/anthropic-proxy.unit.test.ts — streaming finish_reason + tool_calls tests
  • packages/ai-gateway/src/test/openai-models.unit.test.ts — streaming finish_reason test + TS fixes

@Anshgrover23
Copy link
Copy Markdown
Contributor Author

@louis030195 Can I get a review on this one ?

@louis030195 louis030195 merged commit 7d2fe7c into screenpipe:main May 26, 2026
4 of 8 checks passed
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.

2 participants