Thrust Carbon

Calculate emissions (batch)

POST
/emission/batch

A standalone endpoint to calculate a batch of emissions individually.

This endpoint is useful when you want to compare many separate emissions. For example when you want to separately compare the emissions from two different flights in one request. If you do not need the result to be separate (e.g. you want just one combined emission number), you should use the standard emissions endpoint.

You must pass in an array of an array of segments. The top level array will be calculated separately, and will return a separate response; the second level of each array will be calculated as part of the same journey and will have it's emissions combined.

The results will be in the same order as the request body. For example, the first item in your request array will be the first item in the response array, the second item in the request array will be the second item in the response array, and so on.

Full URI: https://api.thrustcarbon.com/2/emission/batch

Use-cases

  1. Point of sale display of flights/hotels/car-hire. This endpoint is frequently used by businesses that wish to display individual carbon results & comparisons next to each result in a list of flights/hotel/car-hire.
  2. Efficiently calculating many items in a database. Businesses that have databases of thousands of segments might use the batch emissions API to efficiently perform 100 calculations at a time.

Comparison of results

You can compare the results of each item in a batch directly. However, you can save time by using pre-computed comparisons provided by Thrust Carbon:

  1. Comparing against the results in the batch. This is where you can compare against the highest, lowest and average result in a batch.
  2. Comparing against a comparison search that you provide. This is useful for large batches where you wish to compare against an 'average' search (e.g. compare all the specific flights between LHR->JFK against a theoretical average flight).

Comparing against the results in the batch

Every result set will return a compare payload, which can be used when comparing your results against each other (for example, you may wish to highlight a result to indicate that it has 'X% lower emissions than average').

If a record in the segments list has two segments (a return trip for example), the sum of those segments (the emission for the entire trip, rather than the individual segments) will be used for the comparison calculation.

Simplified example response:

{  "segments": {    "0": {      "tonnes_of_emissions": 1.5,      ...    },    "1": {      "tonnes_of_emissions": 0.5,      ...    }  },  "compare": {    "highest-emissions": 1.5,    "lowest-emissions": 0.5,    "average_emissions": 1.0,    ...  }}

Comparing against a comparison search that you provide

To use a comparison search, you should fill the compare key in your request. The batch endpoint will then calculate these emissions, and in the response the compare.comparison-emissions and the compare.comparison-invalid-segments payload will be returned.

Please note: like any other emissions calculation, your comparison searches will be billed as standard Thrust Carbon emission calculations.

Example comparison search request body (in this example, you would be billed for three calculations):

{  "compare": [    {      "type": "air",      "origin": {        "iata": "LHR"      },      "destination": {        "iata": "JFK"      }    }  ],  "segments": [    [      {        "type": "air",        "origin": {          "iata": "LHR"        },        "destination": {          "iata": "JFK"        },        "aircraft_type": "744"      }    ],    [      {        "type": "air",        "origin": {          "iata": "LHR"        },        "destination": {          "iata": "JFK"        },        "aircraft_type": "788"      }    ]  ]}

Example comparison search response body:

{  "segments": {    "0": {      "tonnes_of_emissions": 1.2,      ...    },    "1": {      "tonnes_of_emissions": 0.7,      ...    }  },  "compare": {    "comparison_emissions": 0.8,    ...  }}

Specifying compare location

The compare object you pass is still just a segment object, so you can specify the origin and destination in the same way. For example, you may want to use coordinates in the scenario where the user selects a city as the origin, rather than a specific airport. This request would be made as follows:

{  "compare": [    {      "type": "air",      "origin": {        // Use coordinates instead of IATA        "coordinates": {          "latitude": 51.509865,          "longitude": -0.118092        }      },      "destination": {        // You can still use IATA or any other parameter available in the location object        "iata": "JFK"      }    }  ],  "segments": [    ...  ]}

Where the location is resolved to a set of coordinates, we will average the emissions of all possible routes between airports within a 50km radius.

Comparing Hotels within a radius

When batch requesting hotels, you can use the compare feature to retrieve location specific information around hotel sustainability scores. In order to achieve this, you need to specify the radius of hotels that you'd like to include in your search. You can set the radius by adding a config object to the request along with the compare object:

{  "compare": [    {      "type": "hotel",      "location": {        "city_code": "LON",        "country_code": "GB"      }    }  ],  "config": {    "hotel_compare_radius": 50  },  "segments": [    ...  ]}

Example hotel comparison search response body:

{  "segments": {    "0": {      "tonnes_of_emissions": 1.2,      ...    },    "1": {      "tonnes_of_emissions": 0.7,      ...    }  },  "compare": {    "comparison_emissions": 0.8,    "sustainability_score_percentiles": {      "percentile_0": 32,      "percentile_10": 44,      "percentile_20": 46,      "percentile_25": 46,      "percentile_30": 46,      "percentile_40": 46,      "percentile_50": 46,      "percentile_60": 46,      "percentile_70": 49,      "percentile_75": 53,      "percentile_80": 57      "percentile_90": 61,      "percentile_100": 67    },    "sustainability_score_average": 46.41415465268676,    ...  }}

If your comparison request doesn't contain any hotels, then sustainability_score_percentiles and sustainability_score_average will be returned as null. If the config object is not provided, then these parameters will be undefined (will not be present in the response).

Limitations of batch requests

  • We currently support a maximum of 100 calculations in a batch.
    • Each calculation may have a maximum of 20 underlying segments.
    • Please discuss with your account manager if you wish to lookup more than 100 calculations in a batch.

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

curl -X POST "https://example.com/emission/batch" \  -H "Content-Type: application/json" \  -d '{    "compare": [      {        "type": "air",        "origin": {          "iata": "LHR"        },        "destination": {          "iata": "JFK"        }      }    ],    "segments": [      [        {          "type": "air",          "origin": {            "iata": "LHR"          },          "destination": {            "iata": "JFK"          },          "aircraft_type": 744        }      ],      [        {          "type": "air",          "origin": {            "iata": "LHR"          },          "destination": {            "iata": "JFK"          },          "aircraft_type": 787        }      ]    ]  }'
{  "0": {    "tonnes_of_emissions": 0.8521272153582307,    "distance": 5539.377540497169,    "invalid_segments": [],    "equivalencies": [      {        "type": "video-call",        "values": [          "This is equivalent to 8,521 days of video conferencing."        ]      },      {        "type": "moon",        "values": [          "This is equivalent to driving a small car 7,740 kilometers.",          "You could also drive 2.01% of the way to the moon."        ]      },      {        "type": "plastic-bag",        "values": [          "This is equivalent to producing 18742 plastic bags."        ]      }    ]  },  "1": {    "tonnes_of_emissions": 0.6768148785477451,    "distance": 5539.377540497169,    "invalid_segments": [],    "equivalencies": [      {        "type": "video-call",        "values": [          "This is equivalent to 6,768 days of video conferencing."        ]      },      {        "type": "moon",        "values": [          "This is equivalent to driving a small car 6,148 kilometers.",          "You could also drive 1.6% of the way to the moon."        ]      },      {        "type": "plastic-bag",        "values": [          "This is equivalent to producing 14886 plastic bags."        ]      }    ]  },  "compare": {    "highest_emissions": 0.8521272153582307,    "lowest_emissions": 0.6768148785477451,    "average_emissions": 0.7644710469529878,    "comparison_emissions": 0.8191077569133164,    "comparison_invalid_segments": {      "1": {        "travel_class": [          "The selected travel class is invalid."        ]      }    }  }}