Skip to content

Anthropic Error Responses Can Cause NPE In StreamHelper #3740

@adase11

Description

@adase11

Bug description
When Anthropic's API returns an error the models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/api/StreamHelper.java eventToChatCompletionResponse method can throw a NPE because contentBlockReference contains a null reference.

Environment
Java 21
Spring AI 1.0.0 (using the bom for dependency management) specifically in spring-ai-starter-model-anthropic

Steps to reproduce
Hard to reproduce - best I could do is force lots of requests to anthropic and wait for the ErrorEvent[type=ERROR, error=Error[type=overloaded_error, message=Overloaded]]

Here's a screenshot from a breakpoint that I used to find the error:
Image

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions