Whitespace content causes API validation errors in provider transformations #6486

Open
opened 2026-02-16 18:04:22 -05:00 by yindo · 1 comment
Owner

Originally created by @jerome-benoit on GitHub (Jan 16, 2026).

Originally assigned to: @thdxr on GitHub.

Problem

Provider APIs (Anthropic, OpenAI) reject requests containing empty or whitespace-only text content, causing validation failures during message transformation.

Current Behavior:

  • Untrimmed whitespace in message content passes through transformation functions
  • Empty strings after whitespace removal are sent to provider APIs
  • APIs respond with validation errors rejecting empty content blocks

Root Cause:
No consistent whitespace trimming or empty content filtering across provider transformation functions (anthropic.ts, openai.ts, openai-compatible.ts, transform.ts).

Impact

  • User messages with accidental whitespace cause request failures
  • Poor UX when legitimate content is rejected due to formatting
  • Inconsistent behavior across different providers

Proposed Solution

Implement consistent whitespace trimming pattern across all transformations:

const t = content.trim()
if (t.length > 0) {
  parts.push({ type: "text", text: t })
}

Scope:

  • Apply trimming to all text content before API submission
  • Filter empty/whitespace-only messages and parts
  • Preserve tool results and streaming deltas unchanged
  • Add comprehensive test coverage
Originally created by @jerome-benoit on GitHub (Jan 16, 2026). Originally assigned to: @thdxr on GitHub. ## Problem Provider APIs (Anthropic, OpenAI) reject requests containing empty or whitespace-only text content, causing validation failures during message transformation. **Current Behavior:** - Untrimmed whitespace in message content passes through transformation functions - Empty strings after whitespace removal are sent to provider APIs - APIs respond with validation errors rejecting empty content blocks **Root Cause:** No consistent whitespace trimming or empty content filtering across provider transformation functions (`anthropic.ts`, `openai.ts`, `openai-compatible.ts`, `transform.ts`). ## Impact - User messages with accidental whitespace cause request failures - Poor UX when legitimate content is rejected due to formatting - Inconsistent behavior across different providers ## Proposed Solution Implement consistent whitespace trimming pattern across all transformations: ```typescript const t = content.trim() if (t.length > 0) { parts.push({ type: "text", text: t }) } ``` **Scope:** - Apply trimming to all text content before API submission - Filter empty/whitespace-only messages and parts - Preserve tool results and streaming deltas unchanged - Add comprehensive test coverage
Author
Owner

@github-actions[bot] commented on GitHub (Jan 16, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8679: TUI can auto-submit whitespace prompt, creating "empty user message" and breaking Claude/OpenAI-compatible proxies
  • #7493: when (mistakely) sending empty message the session stop with the error: text cannot be empty
  • #6446: Empty message content causes Anthropic API errors during compaction (CLOSED)
  • #5028: Call Missing content in messages: text content blocks must be non-empty (CLOSED)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 16, 2026): This issue might be a duplicate of existing issues. Please check: - #8679: TUI can auto-submit whitespace prompt, creating "empty user message" and breaking Claude/OpenAI-compatible proxies - #7493: when (mistakely) sending empty message the session stop with the error: text cannot be empty - #6446: Empty message content causes Anthropic API errors during compaction (CLOSED) - #5028: Call Missing content in messages: text content blocks must be non-empty (CLOSED) Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6486