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

# Solve Routing Optimization

> Generate an optimized routing plan for a vehicle to efficiently execute a pool of operations within specified constraints. This endpoint uses vehicle routing algorithms to determine the best sequence of operations considering capacity limits, time constraints, and geographic locations.

**Failure Modes:**
- **401**: Invalid or missing authentication credentials
- **403**: Insufficient permissions, or routing is not enabled for your company
- **422**: Invalid request data that fails validation (invalid coordinates, negative capacities, etc.)
- **500**: Internal server error during routing optimization

**Required Auth Scopes:**
- `redistribution:read`



## OpenAPI

````yaml /api-reference/openapi.json post /operations/routing
openapi: 3.1.0
info:
  title: SWITCH API
  version: '1.0'
  description: >-
    The SWITCH API gives mobility and logistics teams programmatic access to
    SWITCH forecasts, fleet operations, routing and analytics. Every request is
    authenticated with an API key sent as a bearer token.
servers:
  - url: https://stage-api.getswitch.io
    description: Stage
security: []
tags:
  - name: Forecast
    description: Demand forecasts per zone and time window.
  - name: Operations
    description: Fleet imbalance, rebalancing suggestions and generated tasks.
  - name: Routing
    description: Route optimisation for single and multiple fleets.
  - name: Routing Sessions
    description: Saved routing sessions, their routes and drivers.
  - name: Routing Operations
    description: Complete, undo and re-route the stops of a route.
  - name: Fleet Management
    description: Your depots, stations, drivers and cargo vehicles.
  - name: Integrations
    description: Vehicles, statuses and commands on your fleet platform.
  - name: Station Based Analytics
    description: Analytics for station-based (docked) services.
  - name: Zone Based Analytics
    description: Analytics for free-floating services, by zone.
  - name: Free Float Analytics
    description: Trip history for free-floating services.
  - name: Transit Analytics
    description: Punctuality and service delivery for public transit.
  - name: Live
    description: Real-time fleet, delivery and transit status.
  - name: Grids
    description: Spatial grids used by forecasts and analytics.
  - name: API Keys
    description: Create and manage the API keys you call this API with.
paths:
  /operations/routing:
    post:
      tags:
        - Routing
      summary: Solve Routing Optimization
      description: >-
        Generate an optimized routing plan for a vehicle to efficiently execute
        a pool of operations within specified constraints. This endpoint uses
        vehicle routing algorithms to determine the best sequence of operations
        considering capacity limits, time constraints, and geographic locations.


        **Failure Modes:**

        - **401**: Invalid or missing authentication credentials

        - **403**: Insufficient permissions, or routing is not enabled for your
        company

        - **422**: Invalid request data that fails validation (invalid
        coordinates, negative capacities, etc.)

        - **500**: Internal server error during routing optimization


        **Required Auth Scopes:**

        - `redistribution:read`
      operationId: solve_routing
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoutingPayload'
        required: true
      responses:
        '200':
          description: >-
            Routing plan generated successfully with optimized sequence of
            operations and timing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RoutingResponse'
        '401':
          description: Unauthorized. Invalid or missing credentials.
        '403':
          description: >-
            Forbidden. Insufficient permissions, or routing is not enabled for
            your company.
        '422':
          description: >-
            Unprocessable Entity. Invalid request data such as invalid
            coordinates, negative capacities, or malformed operations.
        '500':
          description: >-
            Internal Server Error. Unexpected error during routing optimization
            or system failure.
      security:
        - HTTPBearer: []
        - HTTPBearer: []
