[bot] Bedrock Converse prompt caching metrics (cacheReadInputTokens, cacheWriteInputTokens) not captured
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 70/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- aws, java
- Ambito
- observability
Direzione di ricerca
Inizia in InstrumentationSemConv.java da tagBedrockResponse(), quindi segui parseTokenUsage() e buildConverseJson() in BraintrustBedrockInterceptor.java per il percorso di streaming. Aggiungi la copertura in BraintrustAWSBedrockTest.java usando una risposta con i campi di utilizzo della prompt cache di Bedrock; il lavoro è completato quando entrambi i percorsi Converse conservano e acquisiscono cacheReadInputTokens, cacheWriteInputTokens e cacheDetails.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
The Bedrock Converse instrumentation extracts inputTokens, outputTokens, and totalTokens from the response usage object, but silently drops the prompt caching fields cacheReadInputTokens, cacheWriteInputTokens, and cacheDetails. These fields are returned by the Bedrock Converse API when prompt caching is active and are important for understanding cache hit rates and cost savings.
Both the non-streaming (Converse) and streaming (ConverseStream) paths are affected.
What is missing
Non-streaming path
In InstrumentationSemConv.tagBedrockResponse() (lines 350–357), only three usage fields are extracted:
if (usage.has("inputTokens")) metrics.put("prompt_tokens", usage.get("inputTokens"));
if (usage.has("outputTokens")) metrics.put("completion_tokens", usage.get("outputTokens"));
if (usage.has("totalTokens")) metrics.put("tokens", usage.get("totalTokens"));
The following fields from the Bedrock usage object are never extracted:
cacheReadInputTokens— tokens served from the prompt cachecacheWriteInputTokens— tokens written to the prompt cachecacheDetails— array of per-checkpoint cache details including TTL
Streaming path
In BraintrustBedrockInterceptor.TeeingSubscriber.parseTokenUsage() (lines 362–379), only inputTokens and outputTokens are parsed from the metadata event payload. Cache token fields in the same payload are ignored. The buildConverseJson() method (lines 385–410) then constructs a synthetic response with only inputTokens, outputTokens, and totalTokens — cache fields are lost before they reach tagBedrockResponse.
A real Converse response with prompt caching looks like:
"usage": {
"inputTokens": 1200,
"outputTokens": 350,
"totalTokens": 1550,
"cacheReadInputTokens": 800,
"cacheWriteInputTokens": 400,
"cacheDetails": [
{ "inputTokens": 800, "ttl": "5m" }
]
}
Today, only inputTokens, outputTokens, and totalTokens are captured. The cache fields are silently dropped.
For comparison, the Google GenAI handler in this repo already extracts cachedContentTokenCount as prompt_cached_tokens (line 142–146 of BraintrustApiClient.java), showing that cache token extraction is an established pattern here. Similar gaps for Anthropic (#57) and OpenAI (#58, #70) cache tokens have already been filed.
Braintrust docs status
- Braintrust lists AWS Bedrock as a supported cloud provider at https://www.braintrust.dev/docs/integrations/ai-providers
- The Bedrock-specific docs page does not mention prompt caching or cache token metrics: not_found
Upstream sources
- AWS Bedrock prompt caching docs: https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html — GA feature, documents
cacheReadInputTokensandcacheWriteInputTokensin Converse response usage - Bedrock Converse API reference: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html —
TokenUsageincludescacheReadInputTokens,cacheWriteInputTokens,cacheDetails - Supported models: Claude Opus 4, Claude 3.7 Sonnet (GA); Claude 3.5 Sonnet v2 (Preview); Amazon Nova (automatic caching)
Local files inspected
braintrust-sdk/src/main/java/dev/braintrust/instrumentation/InstrumentationSemConv.java— lines 350–357 (tagBedrockResponse: onlyinputTokens,outputTokens,totalTokensextracted from usage)braintrust-sdk/instrumentation/aws_bedrock_2_30_0/src/main/java/dev/braintrust/instrumentation/awsbedrock/v2_30_0/BraintrustBedrockInterceptor.java— lines 362–379 (parseTokenUsage: onlyinputTokensandoutputTokensparsed); lines 385–410 (buildConverseJson: synthetic response omits cache fields)braintrust-sdk/instrumentation/aws_bedrock_2_30_0/src/test/java/dev/braintrust/instrumentation/awsbedrock/v2_30_0/BraintrustAWSBedrockTest.java— no test exercises prompt caching responsesbraintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustApiClient.java— lines 142–146 (GenAI handler already extractscachedContentTokenCountasprompt_cached_tokens)
- Lingua principale
- Java
- Stelle
- 21
- Fork
- 5
- Merge medio
- 2g 7h
- PR unite (30g)
- 8
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di braintrustdata/braintrust-sdk-java
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Tutte le issue di braintrustdata/braintrust-sdk-java
Issue simili
-
certification
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
[BUG] ECR GetAuthorizationToken returns a proxyEndpoint for the default region, not the request's Apertabug ecr
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Needs: Triage Type: Feature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
AntennaPod/AntennaPod#8794 ·
-
agentic-workflows
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
github/copilot-sdk#2760 ·