-
Notifications
You must be signed in to change notification settings - Fork 185
Description
web_fetch fails for some links
Summary
The web_fetch tool fails silently when fetching large PDFs (400KB+), providing no error codes, error events, or failure indication. The stream simply ends prematurely, leaving the SDK to throw a generic exception. This makes it impossible to handle errors gracefully or provide meaningful feedback to users.
Reproduction
Full reproduction with comparative test: https://gist.github.com/svashish305/eb008ad3112f4e71575a4977d2a0f057
Quick Test Results
✅ Small PDF (1-2 KB): Works perfectly
- Tool result received
- All events fire normally
❌ Large PDF (400 KB): Fails silently
web_fetch_tool_error: ❌ NOstream_errorevent: ❌ NOabortevent: ❌ NO- SDK throws: "stream ended without producing a Message with role=assistant"
One-Minute Reproduction
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
// Fails silently - no error code!
const largePDF = 'https://absl.net/wp-content/uploads/2025/09/Business-Services-Industry-in-Europe-2025-Report.pdf';
let toolErrorReceived = false;
const stream = client.beta.messages.stream({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 2048,
messages: [{ role: 'user', content: Analyze: ${largePDF} }],
tools: [{ type: 'web_fetch_20250910', name: 'web_fetch' }],
betas: ['web-fetch-2025-09-10'],
});
stream.on('streamEvent', (event) => {
if (event.content_block?.type === 'web_fetch_tool_error') {
toolErrorReceived = true; // Never happens!
}
});
try {
await stream.finalMessage();
} catch (error) {
console.log(error.message); // "stream ended without producing a Message"
console.log('API sent error code:', toolErrorReceived); // false
}## Environment
- SDK:
@anthropic-ai/[email protected] - Model:
claude-sonnet-4-5-20250929 - Beta:
web-fetch-2025-09-10 - Node.js: 20+
Expected vs Actual
Expected (per docs)
When fetch fails, API returns web_fetch_tool_error block with error code
Actual
Stream ends silently with:
- No error block
- No error events
- No error indication
- Only SDK exception
Impact
Makes web_fetch unusable in production:
- ❌ Cannot detect failures
- ❌ Cannot handle errors
- ❌ Cannot provide user feedback
- ❌ Cannot debug issues
Requested Fix
Return explicit error codes (as documented for other error scenarios):
{
"type": "web_fetch_tool_error",
"error_code": "content_too_large",
"message": "PDF size (400KB) exceeds limit (100KB)"
}Even if the underlying size limit can't be changed immediately, proper error codes would make the feature usable by allowing error handling.
Test Details
Full comparative test in gist shows:
- Small PDF (1-2 KB): ✅ Success with all events
- Large PDF (400 KB): ❌ Silent failure with no error indication
To run:
git clone https://gist.github.com/eb008ad3112f4e71575a4977d2a0f057.git
cd eb008ad3112f4e71575a4977d2a0f057
npm install
export ANTHROPIC_API_KEY=your-key
npm run test:compare## References
Bottom Line: Feature works for small files but fails silently for large ones. Adding proper error codes (already documented for other scenarios) would make this production-ready.