Fix OpenAI/LiteLLM provider: sanitize tool IDs, parse cache stats, hide empty cache UI

- Sanitize tool_use_id values in OpenAI request conversion to match
  Bedrock's required pattern ^[a-zA-Z0-9_-]+$. Fixes 400 errors when
  LiteLLM proxies to Bedrock and tool IDs contain invalid characters.

- Parse cache usage stats from LiteLLM/OpenAI responses
  (prompt_tokens_details.cached_tokens, cache_read_input_tokens,
  cache_creation_input_tokens) and propagate to token usage tracking.

- Hide cache-o-meter in session status bar when provider doesn't report
  cache data (LiteLLM/OpenAI), instead of showing misleading 0% stats.

- Update cost estimation to account for cache read/write pricing tiers.
This commit is contained in:
Ryan Ward
2026-07-20 13:36:11 -05:00
parent 1cc4ede83f
commit ca2cf6f8d6
3 changed files with 123 additions and 47 deletions
+31 -27
View File
@@ -822,35 +822,39 @@ fn render_session_status_bar(
.finish(),
);
// Separator
row.add_child(
Container::new(
Text::new_inline(" \u{2502} ".to_string(), font_family, font_size)
// Only show cache stats when the provider actually reports them
// (Bedrock reports cache data; LiteLLM/OpenAI typically does not)
if cache_read > 0 || cache_write > 0 {
// Separator
row.add_child(
Container::new(
Text::new_inline(" \u{2502} ".to_string(), font_family, font_size)
.with_color(dim_color)
.finish(),
)
.finish(),
);
// Cache Hit: XX.X% (R: Xk W: Xk M: Xk)
let cache_label = format!("\u{25c6} Cache: {:.1}%", cache_hit_pct);
row.add_child(
Text::new_inline(cache_label, font_family, font_size)
.with_color(cache_color)
.finish(),
);
let cache_detail = format!(
" (R:{} W:{} M:{})",
format_token_count(cache_read),
format_token_count(cache_write),
format_token_count(cache_miss),
);
row.add_child(
Text::new_inline(cache_detail, font_family, font_size)
.with_color(dim_color)
.finish(),
)
.finish(),
);
// Cache Hit: XX.X% (R: Xk W: Xk M: Xk)
let cache_label = format!("\u{25c6} Cache: {:.1}%", cache_hit_pct);
row.add_child(
Text::new_inline(cache_label, font_family, font_size)
.with_color(cache_color)
.finish(),
);
let cache_detail = format!(
" (R:{} W:{} M:{})",
format_token_count(cache_read),
format_token_count(cache_write),
format_token_count(cache_miss),
);
row.add_child(
Text::new_inline(cache_detail, font_family, font_size)
.with_color(dim_color)
.finish(),
);
);
}
// Separator
row.add_child(