AI Gateway: Bedrock Converse API responses missing token usage and cost tracking
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 345
- Avg merge
- 13h 31m
- Merged PRs (30d)
- 1
Description
## Description
When routing AWS Bedrock requests through the AI Gateway, token usage and cost aren't tracked in the dashboard. Requests log correctly (status, model, latency), but usage shows "– in / – out" and cost shows "$ –".
## Cause
The Bedrock Converse API returns usage in camelCase, but the gateway only appears to parse snake_case fields:
**Bedrock response:**
```json
{
"usage": {
"inputTokens": 13,
"outputTokens": 12,
"totalTokens": 25
}
}
```
**OpenAI response (tracked correctly):**
```json
{
"usage": {
"input_tokens": 761,
"output_tokens": 3441,
"total_tokens": 4202
}
}
```
## Steps to Reproduce
1. Route Bedrock requests through AI Gateway using the documented URL rewriting approach
2. Make a request to any Bedrock model (e.g. Claude Sonnet 4.6)
3. Check the AI Gateway logs — tokens and cost are missing
## Related
- cloudflare/cloudflare-docs#20536 — Similar parsing issue with Anthropic direct API
Contributor guide
Research direction
Start at the AI Gateway's Bedrock Converse request and response handling, tracing how the documented URL-rewriting route maps response usage into dashboard logs. Compare the Bedrock camelCase usage object with the already-working OpenAI snake_case path, then reproduce with a Bedrock model. Done when input, output, total token usage, and cost appear instead of dashes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100