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 คำนวณจำนวน token ในข้อความใดก็ตามโดยใช้ tokenisation เดียวกับ GPT-4, GPT-3.5 ของ OpenAI และโมเดล Claude วาง prompt, คำสั่งระบบ หรือเอกสารของคุณ — เครื่องมือจะแสดงจำนวน token, ค่าใช้จ่าย API โดยประมาณตามราคาปัจจุบัน และเปอร์เซ็นต์ของ context window ของแต่ละโมเดลที่ใช้ไป จำเป็นสำหรับ prompt engineer และนักพัฒนาที่สร้างแอปพลิเคชันที่ขับเคลื่อนด้วย LLM

token ไม่ใช่คำ — มันคือส่วนของข้อความตามที่ tokeniser ของโมเดลกำหนด คำภาษาอังกฤษทั่วไปมักเป็น 1 token (เช่น "hello" = 1 token) แต่คำที่ยาวกว่าหรือไม่ค่อยพบจะแตกออกเป็นหลาย token ("cryptocurrency" = 3 token) ช่องว่าง เครื่องหมายวรรคตอน และการขึ้นบรรทัดใหม่ก็ใช้ token ด้วย โดยเฉลี่ย 1 token ≈ 4 ตัวอักษร หรือ ¾ ของคำในภาษาอังกฤษ ภาษาที่ไม่ใช่อังกฤษ โค้ด และตัวเลขมักใช้ token มากกว่าต่อตัวอักษร

โมเดลต่างๆ มีขนาด context window ที่แตกต่างกัน: GPT-3.5-turbo รองรับ 16,385 token, GPT-4o รองรับ 128,000 token, GPT-4-32k รองรับ 32,768 และ Claude 3 Opus รองรับ 200,000 token context window รวมทั้ง input (prompt + ประวัติการสนทนา) และ output (การตอบสนองที่สร้าง) ตัวนับ token แสดงเปอร์เซ็นต์ของ input ของคุณในขีดจำกัด context ของโมเดลที่เลือก เพื่อให้คุณอยู่ภายในขอบเขต

OpenAI คิดค่าใช้จ่ายต่อล้าน token: GPT-4o input คิด $5.00/M token และ output $15.00/M GPT-3.5-turbo input คือ $0.50/M Claude 3 Sonnet ของ Anthropic คิด $3.00/M input ในอัตราเหล่านี้ prompt 10,000 token ที่ประมวลผล 100 ครั้งต่อวันมีค่าใช้จ่ายประมาณ $5 ต่อวันสำหรับ GPT-4o input — ตัวนับ token ทำให้การคำนวณนี้ทันที ช่วยให้คาดการณ์ค่าใช้จ่ายที่แม่นยำก่อนตัดสินใจเลือก architecture การผลิต

GPT-4 และ GPT-3.5-turbo ใช้ tokeniser cl100k_base จาก library tiktoken ของ OpenAI Claude ใช้ tokeniser ที่แตกต่างกันภายใน แต่จำนวน token ใกล้เคียงกันพอสำหรับการประมาณ ตัวนับใช้ JavaScript port ของ tiktoken ที่ทำงานในเบราว์เซอร์ทั้งหมด — ไม่มีการเรียก API, ข้อความของคุณไม่เคยถูกอัปโหลด และการนับ token ทำงานแบบ offline นักพัฒนาสามารถทำซ้ำจำนวนนี้ใน 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.

เครื่องมือที่เกี่ยวข้อง