# 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 for Locus Pro. Each call burns credits from your workspace balance.

## Access

**Base URL:** `https://api.paywithlocus.com/api/wrapped/credits/bahn/`
**Auth:** `Authorization: Bearer <LOCUS_CREDITS_SECRET_KEY>` (an `lcr_` secret key or a scoped `lcac_` agent credential)
**Required header:** `Idempotency-Key: <fresh UUID per call>`. A retry with the same key replays the stored result without a new charge.
**Response:** the provider response after any endpoint-specific normalization. `X-Locus-Credits-Charged` carries the charge and `X-Locus-Credits-Balance` the remaining balance. Insufficient credits return `402` before the provider is called.
**Pricing:** estimated costs below are USD. Locus debits the credit equivalent at your workspace rate.

Full call contract: https://docs.paywithlocus.com/api-reference/introduction

> Using a Pay With Locus wallet key (`claw_` prefix)? Wallet routes are documented separately: https://docs.paywithlocus.com/wrapped-apis/for-agents

## 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/credits/bahn/get-metadata \
  -H "Authorization: Bearer $LOCUS_CREDITS_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -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/credits/bahn/get-station-autocomplete \
  -H "Authorization: Bearer $LOCUS_CREDITS_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -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/credits/bahn/get-ticket-offers \
  -H "Authorization: Bearer $LOCUS_CREDITS_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -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/credits/bahn/get-transit-associations \
  -H "Authorization: Bearer $LOCUS_CREDITS_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -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/credits/bahn/search-connections \
  -H "Authorization: Bearer $LOCUS_CREDITS_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"departure_time":"<string>","destination_id":"<string>","origin_id":"<string>"}'
```

## Next steps

- [All wrapped API providers](https://paywithlocus.com/wapi/index.md): pick another provider.
- [Find and call tools](https://paywithlocus.com/agent/tools.md): price ceilings, async results, and errors.
- [Credits and billing](https://paywithlocus.com/agent/billing.md): what a call costs and how to add credits.
- [Agent docs index](https://paywithlocus.com/agent/index.md): every Locus agent page.