81trust / 100
Token Count
by Token count in Onchain & crypto
x402 APIPassing, checked 2 h ago
Count exact LLM tokens for a string using the real OpenAI BPE (o200k_base for gpt-4o/o-series, cl100k_base for gpt-4/gpt-3.5). Deterministic, offline - budget context windows without calling a model.
POST https://agent402.tools/api/token-count
Last 30 days
All checks passedSome failedAll failedNot checked
- Uptime
- 100%
- Response time
- 199 ms typical, 199 ms slowest 5%
- Last check
- 2 h ago
- Next check
- any minute now
How to call it
# See the payment challenge (nothing is charged)
curl -i -X POST "https://agent402.tools/api/token-count" \
-H "content-type: application/json" \
-d '{"model":"gpt-4o","text":"hello world"}'import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client().register(
"eip155:8453",
new ExactEvmScheme(privateKeyToAccount(process.env.AGENT_KEY)),
);
const pay = wrapFetchWithPayment(fetch, client);
// Not sure it's safe to pay? Preflight it first for $0.005:
// GET https://toolvet.app/api/v1/check?url=https%3A%2F%2Fagent402.tools%2Fapi%2Ftoken-count
const res = await pay("https://agent402.tools/api/token-count", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({"model":"gpt-4o","text":"hello world"}),
});
console.log(await res.json());Example input
{
"model": "gpt-4o",
"text": "hello world"
}Example output
{
"characters": 11,
"encoding": "o200k_base",
"model": "gpt-4o",
"tokens": 2
}Security scan
- No findings. We scan names, descriptions and tool definitions for hidden instructions and other prompt-injection patterns.
Recent checks
| When | Result | HTTP | Time | Price |
|---|---|---|---|---|
| 2 h ago | Passed | 402 | 199 ms | $0.001 |
| 6 h ago | Passed | 402 | 230 ms | $0.001 |
| 11 h ago | Passed | 402 | 195 ms | $0.001 |