Skip to main content
TerraTwin provides APIs for modelling freight transport. They share one account, one set of API keys, and one way of describing a shipment, so once you have used one, the others work the same way.

Emissions API

Calculate the greenhouse gas emissions of moving cargo along a transport chain, by road, rail, water, and air, including logistics hubs.POST /emissions/calculate

Distance API

Calculate the routes and distances of a transport chain, with the resolved locations, airports, harbors, and rail yards, without calculating emissions.POST /routes/calculate

Choose an API

Both APIs route a shipment the same way – the same locations, transport modes, airports, harbors, rail yards, ferries, and fallbacks – so the routes and distances from the Distance API match those used by the Emissions API for the same request.

Before you begin

You need:
  • A TerraTwin account
  • An API key from Manage API Keys
  • Credits for the API you want to use – see Credits & usage
  • A way to send an HTTP request, such as curl or the HTTP client of your programming language

What every API has in common

Base URL

All transport APIs are served from:https://api.terratwin.com/api/v1/transportation

Authentication

Send your API key in the x-api-key header of every request. The same key works for every API.See API keys.

Credits

Each API has its own credit balance on your account, and a request only ever uses the balance of the API it calls.See Credits & usage.

Rate limits

Each account can send up to 5 requests per second, across all APIs. Requests above this are rejected with 429 Too Many Requests; retry after a short delay.

The same request, two answers

Both APIs take a shipment described as an origin, a destination, and an ordered transportChain of transport operations. This request moves cargo from Berlin to London by road:
Send it to the endpoint of the API you need. Replace your-api-key with your TerraTwin API key and save the request above as request.json:
The response includes the emissions of the journey, such as totalEmissions.co2eGrams, along with the distance and the vehicle defaults TerraTwin used.
The Emissions API quick start and the Distance API quick start build this request step by step and explain the results.
Treat your API key as a secret. Do not commit a real key to source control or share it in logs, screenshots, or support messages.

Errors and troubleshooting

All TerraTwin APIs report errors in the same way. Error responses include title, status, code, details, and recommendation properties. Start with details, which normally identifies the field, location, or operation that failed, and then follow recommendation. When the error was caused by the content of the request, the response also includes an errors array, following RFC 9457. Each entry has a pointer, a JSON Pointer to the request property at fault, and a short detail. Use the pointer to find the property in your request programmatically, for example to highlight the field or the source data it came from.
Pointers use zero-based array indexes, so #/transportChain/0/location is the location of the first transport chain element. A pointer can refer to an object rather than a single property when the problem concerns the object as a whole, as in this example. For field level validation rules and the complete error code list, see the API reference for the Emissions API or the Distance API.