Developers integrating LLMs need to be aware of how token usage is reported in streamed responses, as it differs across APIs. OpenAI's Chat Completions API requires an explicit option to include usage data, which is sent in a final chunk. Anthropic's Messages API splits usage information across multiple events, with input tokens reported early and output tokens incrementally. This tutorial provides specific TypeScript functions to correctly parse and track token counts and costs for both OpenAI and Anthropic, ensuring accurate billing and usage monitoring. AI
IMPACT Developers can now accurately track token usage and costs for streamed LLM responses across different APIs, enabling better cost management and application reliability.
RANK_REASON The item provides a technical tutorial on how to implement specific features (streamed responses and token counting) for LLM APIs, which is a developer tool.
- Anthropic
- chat completions
- Claude Code
- GitHub
- gpt-5.4-mini
- Hermes IDE
- Messages API
- Node.js
- OpenAI
- Responses API
- TypeScript
AI-generated summary · Google Gemini · from 1 sources. How we write summaries →