Skip to content

Document input not supported for token counting #6370

@azavisha-snap

Description

@azavisha-snap

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions