**European Economic Area (EEA) developers**

> [!NOTE]
> If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](https://developers.google.com/maps/comms/eea/faq.md.txt).

<br />

> [!WARNING]
> This product or feature is Experimental (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google
> Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage descriptions](https://developers.google.com/maps/launch-stages.md.txt).

<br />

Traffic models use specific algorithms and factors to predict how traffic
conditions impact total travel time for a given route. The Routes API
offers different traffic model types to prioritize different factors used in
calculating duration in traffic. You can specify the traffic model type you'd
like your routes to use when calculating the duration for your routes or route
matrix. When you set the traffic model type, the value returned in the
`duration` field varies depending on the traffic model you choose.

Both the Routes API `Compute Routes` and
`Compute Route Matrix` methods support traffic model types.

By default, both methods use the `BEST_GUESS` traffic model type.

## To specify a traffic type

1. Set your origin and destination.

2. If your departure time is in the future, include the time using the
   `departure_time` parameter. If you don't specify a departure time, it
   defaults to now.

3. Set the `routingPreference` parameter to `TRAFFIC_AWARE_OPTIMAL`. Setting the
   `routingPreference` to `TRAFFIC_UNAWARE` or `TRAFFIC_AWARE` is incompatible
   with the `trafficModel` parameter.

4. Select the traffic model to use with the `trafficModel` parameter and
   one of the following types:

   - `BEST_GUESS` (default) to request that the returned `duration_in_traffic`
     is the best estimate of travel time given what is known about both
     historical traffic conditions and live traffic. Live traffic becomes more
     important the closer the `departure_time` is to now. Using the default type
     of `BEST_GUESS` gives the most useful predictions for the vast majority of
     use cases.

   - `PESSIMISTIC` to request that the returned `duration_in_traffic` models the
     time based on the historical traffic conditions on bad traffic days.
     This type gives an estimated duration that is most likely **longer** than
     the actual travel time on most days. Occasional days with particularly bad
     conditions may still exceed this estimate.

   - `OPTIMISTIC` to request that the returned `duration_in_traffic` models the
     time based on the historical traffic conditions on good traffic days.
     This type gives an estimated duration that is most likely **shorter** than
     the actual travel time on most days. Occasional days with particularly
     good conditions may still be faster than this estimate.

   For example:

   ```json
   "trafficModel": "OPTIMISTIC"
   ```

   <br />

   > [!NOTE]
   > **Note:** It is possible the `BEST_GUESS` travel time prediction may be shorter than `OPTIMISTIC` or longer than `PESSIMISTIC`, due to the way `BEST_GUESS` integrates live traffic information.

5. Specify the `routes.duration` field in the field mask.

   **REST**

   ```json
   -H X-Goog-FieldMask: routes.duration
   ```

   **RPC**

   ```
   const (fieldMask = "routes.duration")
   ```

When the Routes API estimates time in traffic, it uses the traffic
model type you've requested.

## Example: Traffic model request

For example, this request specifies that the duration be estimated using the
`OPTIMISTIC` traffic model type at a specific departure time:

```json
curl -X POST -H 'content-type: application/json' -d ' {
"origin": {
  "address": "Kyoto, Japan"
  },
"destination": {
  "placeId": "ChIJrYtcv-urAWAR3XzWvXv8n_s"
  },
"travelMode": "DRIVE",
"routingPreference": "TRAFFIC_AWARE_OPTIMAL",
"trafficModel": "OPTIMISTIC"
}' \
-H 'Content-Type: application/json' \
-H 'X-Goog-Api-Key: YOUR_API_KEY' \
-H 'X-Goog-FieldMask: routes.duration' \
'https://routes.googleapis.com/directions/v2:computeRoutes'
```

This request returns the estimated duration using the `OPTIMISTIC` traffic model
type for the trip:

```json
"duration": "1238s"
```

If you change the traffic model type to `PESSIMISTIC`, the returned duration is
longer:

```json
"duration": "2436s"
```

> [!NOTE]
> **Note:** If you do not specify a `departureTime`, the implied departure is the request time. This means that you may get different values depending on when the request is sent.