Skip to content

Add GPT-5 and o-series model support to tiktoken notebook#2515

Open
edenfunf wants to merge 1 commit intoopenai:mainfrom
edenfunf:fix/tiktoken-add-gpt5-o-series-support
Open

Add GPT-5 and o-series model support to tiktoken notebook#2515
edenfunf wants to merge 1 commit intoopenai:mainfrom
edenfunf:fix/tiktoken-add-gpt5-o-series-support

Conversation

@edenfunf
Copy link

Summary

The How_to_count_tokens_with_tiktoken.ipynb notebook currently raises NotImplementedError when trying to count tokens for GPT-5, o1, o3, or o4-mini models. These are among the most commonly used models today, so this is a significant usability gap.

Changes:

  • Updated the encoding table to list GPT-5 and o-series models under o200k_base
  • Added a gpt-5/o1/o3/o4 branch in num_tokens_from_messages() — these models use the same message token format as gpt-4o (tokens_per_message=3, tokens_per_name=1)
  • Added gpt-5, o1, o3, o3-mini, and o4-mini to the model list in num_tokens_for_tools() — same tool token settings as gpt-4o
  • Added gpt-5 and o4-mini to both verification loops so they get tested alongside the older models
  • Switched from max_tokens to max_completion_tokens in the verification cell, since o-series models require this parameter

How I verified

  • Confirmed via tiktoken.encoding_for_model() that gpt-5, o1, o3, o3-mini, and o4-mini all resolve to o200k_base
  • The token-per-message format for these models matches gpt-4o based on the API behavior
  • Cleared the stored outputs for the updated verification cells so they don't show stale results

Addresses #2436

The num_tokens_from_messages() and num_tokens_for_tools() functions raise
NotImplementedError for GPT-5, o1, o3, and o4-mini models, which are now
widely used.

- Update encoding table to include GPT-5 and o-series in o200k_base row
- Add GPT-5/o-series branch to num_tokens_from_messages()
- Add GPT-5/o-series to num_tokens_for_tools() model list
- Add gpt-5 and o4-mini to verification loops
- Use max_completion_tokens instead of max_tokens (required by o-series)

Addresses openai#2436
@vaultloans4you-debug
Copy link

vaultloans4you-debug commented Mar 12, 2026 via email

@edenfunf
Copy link
Author

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants