Token Count API
Estimate LLM token counts for any text via REST API. Essential for managing context windows in GPT-4, Claude, Gemini, and other LLMs — know before you send whether your input fits, and how much of your context budget remains.
Try it live →How it works
POST your text string. The API applies the ~4 characters-per-token heuristic (accurate to ±10% for English prose, ±20% for code) and returns the estimated token count, character count, and word count. Faster and cheaper than calling the LLM to count.
Use cases
- Check if a document fits within a model's context window before sending
- Implement context-aware chunking — split text at exact token boundaries
- Estimate LLM API costs before making a call based on input token count
- Build RAG pipelines that fill context windows optimally without overflow
- Validate user inputs are within token limits before processing
API Reference
POST https://slopshop.gg/v1/text-token-count
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Input parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
text / input |
string | required | The text or data to process |
Example response
{
"data": {
"tokens": 211,
"characters": 832,
"words": 142,
"model": "gpt-4"
},
"meta": {
"credits_used": 1,
"engine": "real",
"ms": 4
}
}
Examples
Three real-world scenarios showing how developers use Token Count in production.
curl -X POST https://slopshop.gg/v1/text-token-count \
-H "Authorization: Bearer $SLOPSHOP_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "The quarterly revenue report for Q3 2024 shows a 15% increase..."}'
curl -X POST https://slopshop.gg/v1/text-token-count \
-H "Authorization: Bearer $SLOPSHOP_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "You are a helpful assistant that specializes in financial analysis..."}'
curl -X POST https://slopshop.gg/v1/text-token-count \
-H "Authorization: Bearer $SLOPSHOP_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Chapter 1: Introduction to machine learning and its applications in modern data science..."}'
Code examples
curl
curl -X POST https://slopshop.gg/v1/text-token-count \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": "your data here"}'
Python
import requests
response = requests.post(
"https://slopshop.gg/v1/text-token-count",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"input": "your data here"}
)
result = response.json()
print(result["data"])
Node.js
const response = await fetch("https://slopshop.gg/v1/text-token-count", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({ input: "your data here" })
});
const { data } = await response.json();
console.log(data);
CLI
# Install the Slopshop CLI
npm install -g slopshop
# Set your API key
export SLOPSHOP_KEY=your_api_key
# Call text-token-count
slop text-token-count '{"input": "your data here"}'
Pricing
Credits are purchased in bundles starting at $1 for 1,000 credits. All compute APIs like this one use 1 credit per call — that's $0.001. See all pricing tiers.
Related APIs in Text Processing
View the full API catalog · Try in playground · Documentation