{"openapi":"3.1.0","info":{"title":"x402 Utils","version":"1.0.0","description":"Exact utilities for agents, paid per call in USDC on Base: time zones and DST, date arithmetic and business days, holidays, cron schedules, unit conversion, exact math, phone number validation, IDs, hashes, encodings, JWT decoding, JSON Schema validation, regular expressions, LLM token counts and text diffs. Invalid input is not charged.","x-guidance":"GET endpoints take query parameters; POST endpoints (hash, encode, jwt, json-schema, regex, tokens, diff) take a JSON body. A 400 answer means the input was invalid; no payment is settled for it."},"servers":[{"url":"https://utils.kagurazaka.dev"}],"paths":{"/v1/time":{"get":{"operationId":"getTime","summary":"Time in any time zones, or convert a time between zones","description":"The current time, or a given time, in one or more IANA time zones, with UTC offset, abbreviation, whether daylight saving time is in effect, and the weekday. Give a local time with from_tz to convert it, handling DST correctly.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"utc":{},"unix":{},"zones":{}}},"example":{"utc":"2026-10-25T00:00:00.000Z","unix":1792886400,"zones":[{"tz":"America/New_York","local":"2026-10-24T20:00:00","offset":"-04:00","abbreviation":"EDT","dst":true,"weekday":"Saturday"}]}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"tz","in":"query","required":false,"schema":{"type":"string","description":"comma separated IANA zones (up to 10), such as Asia/Tokyo,America/New_York; default UTC"}},{"name":"at","in":"query","required":false,"schema":{"type":"string","description":"ISO 8601 time with offset, unix seconds, or a local time such as 2026-10-25 09:00 (with from_tz); default now"}},{"name":"from_tz","in":"query","required":false,"schema":{"type":"string","description":"the zone of a local time in at"}}]}},"/v1/date":{"get":{"operationId":"getDate","summary":"Date arithmetic: add a duration, or the time between two dates","description":"Add or subtract an ISO 8601 duration (P1M, P2W, PT36H) to a date, months clamped to the month's end; or count the days, weeks, calendar months, years, seconds and business days (Monday to Friday, less a country's public holidays) between two dates. Also the weekday, ISO week and day of year.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"start":{},"between":{}}},"example":{"start":{"date":"2026-10-25","weekday":"Sunday","iso_week":43},"between":{"days":61,"months":2,"business_days":42}}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"start","in":"query","required":true,"schema":{"type":"string","description":"a date such as 2026-10-25, or an ISO 8601 time"}},{"name":"add","in":"query","required":false,"schema":{"type":"string","description":"an ISO 8601 duration to add, such as P1M10D"}},{"name":"subtract","in":"query","required":false,"schema":{"type":"string","description":"an ISO 8601 duration to subtract"}},{"name":"end","in":"query","required":false,"schema":{"type":"string","description":"a second date, to count the time between"}},{"name":"country","in":"query","required":false,"schema":{"type":"string","description":"ISO country code whose public holidays are not business days, such as JP"}}]}},"/v1/holidays":{"get":{"operationId":"getHolidays","summary":"Public holidays of a country in a year","description":"Holidays of a country (and optionally a state or region) in a year, with date, name and type (public, bank, school, optional, observance), from the date-holidays data for about 200 countries.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"country":{},"year":{},"public_holidays":{},"holidays":{}}},"example":{"country":"JP","year":2026,"public_holidays":16,"holidays":[{"date":"2026-01-01","name":"New Year's Day","type":"public"}]}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"country","in":"query","required":true,"schema":{"type":"string","description":"ISO 3166-1 alpha-2 code, such as JP, US, DE"}},{"name":"year","in":"query","required":false,"schema":{"type":"integer","description":"the year (1970-2100), default this year"}},{"name":"state","in":"query","required":false,"schema":{"type":"string","description":"state or region code, such as CA for the US"}},{"name":"lang","in":"query","required":false,"schema":{"type":"string","description":"language of the names, such as en or ja"}}]}},"/v1/cron":{"get":{"operationId":"getCron","summary":"Next run times of a cron expression, in plain words","description":"Explain a cron expression in plain English and list its next run times in a time zone (5 or 6 fields, with ranges, steps, L, W and #).","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"description":{},"next":{}}},"example":{"description":"At 09:00, Monday through Friday","next":[{"utc":"2026-10-26T00:00:00.000Z","local":"2026-10-26T09:00:00"}]}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"expr","in":"query","required":true,"schema":{"type":"string","description":"the cron expression, such as 0 9 * * 1-5"}},{"name":"tz","in":"query","required":false,"schema":{"type":"string","description":"IANA time zone, default UTC"}},{"name":"count","in":"query","required":false,"schema":{"type":"integer","description":"how many next runs (1-50, default 5)"}}]}},"/v1/convert":{"get":{"operationId":"getConvert","summary":"Convert units","description":"Convert a value between units of length, mass, volume, temperature, speed, area, energy, power, pressure, data size, time and more (mathjs units), such as mi to km, degF to degC, GB to MiB, kWh to J.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"value":{},"from":{},"to":{},"result":{},"text":{}}},"example":{"value":26.2,"from":"mi","to":"km","result":42.1648128,"text":"42.1648128 km"}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"value","in":"query","required":true,"schema":{"type":"number","description":"the value"}},{"name":"from","in":"query","required":true,"schema":{"type":"string","description":"the unit, such as mi, lb, degF, GB"}},{"name":"to","in":"query","required":true,"schema":{"type":"string","description":"the target unit, such as km, kg, degC, MiB"}}]}},"/v1/math":{"get":{"operationId":"getMath","summary":"Evaluate a math expression exactly","description":"Evaluate an arithmetic expression with 64 significant digits (no floating point surprises): operators, parentheses, powers, roots, logs, trigonometry, percentages, constants, units (5 inch to cm) and simple statistics.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"expr":{},"result":{},"number":{},"type":{}}},"example":{"expr":"0.1 + 0.2","result":"0.3","number":0.3,"type":"BigNumber"}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"expr","in":"query","required":true,"schema":{"type":"string","description":"the expression, such as 0.1 + 0.2 or sqrt(2) * 10^20 (up to 500 characters)"}}]}},"/v1/phone":{"get":{"operationId":"getPhone","summary":"Validate and format a phone number","description":"Check whether a phone number is valid and possible, find its country and type (mobile, fixed line, toll free and others), and format it as E.164, international and national (libphonenumber metadata).","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"valid":{},"country":{},"type":{},"e164":{},"international":{},"national":{}}},"example":{"valid":true,"country":"US","type":"FIXED_LINE_OR_MOBILE","e164":"+16502530000","international":"+1 650 253 0000","national":"(650) 253-0000"}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"number","in":"query","required":true,"schema":{"type":"string","description":"the phone number, international (+81 3-1234-5678) or national with country"}},{"name":"country","in":"query","required":false,"schema":{"type":"string","description":"ISO country code for national numbers, such as JP"}}]}},"/v1/id":{"get":{"operationId":"getId","summary":"Generate UUIDs, ULIDs or nanoids","description":"Generate random IDs from a cryptographic source: UUID v4, UUID v7 (time ordered), ULID or nanoid, up to 100 at a time.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"type":{},"ids":{}}},"example":{"type":"uuid7","ids":["019a1b2c-3d4e-7f00-8a1b-2c3d4e5f6a7b"]}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"parameters":[{"name":"type","in":"query","required":false,"schema":{"type":"string","enum":["uuid4","uuid7","ulid","nanoid"],"description":"kind of ID (default uuid4)"}},{"name":"count","in":"query","required":false,"schema":{"type":"integer","description":"how many (1-100, default 1)"}}]}},"/v1/hash":{"post":{"operationId":"postHash","summary":"Hash text or bytes","description":"MD5, SHA-1, SHA-256, SHA-512, SHA3-256 and Keccak-256 (Ethereum) of a text, or of bytes given as hex or base64, as hex and base64.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"bytes":{},"sha256":{},"keccak256":{}}},"example":{"bytes":5,"sha256":{"hex":"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"},"keccak256":{"hex":"1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"}}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string","description":"what to hash (up to 1 MB)"},"input":{"type":"string","enum":["utf8","hex","base64"],"description":"how text is encoded (default utf8)"},"algorithms":{"type":"array","items":{"type":"string","enum":["md5","sha1","sha256","sha512","sha3-256","keccak256"]},"description":"which hashes (default all)"}},"required":["text"]},"example":{"text":"hello","algorithms":["sha256","keccak256"]}}}}}},"/v1/encode":{"post":{"operationId":"postEncode","summary":"Encode or decode base64, base64url, hex, URL or HTML","description":"Encode or decode text: base64, base64url, hex, URL (percent) encoding and HTML escaping.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"op":{},"result":{}}},"example":{"op":"base64-encode","result":"aGVsbG8gd29ybGQ="}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string","description":"the text (up to 1 MB)"},"op":{"type":"string","enum":["base64-encode","base64-decode","base64url-encode","base64url-decode","hex-encode","hex-decode","url-encode","url-decode","html-escape","html-unescape"],"description":"what to do"}},"required":["text","op"]},"example":{"text":"hello world","op":"base64-encode"}}}}}},"/v1/jwt":{"post":{"operationId":"postJwt","summary":"Decode a JWT","description":"Decode a JSON Web Token's header and claims, and say when it was issued, when it expires, whether it has expired and in how many seconds it will. The signature is not verified.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"algorithm":{},"payload":{},"expires_at":{},"expired":{}}},"example":{"algorithm":"HS256","payload":{"sub":"123","exp":1792886400},"expires_at":"2026-10-25T00:00:00.000Z","expired":false}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"token":{"type":"string","description":"the JWT"}},"required":["token"]},"example":{"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjMiLCJleHAiOjE3OTI4ODY0MDB9.sig"}}}}}},"/v1/json-schema":{"post":{"operationId":"postJsonSchema","summary":"Validate JSON against a JSON Schema","description":"Validate a JSON value against a JSON Schema (draft-07 and 2019-09 keywords, formats such as email, uri, date-time) and list every error with its path. Patterns run on RE2, so a schema cannot stall the check.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"valid":{},"error_count":{},"errors":{}}},"example":{"valid":false,"error_count":1,"errors":[{"path":"/email","message":"must match format \"email\"","keyword":"format"}]}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"schema":{"type":"object","description":"the JSON Schema"},"data":{"description":"the JSON value to check"}},"required":["schema","data"]},"example":{"schema":{"type":"object","required":["email"],"properties":{"email":{"type":"string","format":"email"}}},"data":{"email":"not-an-email"}}}}}}},"/v1/regex":{"post":{"operationId":"postRegex","summary":"Test a regular expression","description":"Run a regular expression on a text: every match with its position and capture groups (named too), and the text with a replacement applied. RE2 syntax, which runs in linear time (no lookaround or backreferences).","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"matched":{},"count":{},"matches":{},"replaced":{}}},"example":{"matched":true,"count":2,"matches":[{"index":5,"match":"2026-10","groups":["2026","10"],"named":{"year":"2026"}}],"replaced":"from 10/2026 to 01/2027"}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"pattern":{"type":"string","description":"the pattern (up to 2000 characters)"},"flags":{"type":"string","description":"any of i (ignore case), m (multiline), s (dot matches newline)"},"text":{"type":"string","description":"the text (up to 1 MB)"},"replacement":{"type":"string","description":"optional replacement, $1 for groups"}},"required":["pattern","text"]},"example":{"pattern":"(?P<year>\\d{4})-(\\d{2})","text":"from 2026-10 to 2027-01","replacement":"$2/$1"}}}}}},"/v1/tokens":{"post":{"operationId":"postTokens","summary":"Count LLM tokens in a text","description":"Count the tokens of a text for OpenAI models (o200k_base for GPT-4o and later, cl100k_base for GPT-4), with characters, words and lines, to size prompts and estimate cost.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"characters":{},"words":{},"tokens":{}}},"example":{"characters":30,"words":6,"tokens":{"o200k_base":9,"cl100k_base":9}}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string","description":"the text (up to 1 MB)"},"encodings":{"type":"array","items":{"type":"string","enum":["o200k_base","cl100k_base"]},"description":"which encodings (default both)"}},"required":["text"]},"example":{"text":"Agents pay for APIs with x402."}}}}}},"/v1/diff":{"post":{"operationId":"postDiff","summary":"Diff two texts","description":"Compare two texts by lines, words or characters: what was added and removed, and a unified diff for lines.","tags":["Utilities"],"x-payment-info":{"price":{"mode":"fixed","currency":"USD","amount":"0.001"},"protocols":[{"x402":{}}]},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"identical":{},"added":{},"removed":{},"changes":{},"unified":{}}},"example":{"identical":false,"added":2,"removed":1,"changes":[{"type":"removed","value":"two\n"},{"type":"added","value":"2\n"}],"unified":"--- a\n+++ b\n@@ ..."}}}},"400":{"description":"The input is invalid. No payment is settled."},"402":{"description":"Payment Required"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"a":{"type":"string","description":"the old text"},"b":{"type":"string","description":"the new text"},"mode":{"type":"string","enum":["lines","words","chars"],"description":"unit of comparison (default lines)"}},"required":["a","b"]},"example":{"a":"one\ntwo\nthree\n","b":"one\n2\nthree\nfour\n"}}}}}}}}