tkn cnt fix #3

This commit is contained in:
Luxferre
2026-10-16 08:37:38 +03:00
parent c970d96e91
commit d8af11fc47
2 changed files with 24 additions and 7 deletions
+8
View File
@@ -680,6 +680,14 @@ bool parse_nonstream_response(std::string_view body, Message &out, Usage &usage)
if (usage.cached_tokens == 0) {
usage.cached_tokens = u["cached_tokens"].as_int();
}
if (usage.cached_tokens > usage.prompt_tokens) {
/* Some providers (e.g. Cohere models on OpenRouter) report
* prompt_tokens as the *uncached* portion and cached_tokens as an
* *additional* amount, instead of the OpenAI convention where
* cached_tokens is a subset of prompt_tokens. Normalize so
* prompt_tokens always holds the true total input. */
usage.prompt_tokens += usage.cached_tokens;
}
}
usage.model = root["model"].str();
return true;