components:
  schemas:
    RoutingPayload:
      properties:
        operation_pool:
          items:
            $ref: '#/components/schemas/Operation'
          type: array
          title: Operation Pool
          description: List of operations to be considered in the routing solution
        start_point:
          $ref: '#/components/schemas/Point'
          description: Starting point for the routing solution
        end_point:
          $ref: '#/components/schemas/Point'
          description: Ending point for the routing solution
        max_duration:
          type: number
          title: Max Duration
          description: >-
            Maximum duration in minutes for the routing solution, default is 60
            minutes (1 hour)
          default: 60
        max_capacities:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type: object
          title: Max Capacities
          description: Maximum capacities for the routing solution
          default:
            vehicles: 1
            charged_battery: 10
            empty_battery: 10
        start_capacities:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type: object
          title: Start Capacities
          description: Starting capacities for the routing solution
          default:
            vehicles: 0
            charged_battery: 10
            empty_battery: 0
        start_time:
          type: string
          format: date-time
          title: Start Time
          description: Starting time for the routing solution, default is the current time
        must_include_vehicles:
          items:
            type: string
          type:
            - array
            - 'null'
          title: Must Include Vehicles
          description: >-
            Optional list of vehicle IDs whose operations should be heavily
            prioritized. Operations targeting a vehicle in this list have their
            profit multiplied by 1000, making them very likely to be included in
            the optimized route.
        refill_capacities:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type:
            - object
            - 'null'
          title: Refill Capacities
          description: >-
            Total depot stock available for refilling across all stops. Positive
            values represent the total number of items at the depot; each refill
            loads the vehicle up to max_capacities, drawing from this stock
            until it is exhausted. Negative values mark capacities that are
            unloaded (dumped to 0) at the depot with no limit. Keys not present
            are left untouched.
          examples:
            - charged_battery: 68
              empty_battery: -1
        depot_service_time:
          type: number
          title: Depot Service Time
          description: >-
            Time in minutes the vehicle spends at depot per refill stop. Only
            used when refill_capacities is set.
          default: 5
        max_depot_refills:
          type:
            - integer
            - 'null'
          title: Max Depot Refills
          description: >-
            Maximum number of depot refill stops allowed. None means unlimited
            (bounded by max_duration). 0 disables the feature.
      type: object
      required:
        - operation_pool
        - start_point
        - end_point
      title: RoutingPayload
      description: 'Single-vehicle routing request: the operations and the vehicle''s limits.'
      examples:
        - end_point:
            latitude: 45.4781
            longitude: 9.2272
          max_capacities:
            charged_battery: 10
            empty_battery: 10
            vehicles: 4
          max_duration: 120
          operation_pool:
            - additional_notes: Battery level (12.0%) below threshold (20.0%)
              generated_at: '2026-11-30T07:55:00Z'
              latitude: 45.4642
              longitude: 9.1856
              operation_type: battery_swap
              priority: high
              priority_value: 2.4
              vehicle_id: acme-sc-0193
              vehicle_properties:
                battery_level: 12
                id: acme-sc-0193
                last_moved: '2026-11-30T06:41:03Z'
                last_seen: '2026-11-30T07:50:12Z'
                lat: 45.4642
                licence_plate: SC0193
                lon: 9.1856
                status: available
                vehicle_model: S-200
                vehicle_type: scooter
              zone_id: '1042'
            - additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
              generated_at: '2026-11-30T07:55:00Z'
              latitude: 45.4671
              longitude: 9.1883
              operation_type: pickup
              priority: medium
              priority_value: 2.1
              valid_from: '2026-11-30T08:00:00Z'
              valid_until: '2026-11-30T09:00:00Z'
              vehicle_id: acme-sc-0457
              zone_id: '1042'
            - additional_notes: 'Zone deficit 1.2 vehicles (threshold: -2.0)'
              generated_at: '2026-11-30T07:55:00Z'
              latitude: 45.4645
              longitude: 9.1992
              operation_type: dropoff
              priority: high
              priority_value: 4.8
              valid_from: '2026-11-30T09:00:00Z'
              vehicle_id: acme-sc-0457
              zone_id: '1043'
          start_capacities:
            charged_battery: 10
            empty_battery: 0
            vehicles: 0
          start_point:
            latitude: 45.4781
            longitude: 9.2272
          start_time: '2026-11-30T08:00:00Z'
    RoutingResponse:
      properties:
        plan:
          items:
            $ref: '#/components/schemas/RoutingStep'
          type: array
          title: Plan
          description: list of redistribution steps
        total_profit:
          type: number
          title: Total Profit
          description: Total profit achieved by the route
        total_duration:
          type: number
          title: Total Duration
          description: >-
            Total duration of the route in minutes, including travel to/from
            depot
        total_distance:
          type: number
          title: Total Distance
          description: >-
            Total distance of the route in kilometers, including travel to/from
            depot
        unassigned_operations:
          items:
            $ref: '#/components/schemas/Operation'
          type: array
          title: Unassigned Operations
          description: Operations that couldn't be assigned to the route
        utilization:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type: object
          title: Utilization
          description: Maximum capacity usage for each capacity type during the route
          examples:
            - charged_battery: 6
              empty_battery: 4
              vehicles: 8
      type: object
      required:
        - plan
        - total_profit
        - total_duration
        - total_distance
      title: RoutingResponse
      description: |-
        Represents the response structure for a redistribution request.

        This schema includes a list of steps in the redistribution plan.
      examples:
        - plan:
            - expected_arrival: '2026-11-30T08:14:00Z'
              operation:
                additional_notes: Battery level (12.0%) below threshold (20.0%)
                generated_at: '2026-11-30T07:55:00Z'
                latitude: 45.4642
                longitude: 9.1856
                operation_type: battery_swap
                priority: high
                priority_value: 2.4
                vehicle_id: acme-sc-0193
                vehicle_properties:
                  battery_level: 12
                  id: acme-sc-0193
                  last_moved: '2026-11-30T06:41:03Z'
                  last_seen: '2026-11-30T07:50:12Z'
                  lat: 45.4642
                  licence_plate: SC0193
                  lon: 9.1856
                  status: available
                  vehicle_model: S-200
                  vehicle_type: scooter
                zone_id: '1042'
              routing_parameters:
                capacity_delta:
                  charged_battery: -1
                  empty_battery: 1
                profit: 2.4
              step: 0
            - expected_arrival: '2026-11-30T08:23:00Z'
              operation:
                additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
                generated_at: '2026-11-30T07:55:00Z'
                latitude: 45.4671
                longitude: 9.1883
                operation_type: pickup
                priority: medium
                priority_value: 2.1
                valid_from: '2026-11-30T08:00:00Z'
                valid_until: '2026-11-30T09:00:00Z'
                vehicle_id: acme-sc-0457
                zone_id: '1042'
              routing_parameters:
                capacity_delta:
                  vehicles: 1
                profit: 2.1
              step: 1
            - expected_arrival: '2026-11-30T09:02:00Z'
              operation:
                additional_notes: 'Zone deficit 1.2 vehicles (threshold: -2.0)'
                generated_at: '2026-11-30T07:55:00Z'
                latitude: 45.4645
                longitude: 9.1992
                operation_type: dropoff
                priority: high
                priority_value: 4.8
                valid_from: '2026-11-30T09:00:00Z'
                vehicle_id: acme-sc-0457
                zone_id: '1043'
              routing_parameters:
                capacity_delta:
                  vehicles: -1
                profit: 4.8
              step: 2
          total_distance: 14.2
          total_duration: 78.5
          total_profit: 9.3
          unassigned_operations: []
          utilization:
            charged_battery: 10
            empty_battery: 1
            vehicles: 1
    Operation:
      properties:
        vehicle_id:
          type:
            - string
            - 'null'
          title: Vehicle Id
          description: >-
            Vehicle ID associated with the operation. Null for dropoffs
            generated by the suggestion strategies: a dropoff targets a zone,
            not a vehicle.
        latitude:
          type: number
          title: Latitude
          description: Latitude of the operation's location
        longitude:
          type: number
          title: Longitude
          description: Longitude of the operation's location
        zone_id:
          type: string
          title: Zone Id
          description: Zone ID where the operation is located
        operation_type:
          type: string
          title: Operation Type
          description: Type of operation, e.g., pickup, dropoff, or battery swap
        priority:
          type: string
          enum:
            - low
            - medium
            - high
            - must
          title: Priority
          description: Priority level of the operation, e.g., low, medium, or high
        priority_value:
          type: number
          minimum: 0
          title: Priority Value
          description: >-
            Continuous profit value used by the routing solver. Computed by
            suggest strategies as base_profit_for_op_type * urgency_factor
            (urgency in [1.0, 2.0]). The 'priority' enum is metadata only,
            except 'must' which still triggers hard-include.
        additional_notes:
          type:
            - string
            - 'null'
          title: Additional Notes
          description: >-
            Free-text notes about the operation, e.g. imbalance deficit or idle
            time.
        battery_level:
          type:
            - number
            - 'null'
          title: Battery Level
          description: Current battery level of the vehicle, if applicable
        generated_at:
          type: string
          format: date-time
          title: Generated At
          description: Timestamp when the operation was generated
        valid_from:
          type:
            - string
            - 'null'
          format: date-time
          title: Valid From
          description: Start of the validity window for this operation
        valid_until:
          type:
            - string
            - 'null'
          format: date-time
          title: Valid Until
          description: End of the validity window for this operation
        vehicle_properties:
          $ref: '#/components/schemas/VehicleWithoutZone'
          description: >-
            Full vehicle snapshot at the time the operation was generated.
            Serializable to VehicleWithoutZone. Populated by suggest strategies
            and preserved through the routing response so callers can persist it
            to the DB.
      type: object
      required:
        - vehicle_id
        - latitude
        - longitude
        - zone_id
        - operation_type
        - priority
        - priority_value
        - generated_at
      title: Operation
      description: |-
        Represents an operation to be performed.

        This schema includes details such as the operation's location, type,
        priority, and associated vehicle.
      examples:
        - additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
          generated_at: '2026-11-30T07:55:00Z'
          latitude: 45.4671
          longitude: 9.1883
          operation_type: pickup
          priority: medium
          priority_value: 2.1
          valid_from: '2026-11-30T08:00:00Z'
          valid_until: '2026-11-30T09:00:00Z'
          vehicle_id: acme-sc-0457
          zone_id: '1042'
    Point:
      properties:
        latitude:
          type: number
          title: Latitude
        longitude:
          type: number
          title: Longitude
      type: object
      required:
        - latitude
        - longitude
      title: Point
      description: Represents a geographical point with latitude and longitude.
    RoutingStep:
      properties:
        operation:
          $ref: '#/components/schemas/Operation'
          description: Operation to be performed in this step
        step:
          type: integer
          title: Step
          description: Step number in the redistribution plan
        expected_arrival:
          type: string
          format: date-time
          title: Expected Arrival
          description: Expected arrival time at the operation location
        routing_parameters:
          additionalProperties: true
          type: object
          title: Routing Parameters
          description: Routing parameters for this step
          examples:
            - capacity_delta:
                charged_battery: 0
                empty_battery: 0
                vehicles: 1
              profit: 3
      type: object
      required:
        - operation
        - step
        - expected_arrival
        - routing_parameters
      title: RoutingStep
      description: |-
        Represents a single step in a redistribution plan.

        This schema includes details about the vehicle, its target zone, and
        the operation to be performed.
    VehicleWithoutZone:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the vehicle
        licence_plate:
          type:
            - string
            - 'null'
          title: Licence Plate
          description: Licence plate number of the vehicle
        lat:
          type:
            - number
            - 'null'
          title: Lat
          description: Latitude of the vehicle's current location
        lon:
          type:
            - number
            - 'null'
          title: Lon
          description: Longitude of the vehicle's current location
        vehicle_type:
          type:
            - string
            - 'null'
          title: Vehicle Type
          description: Type of the vehicle, e.g., 'scooter', 'bike', 'car'
        vehicle_model:
          type:
            - string
            - 'null'
          title: Vehicle Model
          description: Model of the vehicle, e.g., 'Model X', 'Model Y'
        battery_level:
          type:
            - integer
            - 'null'
          title: Battery Level
          description: Battery level of the vehicle, e.g., 100 for 100%
        battery_level_master:
          type:
            - integer
            - 'null'
          title: Battery Level Master
          description: >-
            Master battery level percentage (custom MDS setup only). None when
            not reported by the provider.
        last_seen:
          type:
            - string
            - 'null'
          format: date-time
          title: Last Seen
          description: Timestamp of the last time the vehicle was seen in the system
        last_moved:
          type:
            - string
            - 'null'
          format: date-time
          title: Last Moved
          description: Timestamp of the last time the vehicle moved
        status:
          type:
            - string
            - 'null'
          title: Status
          description: Current status of the vehicle, e.g., 'available', 'in-use'
      type: object
      required:
        - id
        - battery_level
      title: VehicleWithoutZone
      description: >-
        Represents a vehicle without zone assignment.


        Base schema containing all vehicle attributes except zone_id.

        Used when a grid service is not available and spatial zone mapping is
        skipped.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer
      description: >-
        An API key, sent as `Authorization: Bearer <key>`. Create one in the
        SWITCH Copilot under **Settings → API keys** (needs the API keys
        permission in your company), or with `POST /auth/api-keys`. The key is
        shown once, at creation.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.