Universal Token Counter (UTC)

High-precision multilingual token counting API for OpenAI-compatible encodings.

A utility API to obtain token counts for Japanese and multilingual text in a stable JSON format.

Token Counting / LLM Utility
View on RapidAPI GitHub Repo Back to APIron Lab

Overview

Universal Token Counter (UTC) is a high-precision, multilingual token counting API designed for LLM workflows.

It supports OpenAI-compatible encodings (e.g. o200k_base, cl100k_base) and returns token counts, character counts, and density in a unified JSON format.

What it stabilizes

Token counting becomes unreliable when teams mix models, encodings, or ad hoc local scripts. UTC provides one API surface for consistent token, character, and density metrics in logging, budgeting, and prompt validation flows.

Hosted API on RapidAPI

UTC is available on RapidAPI.

🔗 RapidAPI Hub: https://rapidapi.com/APIronlab/api/universal-token-counter-utc

Endpoint

POST /utc/v0/token-count

Request example:

{
  "model": "gpt-4o",
  "text": "これはテストです"
}

Response example:

{
  "result": {
    "model": "gpt-4o",
    "encoding": "o200k_base",
    "char_count": 8,
    "token_count": 5,
    "token_per_char": 0.625
  },
  "meta": {
    "input_language": "ja",
    "input_size_bytes": 17,
    "token_density": 0.294,
    "model_family": "openai",
    "processing_time_ms": 3.24,
    "utc_timestamp": "2025-01-01T00:00:00Z",
    "version": "0.1.0"
  }
}

Supported Models (example)

Model Encoding
gpt-4o o200k_base
gpt-4.1 o200k_base
gpt-4.1-mini o200k_base
gpt-4 cl100k_base
gpt-3.5-turbo cl100k_base

See the GitHub repository or RapidAPI documentation for the actual list of supported models.

Use Cases

Quick Start – Python Example

import requests

payload = {
    "model": "gpt-4o",
    "text": "これはテストです",
}

res = requests.post(
    "https://your-endpoint/utc/v0/token-count",  # RapidAPI / API Gateway etc.
    json=payload,
)
print(res.json())

Links