TiktokenSharp 1.0.4

TiktokenSharp

Due to the lack of a C# version of cl100k_base encoding (gpt-3.5-turbo), I have implemented a basic solution with encoding and decoding methods based on the official Rust implementation.

Currently, cl100k_base p50k_base has been implemented. Other encodings will be added in future submissions. If you encounter any issues or have questions, please feel free to submit them on the lssues."

Update

1.0.4 20230424

  • Add method TikToken.GetEncoding(encodingName).

1.0.3 20230321

  • GetEncodingSetting now supports the model of gpt-4 and also allows for encoding names to be directly passed in.

1.0.2 20230317

  • add method TikToken.PBEFileDirectory to allow for custom storage directory of bpe files. the path needs to be set before TikToken.EncodingForModel().

1.0.1 20230313

  • p50k_base encoding algorithm that supports the text-davinci-003 model.

Start

using TiktokenSharp;
TikToken tikToken = TikToken.EncodingForModel("gpt-3.5-turbo");
var i = tikToken.Encode("hello world"); //[15339, 1917]
var d = tikToken.Decode(i); //hello world

.NET Standard 2.1

  • No dependencies.

Version Downloads Last updated
1.2.0 7 11/26/2025
1.1.8 120 08/14/2025
1.1.7 21 06/03/2025
1.1.6 4 06/06/2025
1.1.5 4 06/06/2025
1.1.4 4 06/06/2025
1.1.2 4 06/06/2025
1.1.1 4 06/28/2025
1.1.0 4 06/06/2025
1.0.9 5 06/28/2025
1.0.8 4 06/28/2025
1.0.7 4 06/28/2025
1.0.6 4 06/28/2025
1.0.5 4 06/28/2025
1.0.4 4 06/28/2025
1.0.3 4 06/28/2025
1.0.2 4 06/28/2025
1.0.1 4 06/06/2025
1.0.0 4 06/06/2025