Namazu API
Crowdsourced seismic sensing, structural tensor modeling, and real-time earthquake alerts — open to any developer. Integrate shake detection into your app and join the world's most precise distributed seismograph network.
Overview
The Namazu API lets your application submit accelerometer data, receive earthquake alerts, and participate in the TGL (Tensor Generating Logic) competition — where algorithms that best model building structural tensors win Namazu tokens.
https://api.namazu.zweichain.net/v3All requests use HTTPS. All responses are JSON. Timestamps are ISO 8601 UTC.
iOS SDK — NamazuKit (Swift)
Add as a Swift Package in Xcode. Any iOS app becomes a Namazu sensor with two lines.
Install
Xcode → File → Add Package Dependencies → paste URL:
https://github.com/zweispace/namazukit-ios
Usage
// AppDelegate.swift — two lines
import NamazuKit
NamazuKit.shared.configure(token: "nmz_live_xxxxxxxxxxxx")
NamazuKit.shared.start()
// Optional: building context (improves tensor accuracy)
NamazuKit.shared.setBuilding(id: "bld_01HXYZ", floor: 2)
// Optional: callback when shake submitted
NamazuKit.shared.onShakeSubmitted = { response in
print("tokens earned:", response["tokens_earned"])
}
https://api.namazu.zweichain.net/v3/shake/ automatically. Device UUID is generated once and persisted.
Android SDK — NamazuKit (Kotlin)
Add as a Gradle dependency. Same two-line integration.
Install
// build.gradle
dependencies {
implementation("net.zweichain:namazukit:1.0.0")
}
Usage
// Application.kt — two lines
import net.zweichain.namazukit.NamazuKit
NamazuKit.configure(this, token = "nmz_live_xxxxxxxxxxxx")
NamazuKit.start()
// Optional
NamazuKit.setBuilding(id = "bld_01HXYZ", floor = 2)
NamazuKit.onShakeSubmitted = { response -> println(response) }
SensorManager + TYPE_ACCELEROMETER at fastest available rate. No special permissions beyond ACCESS_FINE_LOCATION.
Authentication
Every request requires a Namazu Token in the Authorization header.
Authorization: Bearer nmz_live_xxxxxxxxxxxxxxxxxxxx
| Token Type | Access |
|---|---|
| nmz_live_... | Full access — submit data, receive alerts, enter TGL competition |
| nmz_test_... | Sandbox — explore the API, no data enters the live network |
nmz_test_ token immediately. For live access, contact hayato.kameta@gmail.com.Quickstart
Send your first shake event in under 5 minutes:
# 1. Submit a shake event
curl -X POST https://api.namazu.zweichain.net/v3/shake \
-H "Authorization: Bearer nmz_test_your_token" \
-H "Content-Type: application/json" \
-d '{
"device_id": "your-device-uuid",
"lat": 34.6937,
"lon": 135.5023,
"alt_m": 50,
"timestamp": "2026-05-14T13:00:00.000Z",
"samples": [
{ "t_ms": 0, "x": 0.012, "y": -0.003, "z": 9.814 },
{ "t_ms": 10, "x": 0.045, "y": 0.021, "z": 9.802 },
{ "t_ms": 20, "x": 0.231, "y": 0.198, "z": 9.756 }
],
"sample_rate_hz": 100
}'
POST /shake
Submit accelerometer samples from a device. Called when shake threshold is exceeded.
Request Body
| Field | Type | Description |
|---|---|---|
| device_id | string | required Unique device UUID (persist across sessions) |
| lat | float | required Latitude WGS84 |
| lon | float | required Longitude WGS84 |
| alt_m | float | optional Altitude in metres |
| floor | integer | optional Floor number (0 = ground). Improves tensor modeling. |
| building_id | string | optional If device is in a registered building |
| timestamp | string | required ISO 8601 UTC — event start time |
| samples | array | required Accelerometer readings (see below) |
| sample_rate_hz | integer | required Sampling rate — smartphone: 100Hz typical, IoT sensor: up to 1000Hz (1ms precision). Aerospace-grade MEMS sensors supported. |
Sample Object
| Field | Type | Description |
|---|---|---|
| t_ms | integer | Milliseconds offset from event timestamp |
| x | float | Acceleration m/s² — device X axis |
| y | float | Acceleration m/s² — device Y axis |
| z | float | Acceleration m/s² — device Z axis (gravity ~9.81) |
Response
{
"event_id": "evt_01HXYZ...",
"status": "accepted",
"cluster_id": "clust_osaka_20260514", // null if no cluster yet
"intensity_estimate": 2.3, // JMA scale estimate
"tokens_earned": 0.5 // NMZ tokens for this submission
}
GET /shake/events
Query recent shake events by location and time.
Query Parameters
| Param | Type | Description |
|---|---|---|
| lat, lon | float | required Center point |
| radius_km | float | optional Search radius (default 50km) |
| since | string | optional ISO 8601 start time |
| min_intensity | float | optional Minimum JMA intensity |
| limit | integer | optional Max results (default 50, max 500) |
POST /building
Register a building to enable floor-by-floor tensor modeling and digital twin generation.
{
"name": "Osaka City Hall Annex",
"lat": 34.6937,
"lon": 135.5023,
"floors": 3,
"construction_year": 1978,
"structure_type": "wooden", // wooden | rc | steel | src
"sensors_per_floor": 3
}
GET /building/:id/tensor
Returns the current best structural tensor for a building — the inter-floor stiffness/damping coefficients computed by the leading TGL algorithm.
{
"building_id": "bld_01HXYZ...",
"computed_at": "2026-05-14T12:00:00Z",
"tgl_id": "tgl_lagrangian_v4", // which TGL produced this
"floors": 3,
"tensor": {
"K": [[2.41, -1.20, 0.0], // stiffness matrix
[-1.20, 2.41, -1.20],
[0.0, -1.20, 1.20]],
"C": [[0.05, -0.02, 0.0], // damping matrix
[-0.02, 0.05, -0.02],
[0.0, -0.02, 0.03]],
"confidence": 0.87
},
"risk_class": "moderate" // excellent|good|moderate|poor|critical
}
POST /tgl/sandbox
Check a GitHub repository for malicious code before submitting as a TGL. Clones the repo and runs static security analysis. HIGH severity issues block submission. MEDIUM issues are reported but do not block.
# Request
{ "repo_url": "https://github.com/you/your-tgl" }
# Clean response (200)
{ "status": "clean", "high": 0, "medium": 2, "message": "No high-severity issues found. TGL approved to run." }
# Flagged response (400)
{ "status": "flagged", "reason": "2 HIGH severity issue(s) found.", "high": [...] }
Authorization: Bearer nmz_live_... token.TGL Competition
TGL (Tensor Generating Logic) is Namazu's open competition for structural system identification algorithms. Submit your algorithm, have it tested against real multi-floor sensor data, and earn Namazu tokens if your TGL outperforms others at predicting inter-floor shake propagation.
Writing a TGL — Developer Guide
A TGL is a Python function that models the building as a coupled oscillator system. The equation of motion is:
# M·ẍ(t) + C·ẋ(t) + K·x(t) = f(t)
# Your job: identify K (stiffness) and C (damping) from sensor data.
Your file must expose a predict(shake, floors) function:
# my_tgl.py
import numpy as np
def predict(shake: list[float], floors: int) -> dict:
"""
shake : flat float array — accelerometer samples (x,y,z at 100Hz, all floors merged)
floors: number of floors in the building model
returns: dict with keys 'tensor' (K matrix as nested list) and 'optimized_k' (float)
"""
n = floors
K = np.eye(n).tolist() # replace with your fitted stiffness matrix
C = (np.eye(n) * 0.05).tolist() # replace with your fitted damping matrix
k_opt = float(np.mean(np.diag(np.array(K))))
return {"tensor": K, "optimized_k": k_opt, "damping": C}
• Use Lagrangian mechanics — model each floor as a mass connected by springs (K) and dampers (C).
• Fit K by minimising residuals between predicted and observed inter-floor acceleration.
• The Z-TGL baseline uses eigenvalue decomposition of the empirical covariance matrix of the floor signals.
• You may use any library available in standard
python:3.12-slim + numpy/scipy.• No internet access during scoring — all dependencies must be in the file or stdlib.
POST /tgl/sandbox
Scan a GitHub repository for security issues before submitting. Flagged TGLs are still accepted — the scan is informational only.
{ "repo_url": "https://github.com/you/your-tgl" }
{ "status": "clean", "high": 0, "medium": 0, "message": "No high-severity issues found." }
POST /tgl/upload
Upload a single .py file directly — no GitHub account needed. Gets a tgl_id you can use in the Simulation UI or API.
curl -X POST https://api.namazu.zweichain.net/v3/tgl/upload/ \
-F "file=@my_tgl.py" \
-F "name=My TGL v1"
{
"tgl_id": "tgl_01HXYZ...",
"name": "My TGL v1",
"sandbox": "clean",
"usable": true,
"message": "✓ Clean — ready to use."
}
POST /tgl/submit
{
"name": "My Lagrangian TGL v1",
"description": "Uses Lagrangian mechanics to identify modal frequencies...",
"language": "python",
"entrypoint": "tgl.predict",
"code_url": "https://github.com/you/your-tgl",
"docker_image": "ghcr.io/you/tgl:latest" // optional
}
samples[floor][sensor] → {t_ms, x, y, z}[] and must return predicted acceleration for the target floor over the next 500ms. Interface spec: see schema.GET /tgl/leaderboard
{
"updated_at": "2026-05-14T12:00:00Z",
"entries": [
{
"rank": 1,
"tgl_id": "tgl_lagrangian_v4",
"name": "Lagrangian Modal Decomposition v4",
"author": "namazu_core",
"rmse": 0.0023,
"events_tested": 1482,
"tokens_earned": 12400
}
]
}
Earthquake Alerts
Subscribe to real-time alerts via WebSocket. Alerts fire when the Namazu network detects a cluster of shake events consistent with an earthquake.
# Connect
wss://api.namazu.zweichain.net/v3/alerts?token=nmz_live_xxx&lat=34.69&lon=135.50&radius_km=100
# Alert message received:
{
"type": "earthquake_alert",
"alert_id": "alrt_01HXYZ",
"issued_at": "2026-05-14T13:00:00.000Z",
"epicenter": { "lat": 34.71, "lon": 135.49 },
"depth_km": 12,
"magnitude_estimate": 4.2,
"intensity_at_location": 2.8,
"seconds_to_arrival": 18,
"confidence": 0.91
}
Error Codes
| Code | Meaning |
|---|---|
| 401 | Invalid or missing token |
| 422 | Malformed request body — check field types |
| 429 | Rate limit exceeded (100 req/min on free tier) |
| 503 | Network partition — retry with exponential backoff |