NS Trains Skill
Check Dutch train schedules, departures, disruptions, and plan journeys using the official NS (Nederlandse Spoorwegen) API.
Setup
1. Get an NS subscription key
- 1. Go to NS API Portal
- Create an account and subscribe to the Ns-App product (free tier available)
- Copy your Primary Key
2. Set Environment Variables
CODEBLOCK0
For security, prefer injecting these env vars via your runtime secret mechanism rather than committing them anywhere. Avoid printing or sharing your subscription key.
Quick Usage
🚆 Commute shortcuts
CODEBLOCK1
Plan any journey
CODEBLOCK2
Check departures from a station
CODEBLOCK3
Check arrivals at a station
CODEBLOCK4
Search for stations
CODEBLOCK5
Check current disruptions
CODEBLOCK6
Natural Language
Just ask:
- - "When is the next train to Amsterdam?"
- "Check trains from Utrecht to Rotterdam"
- "Any train disruptions today?"
- "Plan my commute to work"
- "What time does the train arrive?"
Output
Returns journey options with:
- - Departure/arrival times
- Real-time delays
- Duration
- Transfers
- Platform numbers
- Disruption warnings
- Crowdedness forecast (🟢 low / 🟡 medium / 🔴 high)
Commands Reference
| Command | Description |
|---|
| INLINECODE0 | Quick commute check (requires NSHOMESTATION & NSWORKSTATION) |
| INLINECODE1 |
Plan a journey between any stations |
|
departures.mjs --station X | List departures from a station |
|
arrivals.mjs --station X | List arrivals at a station |
|
stations.mjs [query] | Search for station names |
|
disruptions.mjs | Check current disruptions |
API Endpoints Used
- -
/reisinformatie-api/api/v3/trips - Journey planning - INLINECODE7 - Arrivals
- INLINECODE8 - Departures
- INLINECODE9 - Disruptions
- INLINECODE10 - Station search
Reference
- - NS API Portal: https://apiportal.ns.nl/
- Documentation: https://apiportal.ns.nl/startersguide
- Free tier: 5000 requests/day
NS 火车技能
使用官方 NS(荷兰铁路)API 查询荷兰火车时刻表、出发信息、中断情况并规划行程。
设置
1. 获取 NS 订阅密钥
- 1. 访问 NS API 门户
- 创建账户并订阅 Ns-App 产品(提供免费套餐)
- 复制你的主密钥
2. 设置环境变量
bash
export NSSUBSCRIPTIONKEY=你的订阅密钥 # 推荐
向后兼容:
export NS
APIKEY=$NS
SUBSCRIPTIONKEY # 旧名称仍受支持
可选:配置通勤站点以快速访问
export NS
HOMESTATION=乌得勒支中央站
export NS
WORKSTATION=阿姆斯特丹南站
出于安全考虑,建议通过运行时密钥机制注入这些环境变量,而不是将其提交到任何地方。避免打印或分享你的订阅密钥。
快速使用
🚆 通勤快捷方式
bash
node {baseDir}/scripts/commute.mjs --to-work # 早上:家 → 公司
node {baseDir}/scripts/commute.mjs --to-home # 晚上:公司 → 家
规划任意行程
bash
node {baseDir}/scripts/journey.mjs --from 乌得勒支中央站 --to 阿姆斯特丹南站
查询车站出发信息
bash
node {baseDir}/scripts/departures.mjs --station 阿姆斯特丹中央站
查询车站到达信息
bash
node {baseDir}/scripts/arrivals.mjs --station 鹿特丹中央站
搜索车站
bash
node {baseDir}/scripts/stations.mjs 阿姆斯特丹
node {baseDir}/scripts/stations.mjs --search 海牙
查询当前中断信息
bash
node {baseDir}/scripts/disruptions.mjs
node {baseDir}/scripts/disruptions.mjs --from 乌得勒支 --to 阿姆斯特丹
自然语言
直接提问:
- - 下一班去阿姆斯特丹的火车什么时候?
- 查询从乌得勒支到鹿特丹的火车
- 今天有火车中断吗?
- 规划我的上班通勤
- 火车什么时候到达?
输出
返回行程选项,包含:
- - 出发/到达时间
- 实时延误
- 行程时长
- 换乘信息
- 站台编号
- 中断警告
- 拥挤度预测(🟢 低 / 🟡 中 / 🔴 高)
命令参考
| 命令 | 描述 |
|---|
| commute.mjs [work\ | home] | 快速通勤查询(需设置 NSHOMESTATION 和 NSWORKSTATION) |
| journey.mjs --from X --to Y |
规划任意两个站点间的行程 |
| departures.mjs --station X | 列出某站点的出发信息 |
| arrivals.mjs --station X | 列出某站点的到达信息 |
| stations.mjs [query] | 搜索站点名称 |
| disruptions.mjs | 查询当前中断信息 |
使用的 API 端点
- - /reisinformatie-api/api/v3/trips - 行程规划
- /reisinformatie-api/api/v2/arrivals - 到达信息
- /reisinformatie-api/api/v2/departures - 出发信息
- /reisinformatie-api/api/v3/disruptions - 中断信息
- /reisinformatie-api/api/v2/stations - 站点搜索
参考
- - NS API 门户:https://apiportal.ns.nl/
- 文档:https://apiportal.ns.nl/startersguide
- 免费套餐:每天 5000 次请求