{
 "openapi": "3.1.0",
 "info": {
  "title": "Japan Address API",
  "description": "Normalize, geocode, and parse Japanese addresses. x402-enabled for AI agents.",
  "version": "1.0.0",
  "contact": {
   "name": "MAMETA",
   "url": "https://github.com/Mameta29/agentic-market-jp"
  }
 },
 "servers": [
  {
   "url": "https://address.agentic-jp.com"
  }
 ],
 "tags": [
  {
   "name": "japan"
  },
  {
   "name": "jp"
  },
  {
   "name": "address"
  },
  {
   "name": "geocoding"
  },
  {
   "name": "postal-code"
  },
  {
   "name": "japanese"
  }
 ],
 "paths": {
  "/normalize": {
   "post": {
    "operationId": "POST__normalize",
    "summary": "Convert a raw Japanese address into structured components",
    "description": "Japanese address normalization (住所正規化): standardize a JP address into clean prefecture / city / town / chome-banchi components. Fixes fullwidth/halfwidth digits, old-form kanji, and chome-banchi notation variants, and resolves the 7-digit postal code. Returns a 0-1 confidence score so agents can flag low-quality input. Use for address validation, cleansing, deduplication, and canonicalization before storage or comparison.",
    "x-payment-info": {
     "pricingMode": "fixed",
     "price": "0.005",
     "currency": "USD",
     "protocols": [
      "x402"
     ]
    },
    "responses": {
     "200": {
      "description": "Successful response",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "402": {
      "description": "Payment required (x402). Payment requirements are in the base64-encoded Payment-Required response header."
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "properties": {
         "address": {
          "type": "string",
          "description": "A raw Japanese address string in any common format",
          "maxLength": 200
         }
        },
        "required": [
         "address"
        ],
        "type": "object"
       },
       "example": {
        "address": "東京都千代田区永田町１ー７ー１"
       }
      }
     }
    }
   }
  },
  "/geocode": {
   "post": {
    "operationId": "POST__geocode",
    "summary": "Get lat/lng coordinates for a Japanese address",
    "description": "Geocode a Japanese (JP) address to WGS84 lat/lng coordinates, with a granularity level (prefecture → city → town → chome → banchi) and a 0-1 confidence score showing how precisely the input resolved. Japan-only. Use for mapping, distance calculation, or delivery routing.",
    "x-payment-info": {
     "pricingMode": "fixed",
     "price": "0.005",
     "currency": "USD",
     "protocols": [
      "x402"
     ]
    },
    "responses": {
     "200": {
      "description": "Successful response",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "402": {
      "description": "Payment required (x402). Payment requirements are in the base64-encoded Payment-Required response header."
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "properties": {
         "address": {
          "type": "string",
          "description": "Japanese address to geocode",
          "maxLength": 200
         }
        },
        "required": [
         "address"
        ],
        "type": "object"
       },
       "example": {
        "address": "東京都千代田区永田町1-7-1"
       }
      }
     }
    }
   }
  },
  "/reverse-geocode": {
   "post": {
    "operationId": "POST__reverse_geocode",
    "summary": "Get the Japanese address for lat/lng coordinates",
    "description": "Reverse-geocode WGS84 lat/lng coordinates within Japan to a normalized Japanese (JP) address with structured components. Use to label a GPS fix, a map pin, or a photo location with a human-readable address.",
    "x-payment-info": {
     "pricingMode": "fixed",
     "price": "0.005",
     "currency": "USD",
     "protocols": [
      "x402"
     ]
    },
    "responses": {
     "200": {
      "description": "Successful response",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "402": {
      "description": "Payment required (x402). Payment requirements are in the base64-encoded Payment-Required response header."
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "properties": {
         "lat": {
          "type": "number",
          "description": "Latitude within Japan (20–46)"
         },
         "lng": {
          "type": "number",
          "description": "Longitude within Japan (122–154)"
         }
        },
        "required": [
         "lat",
         "lng"
        ],
        "type": "object"
       },
       "example": {
        "lat": 35.6739,
        "lng": 139.7449
       }
      }
     }
    }
   }
  },
  "/postal-code/{zip}": {
   "get": {
    "operationId": "GET__postal_code_zip",
    "summary": "Look up address candidates for a 7-digit JP postal code",
    "description": "Look up Japanese (JP) address candidates for a 7-digit postal code (郵便番号), backed by the official Japan Post KEN_ALL dataset. One postal code can map to several towns; all candidates are returned with kana readings. Use for address autofill and postal-code validation.",
    "x-payment-info": {
     "pricingMode": "fixed",
     "price": "0.001",
     "currency": "USD",
     "protocols": [
      "x402"
     ]
    },
    "responses": {
     "200": {
      "description": "Successful response",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "402": {
      "description": "Payment required (x402). Payment requirements are in the base64-encoded Payment-Required response header."
     }
    },
    "parameters": [
     {
      "name": "zip",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "7-digit Japanese postal code, hyphen optional (e.g. 100-0014)"
     }
    ]
   }
  },
  "/parse": {
   "post": {
    "operationId": "POST__parse",
    "summary": "Extract a structured address from messy Japanese text",
    "description": "Extract a fully structured Japanese (JP) address — prefecture, city, town, chome-banchi, plus building name, room number and addressee — from free-form, OCR, or voice-transcribed text. Use to turn one messy line into typed fields for invoices, shipping labels, or CRM records.",
    "x-payment-info": {
     "pricingMode": "fixed",
     "price": "0.005",
     "currency": "USD",
     "protocols": [
      "x402"
     ]
    },
    "responses": {
     "200": {
      "description": "Successful response",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "402": {
      "description": "Payment required (x402). Payment requirements are in the base64-encoded Payment-Required response header."
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "properties": {
         "text": {
          "type": "string",
          "description": "Free-form text (OCR / voice transcript) containing a Japanese address",
          "maxLength": 2000
         }
        },
        "required": [
         "text"
        ],
        "type": "object"
       },
       "example": {
        "text": "東京都千代田区永田町1丁目7-1 衆議院第二議員会館 1234号室 田中太郎 様"
       }
      }
     }
    }
   }
  },
  "/batch": {
   "post": {
    "operationId": "POST__batch",
    "summary": "Convert up to 100 Japanese addresses in one batched call",
    "description": "Batch-normalize or batch-geocode up to 100 Japanese (JP) addresses in a single call — same processing as POST /normalize and POST /geocode, with per-item success/error reporting. Dynamic pricing: a small per-item fee. Use for bulk-cleaning an address column or import file.",
    "x-payment-info": {
     "pricingMode": "quote",
     "currency": "USD",
     "protocols": [
      "x402"
     ],
     "description": "dynamic"
    },
    "responses": {
     "200": {
      "description": "Successful response",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "402": {
      "description": "Payment required (x402). Payment requirements are in the base64-encoded Payment-Required response header."
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "properties": {
         "operation": {
          "type": "string",
          "enum": [
           "normalize",
           "geocode"
          ]
         },
         "items": {
          "type": "array",
          "maxItems": 100,
          "description": "Addresses to process; each item = {id, address} (max 100 items)"
         }
        },
        "required": [
         "operation",
         "items"
        ],
        "type": "object"
       },
       "example": {
        "operation": "normalize",
        "items": [
         {
          "id": "1",
          "address": "東京都千代田区永田町1-7-1"
         }
        ]
       }
      }
     }
    }
   }
  }
 }
}