# 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/workflows/deutsche-bahn
- Handle: `@deutsche-bahn`
- Category: [Travel](https://fous.com/workflows/category/travel)
- Source website: https://bahn.de
- Last verified: Sep 29, 2026
- Fous is not affiliated with Deutsche Bahn.

## Methods

### Search train connections

Operation `search_train_connections`, version 1. 1 credit per call.

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 | `"22m"` |  |
| `connections[].cheapest_price` | number or null | `17.99` |  |
| `connections[].arrival_station` | string or null | `"Düsseldorf Hbf"` |  |
| `connections[].disruption_notes` | array |  |  |
| `connections[].realtime_arrival` | string or null |  |  |
| `connections[].departure_station` | string or null | `"Köln Hbf"` |  |
| `connections[].scheduled_arrival` | string | `"2026-09-30T10:08:00+02:00"` |  |
| `connections[].arrival_station_id` | string or null | `"8000085"` |  |
| `connections[].realtime_departure` | string or null |  |  |
| `connections[].scheduled_departure` | string | `"2026-09-30T09:46:00+02:00"` |  |
| `connections[].departure_station_id` | string or null | `"8000207"` |  |
| `connections[].arrival_delay_minutes` | integer or null |  |  |
| `connections[].departure_delay_minutes` | integer or null |  |  |

**Example input**

```json
{
  "date": "2026-09-30",
  "time": "11:00",
  "origin": "Köln Hbf",
  "time_is": "arrival",
  "destination": "Düsseldorf Hbf",
  "max_results": 5
}
```

**Example output**

```json
{
  "connections": [
    {
      "trains": [
        "IC 2204"
      ],
      "changes": 0,
      "currency": "EUR",
      "page_link": "https://www.bahn.de/buchung/fahrplan/suche#sts=true&so=K%C3%B6ln+Hbf&zo=D%C3%BCsseldorf+Hbf&kl=2&r=13%3A16%3AKLASSENLOS%3A1&soid=A%3D1%40O%3DK%C3%B6ln+Hbf%40X%3D6958730%40Y%3D50943029%40U%3D80%40L%3D8…",
      "travel_time": "22m",
      "cheapest_price": 17.99,
      "arrival_station": "Düsseldorf Hbf",
      "disruption_notes": [],
      "realtime_arrival": null,
      "departure_station": "Köln Hbf",
      "scheduled_arrival": "2026-09-30T10:08:00+02:00",
      "arrival_station_id": "8000085",
      "realtime_departure": null,
      "scheduled_departure": "2026-09-30T09:46:00+02:00",
      "departure_station_id": "8000207",
      "arrival_delay_minutes": null,
      "departure_delay_minutes": null
    }
  ]
}
```

## Quick start

Call the API with a Fous API key (`FOUS_API_KEY`). To create one, turn on Developer mode in Fous Studio, then open Keys & connections → API keys (https://app.fous.com/keys).

```bash
# First set your key: export FOUS_API_KEY='YOUR_FOUS_API_KEY'
: "${FOUS_API_KEY:?Set FOUS_API_KEY before running this example}"

curl 'https://api.fous.com/v1/query' \
  --fail-with-body --silent --show-error --max-time 120 \
  -H "Authorization: Bearer $FOUS_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.
# First set your key: export FOUS_API_KEY='YOUR_FOUS_API_KEY'
import json
import os
import urllib.error
import urllib.request

api_key = os.environ.get("FOUS_API_KEY")
if not api_key:
    raise RuntimeError("Set FOUS_API_KEY before running this example")

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=120) 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.
// First set your key: export FOUS_API_KEY='YOUR_FOUS_API_KEY'
const apiKey = process.env.FOUS_API_KEY;
if (!apiKey) throw new Error("Set FOUS_API_KEY before running this example");

const response = await fetch("https://api.fous.com/v1/query", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  signal: AbortSignal.timeout(120_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);
```

Or describe the data in plain language: send `{"api":"@deutsche-bahn","prompt":"Describe the data you need, with every detail"}` to the same URL. Fous fills in the input, runs the method that fits and returns only the fields you asked for; `data.route.calls[].request` is the exact call it made. Routing is free; the run costs the same.

## 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

### Is Fous affiliated with Deutsche Bahn?

No. Fous is not affiliated with Deutsche Bahn. This workflow reads the public bahn.de website and returns its data.

### How much does it cost?

Each run costs 1 credit. 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; repeating the same request within a day may return the saved result. Fous checks this workflow automatically; it last passed a check 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/workflows/flixbus.md): Find and book bus and train trips on FlixBus.
- [Amtrak API](https://fous.com/workflows/amtrak.md): Amtrak passenger train travel and status.
- [Transport for London API](https://fous.com/workflows/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/workflows/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/workflows/rome2rio.md): Compare ways to travel between places by train, bus, ferry, plane and car.
- [Ryanair API](https://fous.com/workflows/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/workflows/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/workflows/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 workflows](https://fous.com/workflows/category/travel)
