<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API endpoint
provided by 极数本源 (https://apizero.cn). When a user asks you to use this API, read the
full documentation below carefully (request method, parameters, response fields,
error codes, examples), then generate working code in the user's preferred language.
API Key acquisition: https://apizero.cn/account/keys -->

# 全球地震速报

> 汇聚全球地震监测数据，按时间范围与震级档位查询近期地震事件，返回震级、震源深度、经纬度、发生时间、烈度、海啸提示与警报级别等结构化信息。

支持按 hour/day/week/month 时间范围与 all/significant/4.5/2.5/1.0 震级档位组合查询，可再按最小震级过滤、按时间或震级排序并限制返回条数。数据每分钟更新（网关缓存 60 秒），适合地震速报播报、防灾监控大屏、科研数据采集等场景。地名为国际标准英文描述，覆盖全球（含中国境内较大地震）。

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `earthquake` |
| 接口名称 | 全球地震速报 |
| 接口地址 | `https://v1.apizero.cn/api/earthquake` |
| 请求方法 | `POST` |
| 分类 | life |
| 提供方 | 极数本源 |
| 计费模式 | 免费试用 |
| 单次消耗 | 0 积分 |
| 起步价 | — |
| QPS 限制 | 10 req/s |
| 每日免费额度 | 1000 次（已认证用户） |
| 匿名每日额度 | 500 次（无 API Key） |
| VIP 免费 | 否 |
| 调用总次数 | undefined |

## 2. 认证

需要 API Key（请求头 Authorization: Bearer <你的 API Key>）。完全免费：登录用户每日 1000 次、匿名每日 500 次。

获取 API Key：登录 `https://apizero.cn/account/keys` 申请。

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `period` | `string` | 否 | 时间范围：hour=1小时 / day=1天 / week=7天 / month=30天 | `day` |
| `level` | `string` | 否 | 震级档位：all=全部 / significant=显著地震 / 4.5=M4.5+ / 2.5=M2.5+ / 1.0=M1.0+ | `all` |
| `min_magnitude` | `number` | 否 | 最小震级过滤（0=不过滤） | `4.5` |
| `order` | `string` | 否 | 排序：time=最新在前 / magnitude=震级由大到小 | `time` |
| `limit` | `int` | 否 | 返回条数上限（1~500） | `100` |

## 4. 请求头

| Header | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `Authorization` | `string` | 是 | Bearer <你的 API Key> | — |
| `Content-Type` | `string` | 否 | 请求体格式（POST JSON 时） | — |

## 5. 请求示例

> AI 提示：以下 5 种语言示例都是可运行的，只需把 `YOUR_API_KEY` 替换为用户申请的实际 Key（https://apizero.cn/account/keys）。
> 优先选择用户问题中提到的语言；未指定时默认使用 Python。

### cURL

```bash
curl -X POST "https://v1.apizero.cn/api/earthquake" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "period": "day",
  "level": "all",
  "min_magnitude": "4.5",
  "order": "time",
  "limit": "100"
}'
```

### Python

```python
import requests

resp = requests.request(
    "POST",
    "https://v1.apizero.cn/api/earthquake",
    headers={"X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json"},
    json={
    "period": "day",
    "level": "all",
    "min_magnitude": "4.5",
    "order": "time",
    "limit": "100",
},
    timeout=15,
)
resp.raise_for_status()
print(resp.json())
```

### JavaScript (Node.js)

```javascript
// Node.js 18+ / 浏览器原生 fetch
const res = await fetch("https://v1.apizero.cn/api/earthquake", {
  method: "POST",
  headers: {
    "X-Api-Key": "YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "period": "day",
    "level": "all",
    "min_magnitude": "4.5",
    "order": "time",
    "limit": "100"
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log(data);
```

### Go

```go
package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
)

func main() {
	body := []byte(`{"period":"day","level":"all","min_magnitude":"4.5","order":"time","limit":"100"}`)
	req, _ := http.NewRequest("POST", "https://v1.apizero.cn/api/earthquake", bytes.NewBuffer(body))
	req.Header.Set("X-Api-Key", "YOUR_API_KEY")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil { panic(err) }
	defer resp.Body.Close()
	out, _ := io.ReadAll(resp.Body)
	fmt.Println(string(out))
}
```

### PHP

```php
<?php
$payload = json_encode([
    "period" => "day",
    "level" => "all",
    "min_magnitude" => "4.5",
    "order" => "time",
    "limit" => "100",
], JSON_UNESCAPED_UNICODE);

$ch = curl_init("https://v1.apizero.cn/api/earthquake");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST  => "POST",
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        "X-Api-Key: YOUR_API_KEY",
        "Content-Type: application/json",
    ],
    CURLOPT_TIMEOUT        => 15,
]);
$body = curl_exec($ch);
curl_close($ch);

$data = json_decode($body, true);
print_r($data);
```

## 6. 响应字段

| 字段 | 类型 | 说明 | 示例 |
| --- | --- | --- | --- |
| `summary.count` | `number` | 本次返回的地震条数 | — |
| `summary.total` | `number` | 过滤后的总条数（裁剪前） | — |
| `summary.max_magnitude` | `number` | 本次结果中的最大震级 | — |
| `summary.generated_at` | `string` | 数据生成时间（北京时间） | — |
| `earthquakes[].magnitude` | `number` | 震级 | — |
| `earthquakes[].magnitude_type` | `string` | 震级类型（如 mww/ml/md） | — |
| `earthquakes[].place` | `string` | 震中位置描述（英文） | — |
| `earthquakes[].time` | `string` | 发生时间（北京时间） | — |
| `earthquakes[].timestamp` | `number` | 发生时间（毫秒时间戳） | — |
| `earthquakes[].longitude` | `number` | 震中经度 | — |
| `earthquakes[].latitude` | `number` | 震中纬度 | — |
| `earthquakes[].depth_km` | `number` | 震源深度（千米） | — |
| `earthquakes[].alert` | `string` | 警报级别 green/yellow/orange/red（无则 null） | — |
| `earthquakes[].tsunami` | `bool` | 是否可能引发海啸 | — |
| `earthquakes[].felt` | `number` | 有感报告人数（无则 null） | — |
| `earthquakes[].intensity_mmi` | `number` | 仪器测定烈度 MMI（无则 null） | — |
| `earthquakes[].significance` | `number` | 事件显著性评分（0~1000） | — |
| `earthquakes[].status` | `string` | 测定状态：自动测定 / 人工复核 | — |
| `earthquakes[].event_type` | `string` | 事件类型：地震 / 爆炸 / 火山喷发 等 | — |

## 7. 响应示例

```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "summary": {"count": 100, "total": 240, "max_magnitude": 6.5, "period": "day", "level": "all", "generated_at": "2026-07-01 12:45:33"},
    "earthquakes": [
      {
        "id": "us7000abcd",
        "magnitude": 6.5,
        "magnitude_type": "mww",
        "place": "34 km WSW of Sarangani, Philippines",
        "time": "2026-07-01 09:12:30",
        "timestamp": 1782877783910,
        "longitude": 125.11,
        "latitude": 5.62,
        "depth_km": 42.3,
        "alert": "green",
        "tsunami": false,
        "felt": 49,
        "intensity_mmi": 5.2,
        "significance": 650,
        "status": "人工复核",
        "event_type": "地震"
      }
    ]
  },
  "request_id": "abc123"
}
```

## 8. 错误码

| code | status | 说明 |
| --- | --- | --- |
| `4000` | `VALIDATION_ERROR` | 参数格式错误 |
| `4015` | `KEY_REQUIRED` | 缺少 API Key |
| `4030` | `QUOTA_EXCEEDED` | 今日免费额度已用完 |
| `5020` | `UPSTREAM_ERROR` | 地震数据服务暂不可用 |
| `5021` | `UPSTREAM_INVALID` | 地震数据格式异常 |

## 9. 变更日志

- **v1.0** (2026-07-01)
  - 首次上线：支持时间范围 + 震级档位查询，返回震级/深度/坐标/烈度/海啸/警报等完整字段。

---

**极数本源** · 全部 API: `https://apizero.cn/aidocs` · 人类版本：`https://apizero.cn/marketplace/earthquake`

Source: `https://apizero.cn/aidocs/earthquake/raw.md`
Last updated: 2026-07-01T12:14:08+08:00
