

Road transport from the Reichstag Building in Berlin to the Palace of Westminster in London
1. Set the locations
Define where the journey starts and finishes.
2. Build the chain
Describe the ordered journey between those locations.
3. Choose the operation
Select how the cargo moves on each leg of the journey.
4. Read the distances
See the distance of each leg and of the whole journey.
Before you begin
You need:- A TerraTwin account
- An API key from Manage API Keys
- At least one Distance API credit
- A way to send an HTTP request; this tutorial uses
curlfor the final test
Authentication
Every request must include your API key in the
x-api-key header.See API keys for creating, storing, rotating, and revoking keys.Credits
Requests consume Distance API credits according to the transport operations that TerraTwin routes.See Credits & usage for charging rules and examples.
Build the request
We will build the request body one section at a time. Each step shows the complete JSON as it stands at that point.1
Define the origin and destination
Add top level
origin and destination objects.
Each location needs a type and enough information for TerraTwin to resolve it.For this tutorial, use structured address PLACE locations:PLACE is suitable for cities, addresses, postcodes, buildings, or coordinates. TerraTwin can also resolve purpose specific locations such as AIRPORT, RAIL_YARD, and HARBOR.See the Locations guide for coordinates, structured and freeform addresses, postcodes, IATA airport codes, UN/LOCODEs, location types, and matching behavior.2
Create the transport chain
Add a See the Transport chains guide for single leg and multimodal chains, chain boundaries, and the difference between requested legs and the operations realized in the response.
transportChain array to describe how the cargo moves from the origin to the destination.A transport chain is ordered. Each element is either:- A transport operation, which moves the cargo on one requested leg
- A
HUB, which marks where one leg ends and the next begins
3
Choose the transport operation
The
type inside the transport chain element selects the mode for that leg: ROAD, RAIL, WATER, AIR, or UNKNOWN when the mode isn’t known.
This tutorial uses ROAD, which lets TerraTwin choose a default vehicle.Operation properties that affect the route – such as the vessel of a WATER leg, which decides the harbors and waterways it can use, or the aircraft of an AIR leg – work as they do in the Emissions API. See the guide for each mode:The Distance API doesn’t accept
WEIGHTED_MODES operations, or the firstMile and lastMile properties. Connecting road journeys, for example from an address to a harbor, are still routed and included in the distances.Send the request
Replaceyour-api-key with your TerraTwin API key, then run the command for your shell.
- PowerShell 7.3+
- Windows PowerShell 5.1
- Command Prompt
- Bash or zsh
200 and a JSON result.
Read the result
The response starts with the resolved locations and the total distance:
Each leg’s
elements are the operations TerraTwin actually routed. A road journey can include roll-on/roll-off crossings as subOperations – this one crosses the Channel on the Eurotunnel shuttle:
For every request field, response schema, and error model, see the Distance API reference.
Extend the request to multiple legs
A chain can contain several transport operations, but each pair of requested operations must be separated by aHUB that defines where the first leg ends and the next begins.
This chain moves cargo by water from the port of London Gateway [GBSHV] to the port of Antwerp [BEANR], and then by road to Frankfurt:


Sea transport from London Gateway to the Port of Antwerp, then by road to Frankfurt’s Römer
The total
distanceKm is 699.9 km, and the request costs 2 credits, one for each leg.
In the Distance API, a
HUB only needs a type and a location. It marks the boundary between legs and adds no distance of its own.Next steps
Distance API
- Distance API guide – options, the response, and how distances are measured
- Credits & usage
Shipment structure
Transport operations
Complete schema
Use the Distance API reference for exact field constraints, allowed values, complete response objects, and error codes.