# x402 Utils

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

Paid per call over x402 in USDC (eip155:8453); no account or API key. 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.

## Endpoints

### GET https://utils.kagurazaka.dev/v1/time ($0.001 USDC)

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.

Input (query parameters):
  - `tz` (string): comma separated IANA zones (up to 10), such as Asia/Tokyo,America/New_York; default UTC
  - `at` (string): ISO 8601 time with offset, unix seconds, or a local time such as 2026-10-25 09:00 (with from_tz); default now
  - `from_tz` (string): the zone of a local time in at

Example input:

```json
{"tz":"America/New_York,Europe/London","at":"2026-10-25 09:00","from_tz":"Asia/Tokyo"}
```

### GET https://utils.kagurazaka.dev/v1/date ($0.001 USDC)

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.

Input (query parameters):
  - `start` (string, required): a date such as 2026-10-25, or an ISO 8601 time
  - `add` (string): an ISO 8601 duration to add, such as P1M10D
  - `subtract` (string): an ISO 8601 duration to subtract
  - `end` (string): a second date, to count the time between
  - `country` (string): ISO country code whose public holidays are not business days, such as JP

Example input:

```json
{"start":"2026-10-25","end":"2026-12-25","country":"JP"}
```

### GET https://utils.kagurazaka.dev/v1/holidays ($0.001 USDC)

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.

Input (query parameters):
  - `country` (string, required): ISO 3166-1 alpha-2 code, such as JP, US, DE
  - `year` (integer): the year (1970-2100), default this year
  - `state` (string): state or region code, such as CA for the US
  - `lang` (string): language of the names, such as en or ja

Example input:

```json
{"country":"JP","year":2026,"lang":"en"}
```

### GET https://utils.kagurazaka.dev/v1/cron ($0.001 USDC)

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 #).

Input (query parameters):
  - `expr` (string, required): the cron expression, such as 0 9 * * 1-5
  - `tz` (string): IANA time zone, default UTC
  - `count` (integer): how many next runs (1-50, default 5)

Example input:

```json
{"expr":"0 9 * * 1-5","tz":"Asia/Tokyo","count":3}
```

### GET https://utils.kagurazaka.dev/v1/convert ($0.001 USDC)

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.

Input (query parameters):
  - `value` (number, required): the value
  - `from` (string, required): the unit, such as mi, lb, degF, GB
  - `to` (string, required): the target unit, such as km, kg, degC, MiB

Example input:

```json
{"value":26.2,"from":"mi","to":"km"}
```

### GET https://utils.kagurazaka.dev/v1/math ($0.001 USDC)

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.

Input (query parameters):
  - `expr` (string, required): the expression, such as 0.1 + 0.2 or sqrt(2) * 10^20 (up to 500 characters)

Example input:

```json
{"expr":"0.1 + 0.2"}
```

### GET https://utils.kagurazaka.dev/v1/phone ($0.001 USDC)

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

Input (query parameters):
  - `number` (string, required): the phone number, international (+81 3-1234-5678) or national with country
  - `country` (string): ISO country code for national numbers, such as JP

Example input:

```json
{"number":"+1 650 253 0000"}
```

### GET https://utils.kagurazaka.dev/v1/id ($0.001 USDC)

Generate random IDs from a cryptographic source: UUID v4, UUID v7 (time ordered), ULID or nanoid, up to 100 at a time.

Input (query parameters):
  - `type` (string): kind of ID (default uuid4)
  - `count` (integer): how many (1-100, default 1)

Example input:

```json
{"type":"uuid7","count":2}
```

### POST https://utils.kagurazaka.dev/v1/hash ($0.001 USDC)

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.

Input (JSON body):
  - `text` (string, required): what to hash (up to 1 MB)
  - `input` (string): how text is encoded (default utf8)
  - `algorithms` (array): which hashes (default all)

Example input:

```json
{"text":"hello","algorithms":["sha256","keccak256"]}
```

### POST https://utils.kagurazaka.dev/v1/encode ($0.001 USDC)

Encode or decode text: base64, base64url, hex, URL (percent) encoding and HTML escaping.

Input (JSON body):
  - `text` (string, required): the text (up to 1 MB)
  - `op` (string, required): what to do

Example input:

```json
{"text":"hello world","op":"base64-encode"}
```

### POST https://utils.kagurazaka.dev/v1/jwt ($0.001 USDC)

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.

Input (JSON body):
  - `token` (string, required): the JWT

Example input:

```json
{"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjMiLCJleHAiOjE3OTI4ODY0MDB9.sig"}
```

### POST https://utils.kagurazaka.dev/v1/json-schema ($0.001 USDC)

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.

Input (JSON body):
  - `schema` (object, required): the JSON Schema
  - `data` (any, required): the JSON value to check

Example input:

```json
{"schema":{"type":"object","required":["email"],"properties":{"email":{"type":"string","format":"email"}}},"data":{"email":"not-an-email"}}
```

### POST https://utils.kagurazaka.dev/v1/regex ($0.001 USDC)

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

Input (JSON body):
  - `pattern` (string, required): the pattern (up to 2000 characters)
  - `flags` (string): any of i (ignore case), m (multiline), s (dot matches newline)
  - `text` (string, required): the text (up to 1 MB)
  - `replacement` (string): optional replacement, $1 for groups

Example input:

```json
{"pattern":"(?P<year>\\d{4})-(\\d{2})","text":"from 2026-10 to 2027-01","replacement":"$2/$1"}
```

### POST https://utils.kagurazaka.dev/v1/tokens ($0.001 USDC)

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.

Input (JSON body):
  - `text` (string, required): the text (up to 1 MB)
  - `encodings` (array): which encodings (default both)

Example input:

```json
{"text":"Agents pay for APIs with x402."}
```

### POST https://utils.kagurazaka.dev/v1/diff ($0.001 USDC)

Compare two texts by lines, words or characters: what was added and removed, and a unified diff for lines.

Input (JSON body):
  - `a` (string, required): the old text
  - `b` (string, required): the new text
  - `mode` (string): unit of comparison (default lines)

Example input:

```json
{"a":"one\ntwo\nthree\n","b":"one\n2\nthree\nfour\n"}
```

## Discovery

- OpenAPI: https://utils.kagurazaka.dev/openapi.json
- x402 resources: https://utils.kagurazaka.dev/.well-known/x402
