TiktokenSharp 1.0.1
See the version list below for details.
dotnet add package TiktokenSharp --version 1.0.1
NuGet\Install-Package TiktokenSharp -Version 1.0.1
<PackageReference Include="TiktokenSharp" Version="1.0.1" />
<PackageVersion Include="TiktokenSharp" Version="1.0.1" />
<PackageReference Include="TiktokenSharp" />
paket add TiktokenSharp --version 1.0.1
#r "nuget: TiktokenSharp, 1.0.1"
#:package TiktokenSharp@1.0.1
#addin nuget:?package=TiktokenSharp&version=1.0.1
#tool nuget:?package=TiktokenSharp&version=1.0.1
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, only cl100k_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.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
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (5)
Showing the top 5 NuGet packages that depend on TiktokenSharp:
| Package | Downloads |
|---|---|
|
Mythosia.AI
## What's New in v6.7.0 ### Fixed - The message-count sliding window (MaxMessageCount) can no longer drop the anchoring user message. Long agentic runs (RunAgentAsync/RunAgentStreamAsync) append two messages per tool round and could push the originating user query out of the window, producing requests with no user message that some OpenAI-compatible servers reject (e.g. vLLM/Qwen 400 "No user query found in messages"). The window now re-anchors the most recent cut-off user message whenever the sliced window has no user turn. ### Deprecated - AIService.MaxMessageCount is now [Obsolete] and will be removed in v7.0 — context management becomes token-based only (ConversationPolicy). Until then the window is guaranteed to preserve the most recent user message. Requires Mythosia.AI.Abstractions v2.4.0. --- ## Documentation - Basic Usage: https://github.com/AJ-comp/Mythosia.AI/wiki - Advanced Features: https://github.com/AJ-comp/Mythosia.AI/wiki/Advanced-Features - Release Notes: https://github.com/AJ-comp/Mythosia.AI/wiki/Release-Notes - GitHub: https://github.com/AJ-comp/Mythosia.AI |
|
|
NjxyChatAISDK
支持通过API调用OpenAI、DeepSeek、Doubao |
|
|
Mythosia.AI.Providers.Alibaba
Alibaba Cloud Qwen provider package for Mythosia.AI. Includes QwenService with expanded Qwen 3 / 3.5 model constants, platform-specific thinking request handling across DashScope, vLLM, and Ollama, token usage streaming support, and Mythosia.AI v6.4.0 compatibility. Documentation - GitHub: https://github.com/AJ-comp/Mythosia.AI - Release Notes: core/Mythosia.AI.Providers.Alibaba/RELEASE_NOTES.md |
|
|
TokenFlow.Tokenizers
Model-specific tokenizer implementations for TokenFlow.AI (OpenAI, Claude, etc.). |
|
|
Serina.Semantic.Ai.Pipelines
Serina Pipelines for Semantic Kernel allows to build flexible Ai Proccessing pipelines. |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on TiktokenSharp:
| Repository | Stars |
|---|---|
|
StartupHakk/OpenMonoAgent.ai
(BETA) AI shouldn't have a meter. Unlimited tokens. Forever. Your machine. Your agent. Use it from anywhere. Terminal-native coding agent powered by local LLMs — 100% open source, free forever, and installed with a single command. Proudly built on C#/.NET, because AI tooling should be infrastructure, not a subscription.
|
|
|
MayDay-wpf/AIBotPublic
AIBot PRO 是一个基于.NET 8 的 AI聚合客户端 to C 弱 to B 可以集成众多AI产品(ChatGPT,Gemini,Claude,文心一言,通义千问,讯飞星火),无感切换对话,支持知识库、插件开发、AI流程引擎(workflow)、以及开放平台对外输出定制化的特色AI API
|
|
|
dmitry-brazhenko/SharpToken
SharpToken is a C# library for tokenizing natural language text. It's based on the tiktoken Python library and designed to be fast and accurate.
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.2.1 | 35,265 | 2/22/2026 | |
| 1.2.0 | 46,875 | 11/19/2025 | |
| 1.1.8 | 85,310 | 8/14/2025 | |
| 1.1.7 | 88,230 | 3/14/2025 | |
| 1.1.6 | 27,103 | 12/24/2024 | |
| 1.1.5 | 46,901 | 10/8/2024 | |
| 1.1.4 | 140,954 | 5/14/2024 | |
| 1.1.2 | 644 | 5/14/2024 | |
| 1.1.1 | 304 | 5/14/2024 | |
| 1.1.0 | 15,579 | 4/8/2024 | |
| 1.0.9 | 25,031 | 2/8/2024 | |
| 1.0.8 | 19,777 | 12/27/2023 | |
| 1.0.7 | 39,852 | 10/10/2023 | |
| 1.0.6 | 105,405 | 6/25/2023 | |
| 1.0.5 | 53,807 | 5/8/2023 | |
| 1.0.4 | 3,283 | 4/24/2023 | |
| 1.0.3 | 3,445 | 3/21/2023 | |
| 1.0.2 | 1,388 | 3/17/2023 | |
| 1.0.1 | 1,654 | 3/13/2023 | |
| 1.0.0 | 1,112 | 3/7/2023 |