Stax
Tools

Token Counter

Count tokens for GPT-4, Claude, Gemini, and Llama.

~Tokens
29
Words
18
Characters
101
Sentences
2
Context window usage for GPT-4o mini29 / 128,000 tokens (0.0%)
Estimated API cost (GPT-4o mini)
Input cost: $0.000004($0.15/M tokens)
Output cost: $0.000017($0.6/M tokens)

Token count is approximate (GPT BPE-style). Actual counts may vary ±10–15% per model.

Token Counter の仕組み

Token Counter は、OpenAI の GPT-4、GPT-3.5、Claude モデルと同じトークン化を使用して、任意のテキストのトークン数を計算します。プロンプト、システム指示、またはドキュメントを貼り付けると、トークン数、現在の価格での推定 API コスト、および各モデルのコンテキストウィンドウの何パーセントが消費されるかが表示されます。LLM 搭載アプリケーションを構築するプロンプトエンジニアや開発者に不可欠です。

トークンは単語ではなく、モデルのトークナイザーが定義するテキストのチャンクです。一般的な英単語は通常 1 トークンです(例:「hello」= 1 トークン)が、長い・あまり使われない単語は複数のトークンに分割されます(「cryptocurrency」= 3 トークン)。スペース、句読点、改行もトークンを消費します。平均的に、英語では 1 トークン ≈ 4 文字または ¾ 単語です。英語以外の言語、コード、数字は文字あたりより多くのトークンを使う傾向があります。

モデルによってコンテキストウィンドウサイズが異なります:GPT-3.5-turbo は 16,385 トークン、GPT-4o は 128,000 トークン、GPT-4-32k は 32,768 トークン、Claude 3 Opus は 200,000 トークンをサポートします。コンテキストウィンドウは入力(プロンプト+会話履歴)と出力(生成された回答)の両方を含みます。Token Counter は選択したモデルのコンテキスト上限に対する入力のパーセンテージを表示するので、制限内に収めることができます。

OpenAI は 100 万トークンあたりで課金します:GPT-4o の入力コストは $5.00/M トークン、出力は $15.00/M です。GPT-3.5-turbo の入力は $0.50/M です。Anthropic の Claude 3 Sonnet は入力 $3.00/M を課金します。これらの料金では、10,000 トークンのプロンプトを 1 日 100 回処理すると、GPT-4o の入力だけで約 $5/日かかります — Token Counter でこの計算が瞬時にでき、本番アーキテクチャにコミットする前に正確なコスト予測が可能になります。

GPT-4 と GPT-3.5-turbo は OpenAI の tiktoken ライブラリの cl100k_base トークナイザーを使用します。Claude は内部的に異なるトークナイザーを使用しますが、トークン数は推定目的には十分に近いです。カウンターはブラウザで完全に動作する JavaScript 版の tiktoken を使用します — API 呼び出しは行われず、テキストはアップロードされず、トークンカウントはオフラインで動作します。開発者は Python で tiktoken.get_encoding("cl100k_base").encode(text) を使って同じ数を再現できます。

よくある質問

What is a token in AI models?
Tokens are the basic units that language models process — roughly 4 characters or 0.75 words in English. Common words are single tokens; rare words, code, and non-English text often require more tokens per word. Models are billed per token.
Why does token count vary by model?
Different models use different tokenisation algorithms (BPE, SentencePiece, etc.) trained on different vocabularies. GPT-4 uses cl100k_base, Claude uses its own tokeniser. The same text can have different token counts across models.
What is a context window?
The context window is the maximum number of tokens a model can process in a single request (input + output combined). GPT-4o has 128K tokens, Claude 3.5 Sonnet has 200K, and Gemini 1.5 Pro has 2M. Inputs exceeding the context window are truncated or rejected.
How accurate is this counter?
The token count is approximate (±10–15%) because exact tokenisation requires the model's specific tokeniser library (tiktoken for OpenAI, etc.). For precise counts, use the OpenAI Tokenizer (platform.openai.com/tokenizer) or the tiktoken Python library.
How is API cost calculated?
API cost = (token count / 1,000,000) × price per million tokens. Input and output tokens are priced differently — outputs are typically 3–4× more expensive than inputs. Costs shown are for input tokens only at current list prices.

関連ツール