GPT-5 finding
Token usage estimation in OpenAI provider ignores system prompt, undercounting input tokens
- src/providers/openai.ts:154-157
- src/providers/openai.ts:231-233
Both streaming and non-streaming estimations exclude the system prompt text, which can be large and materially affect cost tracking. This under-reports input tokens when the API does not return exact usage.
Recommendation
Include options.systemPrompt.length in the estimation. For example: baseLength = (options.systemPrompt?.length ?? 0) + messages.reduce(...); Then divide by an appropriate chars-per-token heuristic per model.