[BUG] undefined is not an object (evaluating '$.speed')" on direct Anthropic API (not Bedrock)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
### Bug Description
Getting undefined is not an object (evaluating '$.speed') intermittently when using
Claude Code with the direct Anthropic API (not Bedrock, not Vertex). This appears to be
the same root cause as #40189, but that issue is Bedrock-specific — this confirms the
bug also affects the standard Anthropic API provider.
### Environment
- Claude Code version: 2.1.87
- Provider: Anthropic API (direct, no Bedrock/Vertex)
- OS: Ubuntu Linux (6.14.0-37-generic)
- Model: claude-opus-4-6
Related
- #40189 (same error, but Bedrock-specific)
What Should Happen?
The client should use optional chaining (?.speed) or a null check when accessing
the speed field from API usage metadata, as it can be null.
Error Messages/Logs
Steps to Reproduce
The error occurs intermittently — not on every request. In a single day (2026-03-29),
it appeared 8 times across 5 separate sessions. All occurrences are logged as
isApiErrorMessage: true with model: "<synthetic>", indicating a client-side
parsing failure rather than an actual API error.
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.87
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
### Relevant session log data
```json
{
"message": {
"model": "<synthetic>",
"usage": { "speed": null },
"content": [{ "type": "text", "text": "undefined is not an object (evaluating '$.speed')" }]
},
"isApiErrorMessage": true,
"version": "2.1.87"
}
This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