Skip to content
masterclass Buddy

LangChain · Function

count_tokens_approximately

count_tokens_approximately estimates how many tokens LangChain messages use. It is useful when a fast estimate is enough instead of exact model tokenization.

Last updated

Since
v1.7

Syntax

count_tokens_approximately(messages, *, chars_per_token=4.0, extra_tokens_per_message=3.0, count_name=True, tokens_per_image=85, use_usage_metadata_scaling=False, tools=None) -> int

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • trim_messages
  • MessageLikeRepresentation
  • BaseTool

Source: count_tokens_approximately | langchain_core | LangChain Reference. Checked 2026-11-03.