Recognise gpt-5.1 model identifier (Fixes #464)#554
Open
jbbqqf wants to merge 1 commit into
Open
Conversation
encoding_for_model('gpt-5.1') raised KeyError because 'gpt-5.1' does
not start with the 'gpt-5-' prefix (the literal hyphen mismatches the
dot). Add 'gpt-5.1' (exact) and 'gpt-5.1-' (versioned variant) to the
same o200k_base mapping that the 'gpt-5' entries already use, per
OpenAI's GPT-5.1 migration note that the model is a drop-in replacement
for GPT-5.
Regression test covers both 'gpt-5.1' and 'gpt-5.1-2025-11'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #464.
encoding_for_model("gpt-5.1")currently raisesKeyErrorbecause the prefix table only contains
"gpt-5-", and"gpt-5.1"doesnot start with
"gpt-5-"(the literal hyphen mismatches the dot — thisis the same shape that caused #464 to be filed).
This change adds
"gpt-5.1"(exact) and"gpt-5.1-"(versionedvariant) to the o200k_base mappings, alongside the existing
"gpt-5"/"gpt-5-"pair. Per OpenAI's GPT-5.1 migration note(https://platform.openai.com/docs/guides/latest-model#migrating-from-other-models-to-gpt-5-1)
the model is documented as a drop-in replacement for GPT-5, so the
encoding choice mirrors GPT-5's.
A short code comment in
MODEL_PREFIX_TO_ENCODINGnotes theordering rationale (purely cosmetic given
startswithsemantics, butmakes the intent explicit for the next person editing the table).
Reproduce BEFORE/AFTER yourself (copy-paste)
What I ran locally
Verified the new test fails on
origin/main(before thetiktoken/model.pypatch is applied) with
KeyError: 'Could not automatically map gpt-5.1 to a tokeniser', and passes after the patch.Edge cases
"gpt-5"o200k_base(exact match)"gpt-5-mini"o200k_baseviagpt-5-prefix"gpt-5.1"KeyErroro200k_base(exact match)"gpt-5.1-2025-11"KeyErroro200k_baseviagpt-5.1-prefix"gpt-5.2"(hypothetical future)KeyErrorKeyError(intentional — wait for explicit OpenAI doc)gpt-5modelThe change is additive (two new dict entries plus a comment); existing
mappings are untouched.
PR drafted with assistance from Claude Code (Anthropic). The change
was reviewed manually against
tiktoken/model.pyand the OpenAImigration doc linked above. The reproducer block above is the one I
used during development; reviewers can paste it verbatim.