Text Processing 1 credit COMPUTE

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

API Reference

POST https://slopshop.gg/v1/text-token-count
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Input parameters

ParameterTypeRequiredDescription
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.

Example 1
Check if document fits context window
Count tokens before sending a long document to an LLM.
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..."}'
Example 2
Estimate prompt cost
Count tokens in a system prompt to estimate API spend.
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..."}'
Example 3
Split at token boundary
Count tokens in a chunk to ensure it stays under a 4096-token limit.
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 per call
1
credits
Cost per call
$0.001
at Starter tier
Tier
COMPUTE
Pure compute

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