元渊 API元渊 API
Error Handling GuideError Scenarios

Scenario 3: Text Response Error

Handling text-only responses

Scenario

API returns text explanation instead of image data.

Response Example

{
  "candidates": [{
    "content": {
      "parts": [{ "text": "I can't generate images that..." }]
    },
    "finishReason": "STOP"
  }],
  "usageMetadata": { "candidatesTokenCount": 150 }
}

Key Features

  • candidatesTokenCount > 0
  • finishReason: "STOP"
  • ✅ Has text, no inlineData

Detection

function detectTextResponse(data) {
    const parts = data.candidates?.[0]?.content?.parts || [];
    const hasImage = parts.some(p => p.inlineData?.data);
    const hasText = parts.some(p => p.text);
    
    if (!hasImage && hasText) {
        return {
            isTextResponse: true,
            text: parts[0].text
        };
    }
    return { isTextResponse: false };
}

Rejection Types

  • Watermark removal
  • Face swap
  • NSFW content
  • Copyright violations

User Message

💬 Unable to Generate Image

The model provided an explanation:
[Display model's text]

Suggestions:
✓ Adjust your request based on feedback
✓ Try different phrasing

How is this guide?