> Documentation index: https://developers.google.com/maps/documentation/llms.txt

Routes Preferred API provides performance-optimized versions of Directions APIs for ridesharing and deliveries use cases, with the `ComputeRoutes` and `ComputeRouteMatrix` (Preview) methods. The `ComputeCustomRoutes` method is deprecated and closed to new customers. The API is available only to select customers through Google sales.

## Routes Preferred API: key facts

- **Product:** Routes Preferred API
- **Also known as:** Google Maps Platform Routes Preferred API, Routes Preferred
- **Category:** Routes
- **Platform:** Web service (REST)
- **Runs on:** Server (backend code)
- **Launch stage:** GA
- **Lifecycle:** Active
- **Overview:** [Routes Preferred API overview](https://developers.google.com/maps/documentation/routes_preferred.md.txt)

## Routes Preferred API: when to use it

**Use Routes Preferred API when:**

- You build a ridesharing or deliveries solution and need routes with ETAs from a performance-optimized Directions service.
- You need to choose response fields and set a routing preference to trade route quality against response latency.
- You need distance and duration for many origin and destination pairs over streaming gRPC or REST (`ComputeRouteMatrix`, Preview).
- You need toll fee estimates, traffic on polylines, or two-wheeler routes as part of a route response.
**Don't use Routes Preferred API when:**

- Your project isn't approved for Routes Preferred API through Google sales. Use [Routes API](https://developers.google.com/maps/documentation/routes/quick-reference.md.txt) instead.

## Routes Preferred API: setup

- **Service to enable:** `routespreferred.googleapis.com`
- **Authentication:** API key, OAuth 2.0
- **Get started:** [Set up Routes Preferred API](https://developers.google.com/maps/documentation/routes_preferred/get_started.md.txt)
- **Reference:** [Routes Preferred API reference](https://developers.google.com/maps/documentation/routes_preferred/reference.md.txt)
- **Policies:** [Routes Preferred API policies](https://developers.google.com/maps/documentation/routes_preferred/support.md.txt#terms_of_use)

## Routes Preferred API: common mistakes

- **Problem:** `ComputeRoutes` requires a response field mask. Using the wildcard (`*`) or top-level `routes` in production increases latency, and latency can grow later when Google adds new response fields. **Fix:** Set the `X-Goog-FieldMask` header (or the `$fields`/`fields` URL parameter) to only the fields you need, for example `routes.duration,routes.distanceMeters,routes.polyline`. See [/maps/documentation/routes_preferred/choose_fields](https://developers.google.com/maps/documentation/routes_preferred/choose_fields.md.txt).
- **Problem:** `ComputeRouteMatrix` returns stream elements in no guaranteed order, and errors can apply to single elements instead of the whole stream. **Fix:** Include `status` in the field mask (otherwise every element appears `OK`), map each element back with `originIndex` and `destinationIndex`, keep your origin and destination list order, and check the `status` of each element. See [/maps/documentation/routes_preferred/compute_route_matrix](https://developers.google.com/maps/documentation/routes_preferred/compute_route_matrix.md.txt).
- **Problem:** `ComputeCustomRoutes` supports only `DRIVE` (or `TRAVEL_MODE_UNSPECIFIED`) and `TWO_WHEELER` and doesn't support `via` intermediate waypoints; other travel modes or `via` waypoints make the request fail. **Fix:** Use only `DRIVE` or `TWO_WHEELER` without `via` waypoints with `ComputeCustomRoutes`, or use `ComputeRoutes`. See [/maps/documentation/routes_preferred/custom_routes](https://developers.google.com/maps/documentation/routes_preferred/custom_routes.md.txt).
- **Problem:** Waypoint optimization in `ComputeRoutes` isn't enabled by default, so requests that rely on it don't get optimized waypoint order. **Fix:** Contact Support with estimated `ComputeRoutes` QPM using waypoint optimization and the typical and maximum number of waypoints per request. See [/maps/documentation/routes_preferred/waypoint_optimization_proxy_api](https://developers.google.com/maps/documentation/routes_preferred/waypoint_optimization_proxy_api.md.txt).

## Routes Preferred API: legacy and deprecated features

- **`ComputeCustomRoutes` method (Plan a Custom Route):** Deprecated. **Replacement:** `ComputeRoutes` for routing in Routes Preferred API, or Routes API `computeRoutes` (or Route Optimization API `optimizeTours` / `batchOptimizeTours`) for Navigation SDK route tokens. **Symptom:** Closed to new customers; `ComputeRoutes` in Routes Preferred API doesn't return a Navigation SDK route token.

## What you can do with Routes Preferred API

See the guides linked below for each task, or compare across products in the
[Capabilities Explorer](https://developers.google.com/maps/documentation/capabilities-explorer.md.txt).

- [Compute performance-optimized routes and ETAs with configurable quality-versus-latency preferences.](https://developers.google.com/maps/documentation/routes_preferred/config_trade_offs.md.txt) **Note:** Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Requires an `X-Goog-FieldMask` header (or `fields` URL parameter).
- [Calculate travel time and distance across an origin-destination matrix over streaming gRPC or REST.](https://developers.google.com/maps/documentation/routes_preferred/compute_route_matrix.md.txt) Preview **Note:** Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Stream elements return out of order; include `status` in the field mask and map results with `originIndex` and `destinationIndex`.
- [Estimate toll fees along a route or route matrix.](https://developers.google.com/maps/documentation/routes_preferred/calculate_toll_fees.md.txt) **Note:** Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Available in select regions; specify vehicle emission type and toll passes for accurate estimates.
- [Return traffic speed intervals along a route polyline.](https://developers.google.com/maps/documentation/routes_preferred/traffic_on_polylines.md.txt) **Note:** Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Include both `polyline` and `speedReadingIntervals` in `X-Goog-FieldMask`.
- [Compute routes tailored for two-wheeled motorized vehicles.](https://developers.google.com/maps/documentation/routes_preferred/route_two_wheel.md.txt) **Note:** Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Set `travelMode` to `TWO_WHEELER` (distinct from `BICYCLE`).
- [Configure waypoint modifiers for vehicle heading, side-of-road bias, pickup stopovers, and pass-through points.](https://developers.google.com/maps/documentation/routes_preferred/location_modifiers.md.txt) **Note:** Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. `heading` and `sideOfRoad` can't be used on the same waypoint.
- [Reorder intermediate route waypoints to reduce travel time.](https://developers.google.com/maps/documentation/routes_preferred/waypoint_optimization_proxy_api.md.txt) Experimental **Note:** Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Not enabled by default (contact Support to enable). Requires stopover waypoints only (no `via` waypoints) and `routes.optimizedIntermediateWaypointIndex` in the field mask.