Repository navigation
Description
What version of Effect is running?
@effect/ai: ^0.33.0@effect/ai-amazon-bedrock: ^0.13.0
Description
When extended thinking is enabled via additionalModelRequestFields.thinking, the Bedrock Converse API returns reasoning content in output.message.content (as reasoningContent blocks), and the @effect/ai-amazon-bedrock provider correctly extracts this into ReasoningPart objects (accessible via response.reasoningText).
However, response.usage.reasoningTokens is always undefined. The @effect/ai library defines reasoningTokens in Response.Usage (line 154 of LanguageModel.ts):
reasoningTokens: Schema.optionalWith(Schema.Number, { as: "Option" })But the Bedrock provider's makeResponse function never maps a value for it:
// AmazonBedrockLanguageModel.ts makeResponse (lines 607-622)
usage: {
inputTokens: raw.usage!.inputTokens!,
outputTokens: raw.usage!.outputTokens!,
cacheCreationInputTokens: (raw.usage as any).cacheCreationInputTokens ?? 0,
cacheReadInputTokens: (raw.usage as any).cacheReadInputTokens ?? 0,
// reasoningTokens is never set
},The Bedrock Converse API does not return reasoning tokens as a separate field in its usage metrics — reasoning tokens are bundled into outputTokens. The Anthropic direct API does return them separately (as cache_creation_input_tokens and cache_read_input_tokens for caching, and model-specific fields for thinking).
Root Cause
Two related issues:
-
Bedrock Converse API limitation: The Converse API's
TokenUsageresponse only includesinputTokens,outputTokens,totalTokens,cacheReadInputTokens, andcacheWriteInputTokens. There is noreasoningTokensorthinkingTokensfield. Reasoning tokens are included inoutputTokens. -
Provider gap: The
@effect/ai-amazon-bedrockprovider doesn't attempt to derive reasoning tokens. A possible heuristic would be to count the tokens in the returnedreasoningContentblocks, but this would require a tokenizer and wouldn't be precise.
Reproduction
import { Chat } from "@effect/ai"
import { AmazonBedrockLanguageModel } from "@effect/ai-amazon-bedrock"
import { Effect, Option } from "effect"
const program = Effect.gen(function* () {
const chat = yield* Chat.fromPrompt([{ role: "system", content: "Think carefully." }])
const response = yield* chat.generateText({
prompt: "What is 2+2? Show your reasoning.",
}).pipe(
AmazonBedrockLanguageModel.withConfigOverride({
additionalModelRequestFields: {
thinking: { type: "enabled", budget_tokens: 4096 },
},
})
)
console.log("reasoningText:", response.reasoningText)
// => "Let me think about this..." (populated correctly)
console.log("reasoningTokens:", Option.getOrUndefined(response.usage.reasoningTokens))
// => undefined (never populated)
})Expected Behavior
Either:
- Populate
reasoningTokensby deriving it from the Bedrock response (e.g., if the direct Anthropic API provides it via thex-amzn-bedrock-*headers or if Bedrock adds the field in the future), or - Document that
reasoningTokensis not available when using the Bedrock Converse API and that reasoning tokens are included inoutputTokens, so consumers know not to rely on it for cost calculations.
Note: The Anthropic direct API (@effect/ai-anthropic) may have access to this data and could serve as a reference implementation.
Activity
Chaoran-Huang commentedon Jun 17, 2026
Quick follow-up / correction on my own issue after going back through current
main.The premise here is actually wrong: the Anthropic direct API doesn't break out reasoning tokens either, so it can't serve as a reference. Their
Usage/BetaUsageschema (generated from Anthropic's OpenAPI spec) only hasinput_tokens,output_tokens, the cache fields andserver_tool_use, and the docs are explicit thatoutput_tokensalready includes the thinking tokens. That's the same situation as Bedrock'sTokenUsage. OpenAI is the only provider that reports it separately (output_tokens_details.reasoning_tokens), which is why it's the only one that fills in the field today.So populating/deriving
reasoningTokensfor Bedrock (or Anthropic) isn't really feasible — counting tokens off the reasoning blocks would just be a guess. I'm going with the documentation route instead.Opened #6278 to document this on
Response.Usage.reasoningTokensand at the usage-mapping sites in both the Anthropic and Bedrock providers, so it's clear the field is intentionally unset for these providers and shouldn't be used for cost math.fubhy commentedon Jul 9, 2026
Closing based on the reporter's follow-up: Bedrock Converse does not expose separate reasoning-token usage, so
reasoningTokenscannot be populated accurately. Documentation clarification is tracked in #6278.