<h1 align="center">
<a href="https://prompts.chat">
Track Anthropic costs from native usage metadata instead of relying on the fallback tiktoken estimator.
Loading actions...
<a href="https://prompts.chat">
TypeScript and ESLint rules that MUST be followed when creating, modifying, or reviewing any file under apps/frontend/, including .ts, .tsx, .js, and .jsx files. Also apply when discussing frontend linting, type safety, or ESLint configuration.
risks
Track Anthropic costs from native usage metadata instead of relying on the fallback tiktoken estimator.
Anthropic requests were being costed with a generic text-length estimator rather than the provider's native token usage metadata. That made Anthropic totals inaccurate, especially for streaming responses and tool-calling flows where usage arrives through response metadata rather than plain text length.
gpt_researcher/utils/costs.pyresponse_metadata["usage"] / usage_metadata when Anthropic returns native token countsGenericLLMProvider for both normal and streaming responsescreate_chat_completion() and tool-calling flowsVerified locally with:
uv run python -c "import gpt_researcher; print('ok')"uv run python -m unittest tests.test_costs tests.test_llm_usage_trackingNone.
None identified.