Hmbown/CodeWhale · error · anyhow::Error

translate: Anthropic Messages response did not contain text…

Error message

translate: Anthropic Messages response did not contain text content

What it means

When translating text through an Anthropic Messages-format endpoint, the client joins all text content blocks of the response and requires non-empty text. If the response contained no text content (or only whitespace after trimming), it bails rather than returning an empty translation.

Solutions

  1. Retry the translation request; transient model/refusal responses often succeed on retry.
  2. Inspect the raw response (enable logging) to see what content blocks were returned; switch to a model that returns plain text for translation.
  3. If a proxy is in front of the provider, verify it forwards the Messages response unmodified.
  4. Check provider status/quota — degraded endpoints may return empty content.
Defensive patterns

Strategy: try-catch

Try / catch

match translate_result {
    Err(e) if e.to_string().contains("did not contain text content") => {
        log::warn!("Anthropic returned no text blocks; retrying once");
        translate_result = translate(input).await;
    }
    r => r?,
}

Prevention

When it happens

Trigger: The Anthropic Messages response contains only non-text blocks (e.g. tool_use), or an empty/whitespace-only text array — typically caused by an unexpected model reply or a degraded/proxy endpoint.

Common situations: Hitting a proxy/gateway that returns a mangled Messages payload; a model that replies with tool calls instead of text; quota/refusal responses shaped as non-text blocks.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/add467740d450b74. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/client.rs:2371

        temperature: None,
        top_p: None,
    }
}

fn translation_text_from_response(response: &MessageResponse) -> Result<String> {
    let translated = response
        .content
        .iter()
        .filter_map(|block| match block {
            ContentBlock::Text { text, .. } => Some(text.as_str()),
            _ => None,
        })
        .collect::<Vec<_>>()
        .join("")
        .trim()
        .to_string();
    if translated.is_empty() {
        bail!("translate: Anthropic Messages response did not contain text content");
    }
    Ok(translated)
}

fn xiaomi_mimo_base_url_uses_token_plan(base_url: &str) -> bool {
    let normalized = base_url.trim().to_ascii_lowercase();
    let without_scheme = normalized
        .strip_prefix("https://")
        .or_else(|| normalized.strip_prefix("http://"))
        .unwrap_or(&normalized);
    let host = without_scheme
        .split(['/', '?', '#'])
        .next()
        .unwrap_or_default();
    let host = host.split(':').next().unwrap_or(host);
    host.starts_with("token-plan-") && host.ends_with(".xiaomimimo.com")
}

View on GitHub (pinned to 73e0f67d83)