Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Jan 14, 2026

Summary

Fix for the "Unable to submit request because it must include at least one parts field" error that occurs when using Gemini models via OpenRouter.

Root Cause

User messages containing empty text blocks ({ type: "text", text: "" }) were being passed through to the API without filtering. Gemini requires non-empty content in the 'parts' field.

Solution

Added filtering of empty text blocks in convertToOpenAiMessages() when processing user messages:

  • Empty text blocks ({ type: "text", text: "" }) are filtered out
  • Images are always preserved (they always have base64 content)
  • User messages are only created if there's at least one non-empty content block

Changes

  • src/api/transform/openai-format.ts - Added filtering logic
  • src/api/transform/__tests__/openai-format.spec.ts - Added 3 test cases

Testing

  • All 30 tests in openai-format.spec.ts pass
  • All 24 OpenRouter provider tests pass
  • Full test suite passes (5238 tests)

PostHog Issue

https://us.posthog.com/error_tracking/019bbc67-ebdc-7640-967c-df1c8f43172b

Linear Issue

ROO-528


Important

Filters out empty text blocks in convertToOpenAiMessages() to prevent errors with Gemini models, with new tests added.

  • Behavior:
    • Filters out empty text blocks in convertToOpenAiMessages() in openai-format.ts to prevent errors with Gemini models.
    • Preserves image blocks and only creates user messages if non-empty content exists.
  • Testing:
    • Added 3 test cases in openai-format.spec.ts to verify filtering logic.
    • All existing tests pass, ensuring no regressions.
  • Misc:
    • No changes to other files or functions.

This description was created by Ellipsis for 4928810. You can customize this summary. It will automatically update as commits are pushed.

…tibility

Gemini models via OpenRouter require non-empty content in the 'parts' field.
When user messages contain empty text blocks ({ type: 'text', text: '' }),
the API rejects the request with 'must include at least one parts field'.

This fix filters out empty text blocks when converting Anthropic messages
to OpenAI format, ensuring only valid content is sent to the API.

- Filter empty text blocks from user messages before creating OpenAI format
- Preserve images (they always have base64 content)
- Skip user message creation if all content blocks are empty
- Add 3 test cases for the new filtering behavior

Fixes: https://us.posthog.com/error_tracking/019bbc67-ebdc-7640-967c-df1c8f43172b
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners January 14, 2026 17:16
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jan 14, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 14, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly filters empty text blocks from user messages to prevent Gemini's "must include at least one parts field" error. The fix is well-scoped, properly tested, and does not break existing functionality.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

2 participants