Skip to content

Gemini API error: empty text content causes 'required oneof field data must have one initialized field' #1293

@Darley-Wey

Description

@Darley-Wey

Description

When a Claude API request contains an assistant message with empty text content, the Antigravity/Gemini translator produces an invalid request that causes the Gemini API to return a 400 error.

Error Message

{
  "error": {
    "code": 400,
    "message": "* GenerateContentRequest.contents[1].parts[0].data: required oneof field 'data' must have one initialized field",
    "status": "INVALID_ARGUMENT"
  }
}

Reproduction

Send a Claude API request with an assistant message containing empty text:

{
  "messages": [
    {"role": "user", "content": [{"type": "text", "text": "你好"}]},
    {"role": "assistant", "content": [{"type": "text", "text": ""}]},
    {"role": "user", "content": [{"type": "text", "text": "..."}]}
  ]
}

Root Cause

In internal/translator/antigravity/claude/antigravity_claude_request.go, when processing text content, if the text is empty, a part object {} is still created and added to the parts array. The Gemini API requires every part to have at least one data field initialized.

Expected Behavior

Empty text parts should be skipped during translation to avoid sending invalid requests to the Gemini API.

Environment

  • Route: /api/provider/anthropic/v1/messages
  • Backend: Antigravity (Gemini)
  • Version: v6.7.26-0-plus

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions