Skip to content

Conversation

bl-ue
Copy link

@bl-ue bl-ue commented Jul 15, 2025

This PR adds token count and selected model information to thinking blocks, text blocks and tool call blocks in the rollout files. This is needed for tools to be able to analyze Codex CLI usage programmatically. Because Codex CLI can work with any OpenAI-compatible provider and different models use different tokenizers, attempting to count the tokens of the user/AI messages in the rollout files externally is impractical. In addition, the number of cached tokens, which affects the reported cost, cannot be computed given just the message content. As most OpenAI-compatible providers return token usage directly with each generation request, including that token usage information in the rollout files is trivial

Codex support in Splitrail is now implemented and waiting for this PR.

Closes #1572
Closes #2989
Closes #3433
Closes #3513

Copy link

github-actions bot commented Jul 15, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@bl-ue bl-ue force-pushed the enhance-recorded-chat-history-071525 branch from 30edd03 to 9bf17f4 Compare July 15, 2025 15:41
@bl-ue
Copy link
Author

bl-ue commented Jul 15, 2025

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jul 15, 2025
@bl-ue bl-ue marked this pull request as draft July 16, 2025 01:21
@bl-ue bl-ue marked this pull request as ready for review July 17, 2025 20:30
@bl-ue
Copy link
Author

bl-ue commented Jul 17, 2025

Ready for review.

@bl-ue bl-ue marked this pull request as draft July 21, 2025 15:17
…rollout files

This ensures that the metadata is updated as well as the contents, so that file watchers can get immediate updates.
@bl-ue bl-ue marked this pull request as ready for review July 21, 2025 16:09
@bl-ue
Copy link
Author

bl-ue commented Jul 21, 2025

Hi @bolinfest! This PR adds token, timestamp, and model information to rollout files. This enables our new tool, Splitrail, to track token usage, cost, and throughput for Codex users. It also makes it easier for other tools to do the same. Do you mind taking a look? Thank you!

@bl-ue
Copy link
Author

bl-ue commented Jul 26, 2025

cc @aibrahim-oai

@aibrahim-oai
Copy link
Collaborator

aibrahim-oai commented Jul 26, 2025

Tools can already calculate tokens used from the rollout info. I don't think there is much benefit in adding them in response items. What is the use?

@bl-ue
Copy link
Author

bl-ue commented Jul 26, 2025

Hi @aibrahim-oai! Thank you for reviewing so quickly. Yes, that makes sense, but automatic input caching makes accurate calculations impossible. When input exceeds 1024 tokens, inputs are automatically cached (see here), so there's no way to determine which part of the input was cached and which wasn't; therefore, we can't calculate cost accurately.

In addition, rollouts don't currently store model information, so it's not possible to determine which tokenizer to use, nor can we determine model/token cost for accurate cost calculation. This PR stores model information to address this.

Last but not least, Codex can be used with custom providers, and it would be difficult to perform tokenization on rollouts that use custom models/providers; with open-source models in Ollama, you'd have to download and use a tokenizer, and with providers that don't distribute their tokenizers, you'd have to use an API.

@bl-ue bl-ue marked this pull request as draft August 10, 2025 18:39
@bl-ue bl-ue marked this pull request as ready for review August 10, 2025 22:17
@bl-ue
Copy link
Author

bl-ue commented Aug 10, 2025

Hi @bolinfest, @gpeal, and @pakrym-oai! This PR enhances rollouts with token counts, timestamps, and model info. We're using this data to calculate usage along with Claude Code and Gemini CLI in Splitrail. With GPT-5, we expect Codex CLI usage to increase. Is there any chance you guys could take a look this week?

@guywilsonjr
Copy link

can we get this back?

@bl-ue bl-ue marked this pull request as draft August 17, 2025 01:20
@bl-ue bl-ue marked this pull request as ready for review August 19, 2025 15:23
@bl-ue bl-ue changed the title Add token counts, timestamps, and model to rollouts feat: add token counts, timestamps, and model to rollouts Aug 19, 2025
@bl-ue
Copy link
Author

bl-ue commented Sep 7, 2025

Hi @dylan-hurd-oai @easong-openai @jif-oai @pap-openai @aibrahim-oai @bolinfest! Is there any chance this PR can be merged? Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants