Skip to content

Conversation

@andreiborza
Copy link
Member

The issue surfaced when message.stream was used in conjunction with the stream: true option which would lead to us returning async results instead of the expected MessageStream from anthropic ai.

We now take this into account and tightened the types.

Closes: #17977

…m api

The issue surfaced when `message.stream` was used in conjunction with the
`stream: true` option which would lead to us returning async results instead of
the expected MessageStream from anthropic ai.

We now take this into account and tightened the types.

Closes: #17977
@cursor
Copy link

cursor bot commented Oct 23, 2025

Bug: Stream Method Returns Promise Instead

The synchronous messages.stream() method incorrectly falls into the else branch of handleStreamingRequest. This path wraps it with startSpanManual, which returns a Promise, causing messages.stream() to return a Promise instead of a synchronous MessageStream and breaking its API contract.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,950 - 8,670 +3%
GET With Sentry 1,331 15% 1,343 -1%
GET With Sentry (error only) 5,933 66% 6,020 -1%
POST Baseline 1,184 - 1,173 +1%
POST With Sentry 512 43% 499 +3%
POST With Sentry (error only) 1,050 89% 1,047 +0%
MYSQL Baseline 3,303 - 3,280 +1%
MYSQL With Sentry 479 15% 425 +13%
MYSQL With Sentry (error only) 2,711 82% 2,670 +2%

View base workflow run

}

// Mimics Anthropic SDK's MessageStream class
class MockMessageStream {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we actually use the MessageStream class since this is an integration test anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't export that :(

@andreiborza andreiborza merged commit 7d050b5 into develop Oct 23, 2025
190 of 193 checks passed
@andreiborza andreiborza deleted the ab/fix-anthropic-types branch October 23, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

anthropicAIIntegration() breaks Anthropic's streaming API when running TypeScript via ts-node

2 participants