# Deutsche Bahn API

> Deutsche Bahn returns train connections, fares and delay information, available as a workflow and API.

Deutsche Bahn (DB) Search train connections returns routes, fares, delays and service notes for an origin, destination and travel date. Search train connections can also use local time, passenger count and travel class.

- Page: https://fous.com/tools/deutsche-bahn
- Handle: `@deutsche-bahn`
- Category: [Travel](https://fous.com/tools/category/travel)
- Source website: https://bahn.de
- Last verified: Sep 29, 2026

## Methods

### Search train connections

Operation `search_train_connections`, version 1. 1 credit per completed call. Failed calls without a completed billing receipt are free; completed work can remain charged if delivery is interrupted.

Find Deutsche Bahn train connections by station or city and date, with fares, delays and service notes. Fares and real-time information may be unavailable for some journeys.

**Input**

| Field | Type | Required | Example | Description |
|---|---|---|---|---|
| `date` | string | yes | `"2026-10-01"` | Travel date, for example 2026-09-30. |
| `time` | string | no | `"09:00"` | Local time in HH:MM, for example 08:00. |
| `adults` | integer | no |  | Number of adults, for example 1. |
| `origin` | string | yes | `"Hamburg Hbf"` | Starting station or city, for example Berlin Hbf. |
| `time_is` | string | no | `"arrival"` | Whether time is departure or arrival, for example departure. |
| `destination` | string | yes | `"Bremen Hbf"` | Destination station or city, for example Frankfurt. |
| `max_results` | integer | no | `12` | Maximum number of connections, for example 10. |
| `travel_class` | string | no | `"first"` | Travel class, for example second. |

**Input schema**

```json
{
  "type": "object",
  "required": [
    "origin",
    "destination",
    "date"
  ],
  "properties": {
    "date": {
      "type": "string",
      "format": "date",
      "description": "Travel date, for example 2026-09-30.",
      "examples": [
        "2026-10-01",
        "2026-09-30"
      ]
    },
    "time": {
      "type": "string",
      "default": "08:00",
      "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$",
      "description": "Local time in HH:MM, for example 08:00.",
      "examples": [
        "09:00",
        "08:00",
        "11:00"
      ]
    },
    "adults": {
      "type": "integer",
      "default": 1,
      "minimum": 1,
      "description": "Number of adults, for example 1."
    },
    "origin": {
      "type": "string",
      "title": "From",
      "description": "Starting station or city, for example Berlin Hbf.",
      "examples": [
        "Hamburg Hbf",
        "Berlin Hbf",
        "Köln Hbf"
      ]
    },
    "time_is": {
      "enum": [
        "departure",
        "arrival"
      ],
      "type": "string",
      "default": "departure",
      "description": "Whether time is departure or arrival, for example departure.",
      "examples": [
        "arrival"
      ]
    },
    "destination": {
      "type": "string",
      "title": "To",
      "description": "Destination station or city, for example Frankfurt.",
      "examples": [
        "Bremen Hbf",
        "Frankfurt(Main)Hbf",
        "Düsseldorf Hbf"
      ]
    },
    "max_results": {
      "type": "integer",
      "default": 10,
      "maximum": 30,
      "minimum": 1,
      "description": "Maximum number of connections, for example 10.",
      "x-fous-developer": true,
      "examples": [
        12,
        5
      ]
    },
    "travel_class": {
      "enum": [
        "first",
        "second"
      ],
      "type": "string",
      "default": "second",
      "description": "Travel class, for example second.",
      "examples": [
        "first"
      ]
    }
  },
  "additionalProperties": false,
  "examples": [
    {
      "date": "2026-10-01",
      "time": "09:00",
      "origin": "Hamburg Hbf",
      "destination": "Bremen Hbf",
      "max_results": 12,
      "travel_class": "first"
    },
    {
      "date": "2026-09-30",
      "time": "08:00",
      "origin": "Berlin Hbf",
      "destination": "Frankfurt(Main)Hbf"
    },
    {
      "date": "2026-09-30",
      "time": "11:00",
      "origin": "Köln Hbf",
      "time_is": "arrival",
      "destination": "Düsseldorf Hbf",
      "max_results": 5
    }
  ]
}
```

**Output**

| Field | Type | Example | Description |
|---|---|---|---|
| `connections` | array |  |  |
| `connections[].trains` | array |  |  |
| `connections[].changes` | integer or null | `0` |  |
| `connections[].currency` | string | `"EUR"` |  |
| `connections[].page_link` | string |  |  |
| `connections[].travel_time` | string | `"1h 11m"` |  |
| `connections[].cheapest_price` | number or null | `17.1` |  |
| `connections[].arrival_station` | string or null | `"Bremen Hbf"` |  |
| `connections[].disruption_notes` | array |  |  |
| `connections[].realtime_arrival` | string or null |  |  |
| `connections[].departure_station` | string or null | `"Hamburg Hbf"` |  |
| `connections[].scheduled_arrival` | string | `"2026-10-01T10:26:00+02:00"` |  |
| `connections[].arrival_station_id` | string or null | `"8000050"` |  |
| `connections[].realtime_departure` | string or null |  |  |
| `connections[].scheduled_departure` | string | `"2026-10-01T09:15:00+02:00"` |  |
| `connections[].departure_station_id` | string or null | `"8002549"` |  |
| `connections[].arrival_delay_minutes` | integer or null |  |  |
| `connections[].departure_delay_minutes` | integer or null |  |  |

**Example input**

```json
{
  "date": "2026-10-01",
  "time": "09:00",
  "origin": "Hamburg Hbf",
  "destination": "Bremen Hbf",
  "max_results": 12,
  "travel_class": "first"
}
```

**Example output**

```json
{
  "connections": [
    {
      "trains": [
        "RE4"
      ],
      "changes": 0,
      "currency": "EUR",
      "page_link": "https://www.bahn.de/buchung/fahrplan/suche#sts=true&so=Hamburg+Hbf&zo=Bremen+Hbf&kl=1&r=13%3A16%3AKLASSENLOS%3A1&soid=A%3D1%40O%3DHamburg+Hbf%40X%3D10006909%40Y%3D53552733%40U%3D80%40L%3D8002549%40p%3…",
      "travel_time": "1h 11m",
      "cheapest_price": 17.1,
      "arrival_station": "Bremen Hbf",
      "disruption_notes": [],
      "realtime_arrival": null,
      "departure_station": "Hamburg Hbf",
      "scheduled_arrival": "2026-10-01T10:26:00+02:00",
      "arrival_station_id": "8000050",
      "realtime_departure": null,
      "scheduled_departure": "2026-10-01T09:15:00+02:00",
      "departure_station_id": "8002549",
      "arrival_delay_minutes": null,
      "departure_delay_minutes": null
    },
    {
      "trains": [
        "ICE 519"
      ],
      "changes": 0,
      "currency": "EUR",
      "page_link": "https://www.bahn.de/buchung/fahrplan/suche#sts=true&so=Hamburg+Hbf&zo=Bremen+Hbf&kl=1&r=13%3A16%3AKLASSENLOS%3A1&soid=A%3D1%40O%3DHamburg+Hbf%40X%3D10006909%40Y%3D53552733%40U%3D80%40L%3D8002549%40p%3…",
      "travel_time": "56m",
      "cheapest_price": 43.99,
      "arrival_station": "Bremen Hbf",
      "disruption_notes": [],
      "realtime_arrival": null,
      "departure_station": "Hamburg Hbf",
      "scheduled_arrival": "2026-10-01T10:41:00+02:00",
      "arrival_station_id": "8000050",
      "realtime_departure": null,
      "scheduled_departure": "2026-10-01T09:45:00+02:00",
      "departure_station_id": "8002549",
      "arrival_delay_minutes": null,
      "departure_delay_minutes": null
    }
  ]
}
```

## Quick start

Replace `YOUR_API_KEY` with a Fous API key. To create one, open Developers at the bottom of Fous Studio, turn on Developer mode, then go to API keys (https://app.fous.com/keys). Change the values in `input` to run the same tool on new data.

```bash
curl 'https://api.fous.com/v1/query' \
  --fail-with-body --silent --show-error --max-time 180 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "api": "@deutsche-bahn",
  "visibility": "public",
  "operation": "search_train_connections",
  "version": 1,
  "input": {
    "date": "2026-10-01",
    "time": "09:00",
    "origin": "Hamburg Hbf",
    "destination": "Bremen Hbf",
    "max_results": 12,
    "travel_class": "first"
  },
  "response": {
    "format": "json"
  }
}'
```

```python
# Save as fous.py and run with python3 fous.py. No packages needed.
import json
import urllib.error
import urllib.request

api_key = "YOUR_API_KEY"

body = json.loads("{\n  \"api\": \"@deutsche-bahn\",\n  \"visibility\": \"public\",\n  \"operation\": \"search_train_connections\",\n  \"version\": 1,\n  \"input\": {\n    \"date\": \"2026-10-01\",\n    \"time\": \"09:00\",\n    \"origin\": \"Hamburg Hbf\",\n    \"destination\": \"Bremen Hbf\",\n    \"max_results\": 12,\n    \"travel_class\": \"first\"\n  },\n  \"response\": {\n    \"format\": \"json\"\n  }\n}")
request = urllib.request.Request(
    "https://api.fous.com/v1/query",
    data=json.dumps(body).encode("utf-8"),
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    method="POST",
)
try:
    with urllib.request.urlopen(request, timeout=180) as response:
        result = json.load(response)
except urllib.error.HTTPError as error:
    raise RuntimeError(f"HTTP {error.code}: {error.read().decode('utf-8', errors='replace')}") from error
if result.get("success") is False:
    raise RuntimeError(result.get("error", {}).get("message", "Request failed"))
print(json.dumps(result["data"]["output"], indent=2))
```

```typescript
// Save as fous.mts and run with npx tsx fous.mts.
const apiKey = "YOUR_API_KEY";

const response = await fetch("https://api.fous.com/v1/query", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  signal: AbortSignal.timeout(180_000),
  body: JSON.stringify({
  "api": "@deutsche-bahn",
  "visibility": "public",
  "operation": "search_train_connections",
  "version": 1,
  "input": {
    "date": "2026-10-01",
    "time": "09:00",
    "origin": "Hamburg Hbf",
    "destination": "Bremen Hbf",
    "max_results": 12,
    "travel_class": "first"
  },
  "response": {
    "format": "json"
  }
}),
});
type ApiResult = { success: boolean; data?: { output: unknown }; error?: { message: string } };
const result: ApiResult = await response.json();
if (!response.ok || result.success === false) {
  throw new Error(result.error?.message ?? `HTTP ${response.status}`);
}
if (!result.data) throw new Error("Missing API response data");
console.log(result.data.output);
```

## Use from an AI assistant

Connect this tool to Claude Code, Claude Desktop, Cursor, VS Code, Codex and any MCP client as its own MCP server. Each method is a typed tool whose arguments are the method’s input.

- Server URL: `https://api.fous.com/mcp/tools/deutsche-bahn`
- Authorization: `Authorization: Bearer <Fous API key>`

**Tools**

- `search_train_connections`: Search train connections. 1 credit per completed call. Failed calls without a completed billing receipt are free; completed work can remain charged if delivery is interrupted.
- `fous_get_run`: the result of a run that was still going, by its `request_id`. Free.

Claude Code:

```bash
claude mcp add --scope user --transport http fous-deutsche-bahn https://api.fous.com/mcp/tools/deutsche-bahn --header "Authorization: Bearer ${FOUS_API_KEY:?Set FOUS_API_KEY to your Fous API key}"
```

To give the assistant every tool, connect `https://api.fous.com/mcp`: it finds one with `fous_search_tools` and runs it with `fous_run_tool`. Setup for other clients: https://fous.com/llms-full.txt.

## Use cases

- Compare train routes between cities
- Check journey times and required changes
- Review fares before choosing a connection
- Check departure and arrival delays
- Identify service notes affecting a journey

## FAQ

### Can I run it with my own inputs?

Yes. Change the inputs in Studio and press Run, or send new inputs from your code, or ask a connected AI assistant.

### Can I call this Deutsche Bahn tool as an API?

Yes. Send a POST request to /v1/query with your Fous API key and the inputs, and get JSON back.

### How much does it cost?

Each completed run costs 1 credit. Failed runs without a completed receipt are free; completed work can remain charged if delivery is interrupted. With pay as you go, a credit costs 1¢. Monthly plans cost less per credit.

### Do I need a Deutsche Bahn account?

No. You only need a Fous account.

### How current is the data?

Fous gets the data from bahn.de when you run it. Some results are reused for up to 24 hours, and results that use your account or key are never reused. It was last verified on Sep 29, 2026.

### What train connections are available between two places?

Search train connections returns routes between the supplied origin and destination for the chosen travel date.

### How long does a train journey take?

Search train connections returns travel times and connection changes.

### Are there delays or service notes for a journey?

Search train connections can return delays, real-time departure and arrival details, and disruption notes; this information may be unavailable for some journeys.

## Related

- [FlixBus API](https://fous.com/tools/flixbus.md): Find and book bus and train trips on FlixBus.
- [Amtrak API](https://fous.com/tools/amtrak.md): Amtrak passenger train travel and status.
- [Transport for London API](https://fous.com/tools/transport-for-london.md): Transport for London reports current or currently published future-day service status and ordered journey options with directions and adult pay-as-you-go fares when available.
- [Booking.com API](https://fous.com/tools/booking-com.md): Booking.com helps find stays, property details and public guest reviews; prices and cancellation terms depend on selected dates, and displayed prices may exclude taxes and fees.
- [Rome2rio API](https://fous.com/tools/rome2rio.md): Compare ways to travel between places by train, bus, ferry, plane and car.
- [Ryanair API](https://fous.com/tools/ryanair.md): Ryanair provides flights and fares, including lowest one-way prices by destination or day for selected dates; prices and availability can change.
- [Airbnb API](https://fous.com/tools/airbnb.md): Airbnb returns public stays, listing details, dated trip prices, and night availability, which depend on dates and may be limited, unavailable, or change.
- [Google Flights API](https://fous.com/tools/google-flights.md): Google Flights returns route schedules, public fares, monthly lowest prices, and flight or destination options with times, stops, emissions, and fares that may change.
- [All Travel tools](https://fous.com/tools/category/travel)
