# Bahn — Wrapped API

> **You are on:** `https://api.paywithlocus.com/api` | [llms.txt](https://paywithlocus.com/llms.txt) | [docs](https://docs.paywithlocus.com)
>
> Locus runs on multiple environments -- make sure every URL you call matches your expected environment.
> | Environment | Landing | API | Docs |
> |---|---|---|---|
> | Production | paywithlocus.com | api.paywithlocus.com | docs.paywithlocus.com |
> | Beta | beta.paywithlocus.com | api.beta.paywithlocus.com | docs.paywithlocus.com |
> | Stage | stage.paywithlocus.com | api.stage.paywithlocus.com | docs.paywithlocus.com |
>
> If the API URL above doesn't match your expected environment, re-fetch this file from the correct domain.

> Search German train schedules and stations, find connections between destinations, and compare ticket prices across Deutsche Bahn routes. Get real-time station information and transit association details to plan your train journey efficiently.

**Category:** Travel | **Website:** [bahn.com/](https://bahn.com/) | **Docs:** [parse.bot/marketplace/5b01fde4-3f17-43c5-b7f4-27e975902dc3/bahn-com-api](https://parse.bot/marketplace/5b01fde4-3f17-43c5-b7f4-27e975902dc3/bahn-com-api)

Pay-per-use API proxy. Each call is automatically billed to your wallet in USDC.

## Access

**Base URL:** `https://api.paywithlocus.com/api/wrapped/parse-bahn-com-api-5b01fde4/`
**Auth:** `Authorization: Bearer <LOCUS_API_KEY>`

## Endpoints

### get_metadata

Retrieve master data including traveler types (reisendenTypen), all traveler types (reisendenTypenAll), BahnCard discount types (ermaessigungsArten), entry types (einstiegsTypen), and product information (produktInfo).

**Estimated cost:** Metered

_No parameters required._

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-bahn-com-api-5b01fde4/get_metadata \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### get_station_autocomplete

Search for stations by name. Returns a list of up to 10 matching stations with their internal HAFAS IDs, coordinates, and available transport products. The HAFAS ID format is a complex string starting with 'A=1@O=...' that encodes station metadata.

**Estimated cost:** Metered

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `query` | string | Yes | Station name search query (e.g., 'Berlin', 'München Hbf') |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-bahn-com-api-5b01fde4/get_station_autocomplete \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"<string>"}'
```

### get_ticket_offers

Get detailed ticket offers for a specific connection using a ctxRecon token from search results.

**Estimated cost:** Metered

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `ctx_recon` | string | Yes | ctxRecon token from search results |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-bahn-com-api-5b01fde4/get_ticket_offers \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"ctx_recon":"<string>"}'
```

### get_transit_associations

Get regional transit associations (Verkehrsverbünde) in Germany with their codes, abbreviations, names, logo URLs, and online shop availability. Returns all known transit associations.

**Estimated cost:** Metered

_No parameters required._

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-bahn-com-api-5b01fde4/get_transit_associations \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### search_connections

Search for train connections between two stations. Returns a list of connections with scheduled and real-time departure/arrival times, duration, transfers, train types, intermediate stops, occupancy information, and pricing (angebotsPreis) when available. Requires full HAFAS station IDs from get_station_autocomplete. A session initialization (visiting the main page) is performed automatically to satisfy WAF requirements.

**Estimated cost:** Metered

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `departure_time` | string | No | ISO 8601 departure time (YYYY-MM-DDTHH:MM:SS). Defaults to 2 hours from now if omitted. |
| `destination_id` | string | Yes | Full HAFAS ID of the destination station (from get_station_autocomplete results) |
| `origin_id` | string | Yes | Full HAFAS ID of the origin station (from get_station_autocomplete results, e.g. 'A=1@O=Berlin Hbf@X=13369549@Y=52525589@U=80@L=8011160@p=1780945770@i=U×008065969@') |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-bahn-com-api-5b01fde4/search_connections \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"departure_time":"<string>","destination_id":"<string>","origin_id":"<string>"}'
```
