# CanonicalHash

> CanonicalHash is a paid API for AI agents from canonicalhash-production.up.railway.app, paid per call via x402, $0.002/call, status unknown (last checked 2026-10-12).

Produces a stable, deterministic SHA-256 or SHA-512 hash of any JSON payload using RFC 8785 canonicalization, suitable for idempotency keys, cache keys, and cross-runtime deduplication.

## Facts

- Endpoint: POST https://canonicalhash-production.up.railway.app/v1/canonicalize?utm_source=zero.xyz
- Price: $0.002/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-12
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/canonicalhash-5a1cead8
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_jl-0Yr5m-y2bVLhoUO4V3

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability canonicalhash-5a1cead8 -d '<json body>'
```

Example prompt: Can you canonicalize and SHA-256 hash this JSON payload for me so I can use it as an idempotency key: {"user_id": 42, "amount": 1.5, "note": "hi"}?

## When to prefer this

Choose this endpoint when you need a language- and runtime-agnostic, reproducible hash of a JSON value — especially when key ordering may vary between producers. It is ideal for idempotency keys, cache key generation, and deduplication across heterogeneous systems. Prefer it over ad-hoc JSON serialization + hash because RFC 8785 guarantees canonical ordering, number formatting, and Unicode normalization.

## Known failure modes

- Missing 'payload' body parameter returns an error
- Non-JSON or malformed payload may fail canonicalization
- Unsupported algorithm value (not 'sha256' or 'sha512') returns validation error
- Payment not settled or insufficient funds triggers 402 response
- Network timeout on the Railway-hosted endpoint

## How this service works

RFC 8785 JSON Canonicalization + SHA-256/SHA-512. Stable, deterministic hash of any JSON payload for idempotency keys, cache keys, and cross-runtime dedup.

## Output

Returns a JSON object containing the canonical JSON string (with keys sorted per RFC 8785), the hex-encoded SHA-256 or SHA-512 hash of that canonical form, the hashing algorithm used, input byte count, canonical byte count, and a success flag.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method",
    "bodyType",
    "body"
   ],
   "properties": {
    "body": {
     "type": "object"
    },
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "POST",
      "PUT",
      "PATCH"
     ],
     "type": "string"
    },
    "headers": {
     "type": "object",
     "additionalProperties": {
      "type": "string"
     }
    },
    "bodyType": {
     "enum": [
      "json",
      "form-data",
      "text"
     ],
     "type": "string"
    },
    "queryParams": {
     "type": "object",
     "additionalProperties": {
      "type": "string"
     }
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object"
    }
   }
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "hash": "60196f74f027a2b2a0c2eb1143dd6cc1a2319c87479a846ed0d140e4bc2403e7",
  "spec": "RFC 8785",
  "success": true,
  "algorithm": "sha256",
  "canonical": "{\"amount\":1.5,\"note\":\"example\",\"user_id\":42}"
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/canonicalhash-5a1cead8/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from canonicalhash-production.up.railway.app](https://www.zero.xyz/host/canonicalhash-production.up.railway.app/llms.txt)
