DevOnlineTools

LLM Token Counter & Cost Estimator

Estimate token counts and API invocation costs for text prompts across OpenAI (GPT-4o), Anthropic (Claude 3.5 Sonnet), and Google (Gemini 1.5 Pro) AI models.

devonlinetools://ai/token-counter
⌘ + EnterRun / Format
Shortcuts Active
Estimated Tokens
31
Words
16
Characters
116
Estimated API Cost (Input Tokens)
GPT-4o (OpenAI)
$2.5 / 1M tokens
$0.000077
GPT-4o Mini (OpenAI)
$0.15 / 1M tokens
$0.000005
Claude 3.5 Sonnet (Anthropic)
$3 / 1M tokens
$0.000093
Gemini 1.5 Pro (Google)
$1.25 / 1M tokens
$0.000039

Code Snippets & Examples

Copy-paste ready code implementations for your project:

JavaScript (@jqnatividad/tiktoken / js-tiktoken)
import { encoding_for_model } from "js-tiktoken";

const enc = encoding_for_model("gpt-4o");
const tokens = enc.encode("Hello world!");
console.log("Token count:", tokens.length);
Python (tiktoken)
import tiktoken

encoding = tiktoken.encoding_for_model("gpt-4o")
tokens = encoding.encode("Hello world!")
print(f"Tokens: {len(tokens)}")