TokenFlow.Core
0.3.0
See the version list below for details.
dotnet add package TokenFlow.Core --version 0.3.0
NuGet\Install-Package TokenFlow.Core -Version 0.3.0
<PackageReference Include="TokenFlow.Core" Version="0.3.0" />
<PackageVersion Include="TokenFlow.Core" Version="0.3.0" />
<PackageReference Include="TokenFlow.Core" />
paket add TokenFlow.Core --version 0.3.0
#r "nuget: TokenFlow.Core, 0.3.0"
#:package TokenFlow.Core@0.3.0
#addin nuget:?package=TokenFlow.Core&version=0.3.0
#tool nuget:?package=TokenFlow.Core&version=0.3.0
<p align="center"> <img src="https://github.com/AndrewClements84/TokenFlow.AI/blob/master/assets/logo.png?raw=true" alt="TokenFlow.AI" width="500"/> </p>
TokenFlow.AI
๐ก Overview
TokenFlow.AI is a lightweight .NET library for tokenization, chunking, and cost estimation across modern large language models (LLMs) such as OpenAI GPTโ4o, Anthropic Claude, and Azure OpenAI.
It serves as the core engine of the Flow.AI ecosystem โ providing accurate token counting, intelligent text splitting, and realโtime cost tracking for any AIโdriven application.
๐งฉ Key Features
- ๐ข GPTโstyle token counting for .NET
- ๐งฑ Smart text chunking with configurable token limits and overlap
- ๐ฐ Realโtime cost estimation for prompt and completion usage
- ๐ Pluggable tokenizer providers (OpenAI, Anthropic, Azure AI)
- ๐งฎ Unified TokenFlowClient for developers โ analyze, chunk, and cost in one API
- ๐ฆ Zero external dependencies โ small, fast, and portable
- ๐ง Designed to integrate with PromptStream.AI, DataFlow.AI, and ReasonFlow.AI
๐ Installation
dotnet add package TokenFlow.AI
Or install the shared core contracts:
dotnet add package TokenFlow.Core
๐ง Quick Example
Token analysis and cost estimation:
using TokenFlow.AI.Client;
var client = new TokenFlowClient("gpt-4o");
var result = client.AnalyzeText("TokenFlow.AI brings structure to prompt engineering.");
Console.WriteLine($"Model: {result.ModelId}");
Console.WriteLine($"Tokens: {result.TokenCount}");
Console.WriteLine($"Estimated cost: ยฃ{result.EstimatedCost:F4}");
Chunking long text:
var chunks = client.ChunkText("This is a long body of text that exceeds a given token limit...", maxTokens: 50, overlapTokens: 5);
foreach (var chunk in chunks)
Console.WriteLine($"Chunk: {chunk.Substring(0, Math.Min(40, chunk.Length))}...");
๐งฉ Example Architecture
TokenFlow.AI
โโ Client/
โ โโ ITokenFlowClient.cs
โ โโ TokenFlowClient.cs
โโ Chunking/
โ โโ ITextChunker.cs
โ โโ TokenChunker.cs
โโ Tokenizer/
โ โโ ApproxTokenizer.cs
โโ Costing/
โ โโ CostEstimator.cs
โโ Registry/
โโ ModelRegistry.cs
๐งช Running Tests
dotnet test --no-build --verbosity normal
All unit tests are written in xUnit and run automatically through GitHub Actions.
Code coverage is tracked with Codecov, and the project maintains 100% line and branch coverage.
๐งญ Part of the Flow.AI Ecosystem
| Package | Purpose |
|---|---|
| ๐ง TokenFlow.AI | Core tokenization, chunking & cost estimation |
| ๐ฌ PromptStream.AI | Prompt composition & validation |
| ๐ DataFlow.AI | Data ingestion & structured streaming pipelines |
| ๐งฉ ReasonFlow.AI | Logical reasoning & multi-step thought orchestration |
| ๐งฌ ModelFlow.AI | Unified model abstraction & configuration registry |
| ๐ญ ChatFlow.AI | Conversational orchestration & dialogue state management |
๐ ๏ธ Roadmap
โ Completed
- Core interfaces and models (
ITokenizer,ICostEstimator,ModelSpec,TokenCountResult) - Implemented
ApproxTokenizer,CostEstimator, andModelRegistry - Added
TokenChunkerwith overlap support - Added
TokenFlowClientโ unified entry point for developers - Full xUnit test suite with 100% code coverage
- CI/CD pipeline with Codecov and automated NuGet publishing
- Dual targeting for .NET Standard 2.0 and .NET 8.0
๐ง In Progress
- Introduce
TokenUsageTrackerfor cumulative cost tracking - Implement
ITokenizerFactoryfor dynamic tokenizer resolution - Extend
ModelRegistryto support JSON configuration loading - CLI utilities via TokenFlow.Tools
- Benchmark suite using BenchmarkDotNet
๐ Future Goals
- Integration with PromptStream.AI for prompt budget validation
- Integration with DataFlow.AI for token-based stream segmentation
- Advanced tokenizers (OpenAI tiktoken, Claude tokenizer)
- Developer documentation & sample apps
- Public release under Flow.AI brand umbrella
๐ฌ Contributing
Pull requests are welcome!
If youโd like to contribute to the Flow.AI ecosystem, please read the upcoming CONTRIBUTING.md once published.
๐ชช License
Distributed under the MIT License.
See LICENSE for details.
โญ If you find TokenFlow.AI useful, please give the repository a star on GitHub!
It helps others discover the Flow.AI ecosystem and supports ongoing development.
| 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on TokenFlow.Core:
| Package | Downloads |
|---|---|
|
TokenFlow.AI
Lightweight .NET library for tokenization, chunking, and cost estimation across modern LLMs (OpenAI GPT-4o, Claude, Azure OpenAI). |
|
|
TokenFlow.Tokenizers
Model-specific tokenizer implementations for TokenFlow.AI (OpenAI, Claude, etc.). |
|
|
PromptStream.AI
Token-aware prompt composition, validation, and conversational context toolkit for .NET. |
GitHub repositories
This package is not used by any popular GitHub repositories.