openclaw - 💡(How to fix) Fix Bug: pi-ai Anthropic provider crashes on malformed responses (anthropic.js:590) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#63089Fetched 2026-04-09 07:58:43
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants
RAW_BUFFERClick to expand / collapse

The crash is an upstream bug in @mariozechner/pi-ai’s Anthropic provider at pi-ai/dist/providers/anthropic.js:590. It calls b.text.trim() without checking if b.text exists.

For comparison, this is properly guarded in pi-ai/dist/providers/openai-completions.js (lines 477/489) as (b.text && b.text.trim()).

When openrouter/auto routes to an Anthropic model, it hits this code path and crashes on malformed responses, causing OpenClaw to fail the validation.

extent analysis

TL;DR

Adding a null check for b.text before calling trim() on it is likely to fix the crash in the Anthropic provider.

Guidance

  • The crash occurs because b.text is not checked for existence before calling trim() on it, similar to how it's properly handled in openai-completions.js.
  • To verify the fix, test the Anthropic provider with malformed responses that cause b.text to be null or undefined.
  • The code change should be applied to pi-ai/dist/providers/anthropic.js at line 590, adding a null check similar to (b.text && b.text.trim()).
  • Consider adding additional error handling or logging to handle cases where b.text is null or undefined.

Example

// Before
const trimmedText = b.text.trim();

// After
const trimmedText = b.text && b.text.trim();

Notes

This fix assumes that the intention is to skip trimming if b.text is null or undefined. If b.text is expected to always be present, additional error handling may be necessary.

Recommendation

Apply the workaround by adding a null check for b.text before calling trim(), as this directly addresses the identified issue and prevents the crash.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING