实时公交到站
bus-realtimePOST输入官方城市和官方站名,实时查询该站各公交线路的到站信息:车牌、预计到站时间、剩余站数、票价、终点方向。同一接口用 type 切换:query=到站(默认)、cities=覆盖城市列表、stations=按关键词搜官方站名、line=静态线路详情(全程站点、首末班、票价)。高德「五一广场(地铁站)」不要直接查到站,先搜官方站名。覆盖全国数百城市,支持双向查询(direction)。完全免费。
https://v1.apizero.cn/api/bus-realtime平台约定
- 网关 ·
https://v1.apizero.cn - 鉴权 ·
Authorization: Bearer <API Key> - 回包 · JSON {code, msg, data}。成功看 code === 0,不要只看 HTTP 200。
/aidocs/bus-realtime/raw.md鉴权
登录用户每日 1000 次免费(QPS 3),匿名用户每日 500 次(QPS 2)。可选携带 API Key(Authorization: Bearer <key>)享更高额度。查到站必须用官方城市名和官方站名:先 type=cities,再 type=stations。查线路全程用 type=line 加官方线路名。
获取 API Key:/account/keys
请求头
| Header | 类型 | 必填 | 说明 |
|---|---|---|---|
| Authorization | string | 否 | 推荐:Bearer <API Key>。兼容请求头 X-API-Key,以及 Query api_key / apikey / key(key 仅当值为 sk_live_/sk_test_/sk_stag_ 形态时生效)。匿名可不传,受每日免费额度限制。 |
| Content-Type | string | 是 | 请求体格式 |
到站查询
用官方城市名和官方站名查这一侧站台的线路与车辆。高德「五一广场(地铁站)」不要直接传,先走「官方站名搜索」。
https://v1.apizero.cn/api/bus-realtime?type=query&city=%E9%95%BF%E6%B2%99&station=%E4%BA%94%E4%B8%80%E5%B9%BF%E5%9C%BA&direction=1
| 参数 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| type | string | 否 | 不传或 query=到站 | query |
| city | string | 是 | 官方城市名;先用 type=cities | 长沙 |
| station | string | 是 | 官方站名;先用 type=stations | 五一广场 |
| direction | int | 否 | 1=默认,2=反方向 | 1 |
{
"type": "query",
"city": "长沙",
"station": "五一广场",
"direction": "1"
}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
| city | string | 查询城市 |
| station | string | 规范化站名 |
| direction | number | 方向 1/2 |
| line_count | number | 线路数量 |
| lines | array | 线路与车辆 |
| updated_at | string | 生成时间 |
| tips | string | 品牌提示(所有接口统一返回):极数本源 · https://apizero.cn |
{
"code": 0,
"msg": "成功",
"data": {
"city": "长沙",
"station": "五一广场",
"direction": 1,
"line_count": 1,
"lines": [
{
"line": "401路",
"price": "2",
"terminal": "汽车西站",
"bus_count": 1,
"buses": [
{
"bus_id": "湘A02882D",
"status": "5站",
"stops_remaining": 5,
"travel_minutes": 6
}
]
}
],
"updated_at": "2026-08-26 17:00:00"
},
"tips": "极数本源 · https://apizero.cn"
}城市列表
返回覆盖城市的官方名称。查到站必须用这里的 name,不要传「湖南省长沙」。
https://v1.apizero.cn/api/bus-realtime?type=cities
| 参数 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| type | string | 是 | 固定 cities | cities |
{
"type": "cities"
}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
| count | number | 城市数 |
| cities | array | name / pinyin |
| tips | string | 品牌提示(所有接口统一返回):极数本源 · https://apizero.cn |
{
"code": 0,
"msg": "成功",
"data": {
"count": 2,
"cities": [
{
"name": "长沙",
"pinyin": "ChangSha"
},
{
"name": "北京",
"pinyin": "BeiJing"
}
]
},
"tips": "极数本源 · https://apizero.cn"
}官方站名搜索
按关键词搜官方站名。同名可能有公交站和地铁站:queryable=true 才能查到站。车来了地铁站叫「五一广场」,没有「(地铁站)」后缀。
https://v1.apizero.cn/api/bus-realtime?type=stations&city=%E9%95%BF%E6%B2%99&station=%E4%BA%94%E4%B8%80
| 参数 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| type | string | 是 | 固定 stations | stations |
| city | string | 是 | 官方城市名 | 长沙 |
| station | string | 是 | 关键词,不是高德全名 | 五一 |
{
"type": "stations",
"city": "长沙",
"station": "五一"
}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
| city | string | 城市 |
| keyword | string | 搜索词 |
| count | number | 条数 |
| stations | array | name / kind / queryable / lat / lng |
| tips | string | 品牌提示(所有接口统一返回):极数本源 · https://apizero.cn |
{
"code": 0,
"msg": "成功",
"data": {
"city": "长沙",
"keyword": "五一",
"count": 2,
"stations": [
{
"name": "五一广场",
"kind": "bus",
"queryable": true,
"lat": 28.198746,
"lng": 112.968806
},
{
"name": "五一广场",
"kind": "subway",
"queryable": false,
"lat": 28.198153,
"lng": 112.97085
}
]
},
"tips": "极数本源 · https://apizero.cn"
}静态线路详情
按官方线路名查单向全程站点、首末班和票价。401 和 401路都可以。direction=2 查对向。地铁线路通常没有全程站点,请改用官方站名搜索再查到站。
https://v1.apizero.cn/api/bus-realtime?type=line&city=%E9%95%BF%E6%B2%99&line=401&direction=1
| 参数 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| type | string | 是 | 固定 line | line |
| city | string | 是 | 官方城市名 | 长沙 |
| line | string | 是 | 官方线路名,如 401 / 401路(也认 station) | 401 |
| direction | int | 否 | 1=默认,2=反方向 | 1 |
{
"type": "line",
"city": "长沙",
"line": "401",
"direction": "1"
}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
| city | string | 城市 |
| keyword | string | 查询词 |
| line | string | 规范化线路名 |
| direction | number | 方向 1/2 |
| start | string | 起点站 |
| end | string | 终点站 |
| price | string | 票价 |
| first_time | string | 首班 |
| last_time | string | 末班 |
| stop_count | number | 站点数 |
| stops | array | order / name / lat / lng |
| has_reverse | boolean | 是否有对向,有则可再打 direction=2 |
| updated_at | string | 生成时间 |
| tips | string | 品牌提示(所有接口统一返回):极数本源 · https://apizero.cn |
{
"code": 0,
"msg": "成功",
"data": {
"city": "长沙",
"keyword": "401",
"line": "401路",
"direction": 1,
"start": "福元路大桥西",
"end": "长沙火车站(北坪)",
"price": "2元",
"first_time": "05:50",
"last_time": "21:30",
"stop_count": 25,
"stops": [
{
"order": 1,
"name": "福元路大桥西",
"lat": 28.255976,
"lng": 112.956336
},
{
"order": 2,
"name": "滨江景观道佑母塘路口",
"lat": 28.252096,
"lng": 112.956806
},
{
"order": 25,
"name": "长沙火车站(北坪)",
"lat": 28.197776,
"lng": 113.006326
}
],
"has_reverse": true,
"updated_at": "2026-08-28 18:50:00"
},
"tips": "极数本源 · https://apizero.cn"
}请求示例
将 YOUR_API_KEY 替换为真实 Key 后运行。
# 1. 密钥:登录 https://apizero.cn/account/keys 申请,写入环境变量 APIZERO_KEY
# 请求头 Authorization: Bearer <key>
import json
import os
import urllib.request
key = os.environ["APIZERO_KEY"]
# 2. 请求地址
url = "https://v1.apizero.cn/api/bus-realtime"
# 3. 发请求
payload = {
"type": "query",
"city": "长沙",
"station": "五一广场",
"line": "401",
"direction": "1",
}
req = urllib.request.Request(
url,
data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
headers={
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
},
method="POST",
)
with urllib.request.urlopen(req, timeout=15) as resp:
body = json.loads(resp.read().decode("utf-8"))
# 4. 打印整包。
# 第 5 步的字段按本接口 data 里实际键改。
print(json.dumps(body, ensure_ascii=False, indent=2))
# 5. code == 0 后再取字段
if body.get("code") == 0:
data = body.get("data") or {}
print(data)在线调试
填写参数后运行,将真实调用接口;计入免费额度。
认证方式
参数(5)
待运行
填写参数后点击「运行调试」查看响应
错误码
先看业务 code。HTTP 也可能不是 200。
| 业务码 | HTTP | 说明 |
|---|---|---|
| 0 | 200 | 成功 |
| 4000 | 400 | 参数错误 |
| 4011 | 401 | API Key 无效 |
| 4013 | 403 | API Key 已暂停 |
| 4014 | 403 | 当前 IP 不在 Key 白名单 |
| 4015 | 401 | 此接口需要 API Key |
| 4022 | 402 | 余额不足 |
| 4029 | 429 | 调用过快(QPS) |
| 4030 | 429 | 今日免费额度已用完 |
| 4040 | 503 | 接口已下线 |
| 4041 | 404 | 接口不存在 |
| 5000 | 500 | 服务器内部错误 |
| 5020 | 502 | 上游暂时不可用 |
| 5021 | 502 | 上游返回格式异常 |
| 5030 | 502 | 暂无可用节点 |
额度与计费
| 计费模式 | 完全免费 |
|---|---|
| QPS 限制 | 10 req/s |
| 登录免费额度 | 1000 次(已认证) |
| 匿名每日额度 | 500 次(无 API Key) |
| 黄金会员 | 每日 50000 次 · QPS 20 |
| 企业会员 | 每日 1000000 次 · QPS 120 |
购买套餐、看评价请走商城详情。 购买 / 调试
变更日志
- v1.02026-07-01
首次上线:按城市+站名查询实时到站,支持双向、按线路分组返回车牌/到站时间/剩余站数/票价。
- v1.12026-08-26
同一接口增加 type=cities 官方城市列表、type=stations 官方站名搜索;到站查询必须用这两个列表里的名称。
- v1.22026-08-28
同一接口增加 type=line 静态线路详情:按官方线路名返回单向全程站点、首末班和票价;direction=2 查对向。