> ## Documentation Index
> Fetch the complete documentation index at: https://code.dcycle.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Consumption Calculation Steps

> View the detailed emission calculation breakdown for a vehicle consumption

# Consumption Calculation Steps

Retrieve the full calculation chain showing how CO2e emissions were computed for a vehicle consumption record. The response breaks down each conversion step — from raw fuel quantity through emission factors to final CO2e — split by GHG scope and period.

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### Path Parameters

<ParamField path="vehicle_consumption_id" type="string" required>
  UUID of the vehicle consumption record
</ParamField>

## Response

<ResponseField name="total_co2e" type="number">
  Total CO2 equivalent emissions across all periods (kg)
</ResponseField>

<ResponseField name="total_energy_kwh" type="number | null">
  Total energy across all periods (kWh)
</ResponseField>

<ResponseField name="periods" type="array[object]">
  Breakdown by emission factor period
</ResponseField>

<ResponseField name="periods[].start_date" type="string">
  Period start date
</ResponseField>

<ResponseField name="periods[].end_date" type="string">
  Period end date
</ResponseField>

<ResponseField name="periods[].co2e_scope_1" type="number">
  Scope 1 (direct combustion) emissions in kg CO2e
</ResponseField>

<ResponseField name="periods[].co2e_scope_3" type="number">
  Scope 3 (upstream fuel generation) emissions in kg CO2e
</ResponseField>

<ResponseField name="periods[].co2e" type="number">
  Total emissions for this period in kg CO2e
</ResponseField>

<ResponseField name="periods[].sources" type="array[object]">
  Emission factor sources used (name, version, reference year)
</ResponseField>

<ResponseField name="periods[].details" type="array[object]">
  Detailed conversion steps grouped by scope and category, showing the step-by-step calculation chain (raw value → conversion factor → calculated value)
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl "https://api.dcycle.io/v1/vehicle_consumptions/${CONSUMPTION_ID}/steps" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}"
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  response = requests.get(
      f"https://api.dcycle.io/v1/vehicle_consumptions/{os.getenv('CONSUMPTION_ID')}/steps",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
  )

  calc = response.json()
  print(f"Total: {calc['total_co2e']} kg CO2e")
  for period in calc["periods"]:
      print(f"  {period['start_date']}–{period['end_date']}: "
            f"Scope 1: {period['co2e_scope_1']}, Scope 3: {period['co2e_scope_3']}")
      for source in period["sources"]:
          print(f"    Source: {source['source_name']} {source['source_version']}")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const response = await axios.get(
    `https://api.dcycle.io/v1/vehicle_consumptions/${process.env.CONSUMPTION_ID}/steps`,
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
      },
    }
  );

  const calc = response.data;
  console.log(`Total: ${calc.total_co2e} kg CO2e`);
  calc.periods.forEach(p => {
    console.log(`  ${p.start_date}–${p.end_date}: Scope 1: ${p.co2e_scope_1}, Scope 3: ${p.co2e_scope_3}`);
    p.sources.forEach(s => console.log(`    Source: ${s.source_name} ${s.source_version}`));
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "total_co2e": 1170.0,
  "total_energy_kwh": 4500.0,
  "periods": [
    {
      "start_date": "2025-01-01",
      "end_date": "2025-03-31",
      "co2e_scope_1": 1053.0,
      "co2e_scope_3": 117.0,
      "co2e": 1170.0,
      "total_energy_kwh": 4500.0,
      "sources": [
        {
          "source_id": "source-uuid",
          "source_name": "DEFRA",
          "source_version": "2024",
          "source_reference_year": 2024,
          "scope": 1
        }
      ],
      "energy": [
        {
          "step": 1,
          "raw_value": { "value": 450.0, "unit": { "unit_id": "l", "unit_name": "litre" } },
          "conversion_factor": { "value": 10.0, "type": "multiplication" },
          "calculated_value": { "value": 4500.0, "unit": { "unit_id": "kWh", "unit_name": "kilowatt-hour" } },
          "source": { "source_id": "src-uuid", "source_name": "DEFRA", "source_version": "2024" },
          "coincidence": "Diesel"
        }
      ],
      "details": [
        {
          "scope": "scope_1",
          "category": "transport",
          "co2e_from_ch4": [],
          "co2e_from_n2o": [],
          "co2e_from_co2": [
            {
              "step": 1,
              "raw_value": { "value": 450.0, "unit": { "unit_id": "l", "unit_name": "litre" } },
              "conversion_factor": { "value": 2.34, "type": "multiplication" },
              "calculated_value": { "value": 1053.0, "unit": { "unit_id": "kgCO2e", "unit_name": "kg CO2e" } },
              "source": { "source_id": "src-uuid", "source_name": "DEFRA", "source_version": "2024" },
              "coincidence": "Cars - Large - Diesel"
            }
          ],
          "co2_biogenic": [],
          "co2e": []
        }
      ]
    }
  ]
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 404 Not Found

**Cause:** The vehicle consumption record does not exist or belongs to another organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Not Found"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Consumption" icon="gas-pump" href="/api-reference/vehicles/consumptions-get">
    View consumption record details
  </Card>

  <Card title="List Consumptions" icon="list" href="/api-reference/vehicles/consumptions">
    Browse all consumptions for a vehicle
  </Card>
</CardGroup>
