tkn cnt fix #3
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user