Skip to main content

Installation (Python)

LLM Context Forge requires Python 3.9+. It is published on PyPI.

Standard Installation

Install using standard package managers. This installs the base package with tiktoken for OpenAI/Anthropic/Gemini counting.

# Pip
pip install llm-context-forge

# Poetry
poetry add llm-context-forge

# uv
uv pip install llm-context-forge

Optional Dependencies

Some models require additional tokenizers. You can install them using extras:

# For Mistral/Mixtral exact counting
pip install "llm-context-forge[mistral]"

# For Llama 3 exact counting via HuggingFace
pip install "llm-context-forge[hf]"

# Install everything
pip install "llm-context-forge[all]"

Verify Installation

You can quickly verify your installation via the CLI:

$ python -m llm_context_forge count gpt-4o "Hello, world!"
Tokens: 4

Or programmatically:

import llm_context_forge
print(llm_context_forge.__version__)