[Bug]: Bedrock LLM prompt_tokens leaves out cache read/write tokens
Los mantenedores suelen responder en 1 día
@lalith0407 ya está trabajando en esto.
Desde el 6/11/2026.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
Start in the Bedrock provider at BedrockCompletion._track_token_usage_internal, named in the issue, and compare its accounting with the Anthropic provider’s cache token handling. Check the mocked Converse usage example and the existing token usage tests; done means prompt_tokens includes input, cache read, and cache write, cached_prompt_tokens and cache_creation_tokens track their respective fields, and the totals add up when consistent.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
When using the native Bedrock provider with prompt caching, UsageMetrics.prompt_tokens undercounts billed input. Bedrock Converse reports usage.inputTokens as the non-cached input only; cache hits and writes are separate (cacheReadInputTokens / cacheWriteInputTokens). AWS documents total input as the sum of those three, and totalTokens already includes them.
BedrockCompletion._track_token_usage_internal currently does:
self._token_usage["prompt_tokens"] += input_tokens # inputTokens only
self._token_usage["cached_prompt_tokens"] += cached_tokens # read only
# cache writes never recorded; prompt+completion != totalTokens
The Anthropic provider in this repo already folds cache_read_input_tokens + cache_creation_input_tokens into input_tokens before tracking.
Steps to Reproduce
Offline with a mocked converse response (no live AWS needed):
from unittest.mock import patch
from crewai.llm import LLM
llm = LLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0")
usage = {
"inputTokens": 10,
"outputTokens": 5,
"totalTokens": 18906,
"cacheReadInputTokens": 18891,
"cacheWriteInputTokens": 0,
}
with patch.object(llm._client, "converse") as mock_converse:
mock_converse.return_value = {
"output": {"message": {"role": "assistant", "content": [{"text": "OK"}]}},
"usage": usage,
"stopReason": "end_turn",
}
llm.call("Hello")
print(llm._token_usage)
# main: prompt_tokens=10, cached_prompt_tokens=18891, total_tokens=18906
# expected: prompt_tokens=18901 (== 10+18891), prompt+completion == total
Same gap on the first (cache-write) turn: cacheWriteInputTokens is ignored entirely (cache_creation_tokens stays 0).
Expected behavior
prompt_tokens == inputTokens + cacheRead + cacheWritecached_prompt_tokens == cacheReadcache_creation_tokens == cacheWriteprompt_tokens + completion_tokens == total_tokens(whentotalTokensis consistent)
Actual behavior
prompt_tokens= non-cachedinputTokensonly- cache writes not tracked
prompt + completion != totalon cached turns
CrewAI version
main @ 7abc196 (2026-11-06)
Additional context
HUMAN: I hit this while checking Bedrock prompt-caching metrics in crewAI: on a cache-hit turn, prompt_tokens stayed at the non-cached input count while total_tokens already included the cache read, so the parts didn't add up. Looking at the Converse usage fields and how the Anthropic path in this repo folds cache read/write into input, Bedrock wasn't doing the same. Happy to take a fix once this is confirmed.
- Lenguaje dominante
- Python
- Estrellas
- 60.6k
- Forks
- 9.1k
- Merge medio
- 1 d 2 h
- PR fusionados (30 d)
- 214
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de crewAIInc/crewAI
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Feature request: GoldenDirectiveTool (harmonic relationship score, full vs cropped reporting)Abiertofeature-request
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
crewAIInc/crewAI#9200 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
crewAIInc/crewAI#9132 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
[BUG] Scrape tools reject the documented cookies mapping and drop cookies when the URL is passed at runtimePosiblemente ocupada @Luckyou-d la tomó hace 5 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[BUG] OpenAI-compatible embedding model alias breaks embedder constructionPosiblemente ocupada @gokay-ai la tomó hace 11 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
crewAIInc/crewAI#8761 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de crewAIInc/crewAI
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
bigbio/sdrf-pipelines#372 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Open Source] PixelboltAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
521xueweihan/HelloGitHub#4297 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
aws-samples/sample-per-model-bedrock#822 ·
Los mantenedores suelen responder en 1 día
-
area:study-data p2-high ready-for-agent type:chore
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
fderuiter/deruiter.dev#3706 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
awslabs/visual-asset-management-system#1234 ·
Los mantenedores suelen responder en 1 día