Tiktoken Chat
Use a tiktoken vocabulary through the chat codec interface for native API token accounting.
TiktokenChatTokenizer
Section titled “TiktokenChatTokenizer”Use a tiktoken encoding through the ChatCodec interface. It renders messages as plain text with role labels for local token accounting.
The selected tiktoken vocabulary handles encoding and decoding. Native API backends send tool schemas separately.
Definition
Fields
TiktokenChatTokenizer.init
Section titled “TiktokenChatTokenizer.init”TiktokenChatTokenizer.encode
Section titled “TiktokenChatTokenizer.encode”Encode text as token IDs. add_special_tokens is accepted but ignored. Special-token spellings in the input are encoded as ordinary text.
TiktokenChatTokenizer.decode
Section titled “TiktokenChatTokenizer.decode”Decode token IDs as text. skip_special_tokens is accepted but ignored.
TiktokenChatTokenizer.encode_single_token
Section titled “TiktokenChatTokenizer.encode_single_token”Look up the token ID for a token’s bytes. This lets the chat adapter recover exact IDs from per-token response data.
TiktokenChatTokenizer.apply_chat_template
Section titled “TiktokenChatTokenizer.apply_chat_template”Render messages as text with role labels, then encode that text. Tool schemas are sent separately by the native API backend and are omitted from this rendering.
TiktokenChatTokenizer.render_text
Section titled “TiktokenChatTokenizer.render_text”Return the conversation as text with one role-labeled block per message. Use it to inspect the transcript used for local token accounting.