aws / aws/aws-sdk-java-v2

Document input not supported for token counting

Open
#6,370 2 comments 2 reactions 0 assignees View on GitHub
feature-request service:bedrock-runtime
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

### Describe the bug

There is very little information about the new token counting feature for Bedrock. It seems to work for basic text, which is cute, but the difficult part is documents, and it doesn't work for any kind of documents. I know that Claude 4 supports token counting, at least through their API, but Bedrock is throwing an exception.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Expected Behavior

I expect token counting to work for Claude 4, including documents such as txt, md, doc, docx, csv, xls, xlsx, pdf.

### Current Behavior

Exception for any document: "Document input not supported for token counting".

### Reproduction Steps

```groovy
bedrockRuntimeClient.countTokens({
it.modelId('anthropic.claude-sonnet-4-20250514-v1:0')
it.input({
it.converse {
it.messages([
Message.builder()
.content([
ContentBlock.fromDocument({
it.name('document')
it.source {
it.text('text')
}
})
])
.role(ConversationRole.USER)
.build()
])
}
})
}).inputTokens()
```

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### AWS Java SDK version used

2.32.29

### JDK version used

11

### Operating System and version

MacOS 15.0.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.