x402-tools: POST /count-tokens
Count the number of tokens a string uses for an LLM, using the same BPE encodings the major models use (o200k_base for GPT-4o/o1, cl100k_base for GPT-4/3.5 and embeddings). Optionally pass a USD price per million tokens to get an estimated cost. Lets an agent budget context and spend before a call.
Start with a quote-only recipe. Payment signing stays in your project.
const response = await fetch("https://x402.nichospt.net/count-tokens", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
"type": "http",
"method": "POST",
"bodyType": "json",
"bodyFieldNames": [
"encoding",
"price_per_1m",
"text"
],
"pathParamNames": [],
"queryParamNames": []
}),
});
console.log(response.status);
console.log(Object.fromEntries(response.headers));
console.log((await response.text()).slice(0, 1000));
// A valid 402 is a quote, not a completed paid call.Review the provider input schema before running this non-read-only method. No payment code is included.
- Exact route checked
not safely testable · potentially-mutating-method:POST
- Origin reachable
HEAD https://x402.nichospt.net/ returned 200.
- Observed in cdp-bazaar
The registry record was observed and retained with provenance.
EVIDENCE
Each record has an exact-route quote outcome. Unresolved templates and potentially mutating methods are labeled instead of being invoked without provider-specific test input. A quote is still separate from a settled paid call.