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

# optimize

> Solve a vehicle routing problem



## OpenAPI

````yaml /openapi/openapi.json post /optimize
openapi: 3.1.0
info:
  title: JustRouting API
  version: v1
  description: >-
    OSRM-compatible routing services (route, table, match, trip, nearest) and a
    hosted VROOM vehicle routing solver (optimize). All requests require a
    Bearer API key. Coordinates use `lng,lat` order and must be within a single
    country (Southeast Asia).
  contact:
    email: hello@justrouting.tech
    name: JustRouting
    url: https://justrouting.tech
servers:
  - url: https://api.justrouting.tech
    description: Production
security:
  - bearerAuth: []
tags:
  - name: route
    description: Directions between coordinates
  - name: table
    description: NxN travel time/distance matrix
  - name: match
    description: Map matching for GPS traces
  - name: trip
    description: Traveling salesman optimization
  - name: nearest
    description: Snap a coordinate to the road network
  - name: optimize
    description: Hosted VROOM vehicle routing solver
  - name: geocode
    description: 'Forward geocoding: place name or address into coordinates'
paths:
  /optimize:
    post:
      tags:
        - optimize
      summary: Solve a vehicle routing problem
      operationId: solveOptimize
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VroomInput'
            examples:
              twoVehiclesSixJobs:
                summary: Two vehicles, six jobs
                value:
                  vehicles:
                    - id: 1
                      profile: car
                      start:
                        - 103.79234106
                        - 1.32463108
                      end:
                        - 103.79234106
                        - 1.32463108
                    - id: 2
                      profile: car
                      start:
                        - 103.82324228
                        - 1.32408622
                      end:
                        - 103.82324228
                        - 1.32408622
                  jobs:
                    - id: 1
                      location:
                        - 103.79751693
                        - 1.31035001
                    - id: 2
                      location:
                        - 103.78432387
                        - 1.31490148
                    - id: 3
                      location:
                        - 103.79763397
                        - 1.31980519
                    - id: 4
                      location:
                        - 103.81234512
                        - 1.31824846
                    - id: 5
                      location:
                        - 103.82152987
                        - 1.30984208
                    - id: 6
                      location:
                        - 103.83701939
                        - 1.32143977
      responses:
        '200':
          description: Problem solved
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VroomOutput'
        '400':
          description: Invalid input (code 2) — details in the `error` field
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VroomError'
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthError'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitError'
        '500':
          description: Internal error (code 1) — details in the `error` field
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VroomError'
components:
  schemas:
    VroomInput:
      type: object
      required:
        - vehicles
      properties:
        vehicles:
          type: array
          items:
            $ref: '#/components/schemas/Vehicle'
          description: 'Available vehicles. Free plan: up to 10; Hobby: up to 50.'
        jobs:
          type: array
          items:
            $ref: '#/components/schemas/Job'
          description: >-
            Jobs to serve. Optional if `shipments` is provided. Free plan: up to
            100 tasks; Hobby: up to 1,000.
        shipments:
          type: array
          items:
            $ref: '#/components/schemas/Shipment'
          description: Pickup-and-delivery tasks (pickup must precede delivery).
        matrices:
          $ref: '#/components/schemas/CustomMatrices'
          description: >-
            Custom matrices per profile; skips OSRM table calls when `durations`
            are provided for all used profiles.
        options:
          $ref: '#/components/schemas/VroomOptions'
          description: Solver options; `g` maps to the VROOM `-g` flag.
    VroomOutput:
      type: object
      properties:
        code:
          type: integer
          enum:
            - 0
            - 1
            - 2
            - 3
          description: 0 = ok, 1 = internal error, 2 = input error, 3 = routing error.
        error:
          type: string
          description: Present when code != 0.
        summary:
          $ref: '#/components/schemas/Summary'
        unassigned:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
              type:
                type: string
                description: '`job`, `pickup` or `delivery`.'
              location:
                type: array
                items:
                  type: number
              location_index:
                type: integer
                description: Row/column in custom matrices, if provided in input.
              description:
                type: string
        routes:
          type: array
          items:
            $ref: '#/components/schemas/VroomRoute'
    VroomError:
      type: object
      properties:
        code:
          type: integer
        error:
          type: string
    AuthError:
      type: object
      properties:
        error:
          type: string
          description: '`missing Authorization header` or `invalid or revoked API key`.'
    RateLimitError:
      type: object
      properties:
        code:
          type: string
          enum:
            - rate_limited
        message:
          type: string
    Vehicle:
      type: object
      required:
        - id
      properties:
        id:
          type: integer
        profile:
          type: string
          enum:
            - car
            - motorcycle
          default: car
          description: >-
            Routing profile (defaults to `car`). JustRouting supports `car` and
            `motorcycle`.
        description:
          type: string
        start:
          type: array
          items:
            type: number
          minItems: 2
          maxItems: 2
          description: Depot as `[lng, lat]`.
        end:
          type: array
          items:
            type: number
          minItems: 2
          maxItems: 2
          description: >-
            Return depot as `[lng, lat]`; same as start for a round trip; omit
            to stop at the last task.
        start_index:
          type: integer
          description: Row/column in custom matrices.
        end_index:
          type: integer
          description: Row/column in custom matrices.
        capacity:
          type: array
          items:
            type: integer
          description: >-
            Multidimensional capacity (e.g. weight, volume); the load at each
            route step must stay below capacity.
        skills:
          type: array
          items:
            type: integer
          description: Job skills must be a subset of vehicle skills.
        type:
          type: string
          description: Vehicle type, referenced by per-type setup and service times.
        time_window:
          $ref: '#/components/schemas/TimeWindow'
        breaks:
          type: array
          items:
            $ref: '#/components/schemas/Break'
          description: Rest periods during the route.
        speed_factor:
          type: number
          exclusiveMinimum: 0
          maximum: 5
          default: 1
          description: >-
            Scales all travel times for this vehicle, range `(0, 5]`, two
            decimals precision (defaults to 1).
        max_tasks:
          type: integer
          description: Maximum number of tasks in this vehicle's route.
        max_travel_time:
          type: integer
          description: Seconds.
        max_distance:
          type: integer
          description: Meters.
        costs:
          $ref: '#/components/schemas/VehicleCosts'
        steps:
          type: array
          items:
            $ref: '#/components/schemas/VehicleStep'
          description: >-
            Custom route. In solving mode this warm-starts the search: only
            `job`, `pickup` and `delivery` steps are used and `service_*` keys
            are ignored.
    Job:
      type: object
      required:
        - id
        - location
      properties:
        id:
          type: integer
        description:
          type: string
          description: A string describing this job.
        location:
          type: array
          items:
            type: number
          minItems: 2
          maxItems: 2
          description: >-
            `[lng, lat]`. Optional if custom matrices cover all used profiles
            (then `location_index` is required).
        location_index:
          type: integer
          description: >-
            Row/column in custom matrices; required when custom matrices are
            provided.
        setup:
          type: integer
          default: 0
          description: Setup duration in seconds (defaults to 0).
        service:
          type: integer
          default: 0
          description: Service duration in seconds (defaults to 0).
        setup_per_type:
          type: object
          additionalProperties:
            type: integer
          description: >-
            Setup durations per vehicle type; overrides `setup` for vehicles of
            that type.
        service_per_type:
          type: object
          additionalProperties:
            type: integer
          description: >-
            Service durations per vehicle type; overrides `service` for vehicles
            of that type.
        delivery:
          type: array
          items:
            type: integer
          description: Amounts to deliver (loaded at vehicle start).
        pickup:
          type: array
          items:
            type: integer
          description: Amounts to pick up (returned at vehicle end).
        skills:
          type: array
          items:
            type: integer
          description: >-
            Skills required to serve this job; the vehicle must have all of
            them.
        priority:
          type: integer
          minimum: 0
          maximum: 100
          default: 0
          description: Higher priority tasks are preferred when not all tasks fit.
        time_windows:
          type: array
          items:
            $ref: '#/components/schemas/TimeWindow'
          description: Valid slots for service start.
    Shipment:
      type: object
      required:
        - pickup
        - delivery
      properties:
        pickup:
          $ref: '#/components/schemas/ShipmentStep'
        delivery:
          $ref: '#/components/schemas/ShipmentStep'
        amount:
          type: array
          items:
            type: integer
          description: Amounts loaded at the pickup and unloaded at the delivery.
        skills:
          type: array
          items:
            type: integer
          description: >-
            Skills required to serve this shipment; the vehicle must have all of
            them.
        priority:
          type: integer
          minimum: 0
          maximum: 100
          default: 0
          description: Higher priority shipments are preferred when not all tasks fit.
    CustomMatrices:
      type: object
      description: >-
        Per-profile custom matrices (`durations`, `distances`, `costs`).
        Providing `durations` for all used profiles makes `location`, `start`
        and `end` optional; use the `*_index` keys instead.
      additionalProperties:
        type: object
        properties:
          durations:
            type: array
            items:
              type: array
              items:
                type: integer
            description: Custom travel-time matrix used for all timing checks.
          distances:
            type: array
            items:
              type: array
              items:
                type: integer
            description: Custom distance matrix; requires `durations`.
          costs:
            type: array
            items:
              type: array
              items:
                type: integer
            description: Custom cost matrix used in all route cost evaluations.
    VroomOptions:
      type: object
      properties:
        g:
          type: boolean
          default: false
          description: >-
            Add polyline geometry (and distances) to each route in the response.
            Same effect as VROOM's `-g` flag.
    Summary:
      type: object
      properties:
        cost:
          type: integer
          description: Total cost for all routes.
        routes:
          type: integer
          description: Number of routes in the solution.
        unassigned:
          type: integer
          description: Number of tasks that could not be served.
        setup:
          type: integer
          description: Total setup time for all routes.
        service:
          type: integer
          description: Total service time for all routes.
        duration:
          type: integer
          description: Total travel time in seconds.
        waiting_time:
          type: integer
          description: Total waiting time for all routes.
        priority:
          type: integer
          description: Total priority sum for all assigned tasks.
        distance:
          type: integer
          description: Total distance in meters (with `options.g` or distance matrices).
        delivery:
          type: array
          items:
            type: integer
          description: Total delivery for all routes.
        pickup:
          type: array
          items:
            type: integer
          description: Total pickup for all routes.
        violations:
          type: array
          items:
            $ref: '#/components/schemas/Violation'
          description: Violation objects for all routes.
    VroomRoute:
      type: object
      properties:
        vehicle:
          type: integer
          description: Id of the vehicle assigned to this route.
        cost:
          type: integer
          description: Cost for this route.
        setup:
          type: integer
          description: Total setup time for this route.
        service:
          type: integer
          description: Total service time for this route.
        duration:
          type: integer
          description: Travel time in seconds.
        waiting_time:
          type: integer
          description: Total waiting time for this route.
        priority:
          type: integer
          description: Total priority sum for tasks in this route.
        distance:
          type: integer
          description: Meters (with `options.g` or distance matrices).
        geometry:
          type: string
          description: Encoded polyline (when `options.g` is true).
        delivery:
          type: array
          items:
            type: integer
          description: Total delivery for tasks in this route.
        pickup:
          type: array
          items:
            type: integer
          description: Total pickup for tasks in this route.
        description:
          type: string
          description: Vehicle description, if provided in input.
        steps:
          type: array
          items:
            $ref: '#/components/schemas/Step'
          description: Route steps.
        violations:
          type: array
          items:
            $ref: '#/components/schemas/Violation'
          description: Violation objects for this route.
    TimeWindow:
      type: array
      minItems: 2
      maxItems: 2
      items:
        type: integer
      description: >-
        `[start, end]` in seconds relative to the planning horizon, or absolute
        UNIX timestamps (consistent within one request). Both ends are
        inclusive.
    Break:
      type: object
      required:
        - id
      properties:
        id:
          type: integer
        time_windows:
          type: array
          items:
            $ref: '#/components/schemas/TimeWindow'
          description: Valid slots for break start.
        service:
          type: integer
          default: 0
          description: Break duration in seconds (defaults to 0).
        description:
          type: string
          description: A string describing this break.
        max_load:
          type: array
          items:
            type: integer
          description: Maximum vehicle load for which this break can happen.
    VehicleCosts:
      type: object
      properties:
        fixed:
          type: integer
          default: 0
          description: Cost of using this vehicle in the solution (defaults to 0).
        per_hour:
          type: integer
          default: 3600
          description: Cost for one hour of travel time (defaults to 3600).
        per_task_hour:
          type: integer
          default: 0
          description: Cost for one hour of task time, setup + service (defaults to 0).
        per_km:
          type: integer
          default: 0
          description: Cost for one kilometer of travel (defaults to 0).
    VehicleStep:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - start
            - job
            - pickup
            - delivery
            - break
            - end
          description: Step type.
        id:
          type: integer
          description: Task id for `job`, `pickup`, `delivery` or `break` steps.
        service_at:
          type: integer
          description: Hard constraint on service time (plan mode only).
        service_after:
          type: integer
          description: Hard constraint on service time lower bound (plan mode only).
        service_before:
          type: integer
          description: Hard constraint on service time upper bound (plan mode only).
    ShipmentStep:
      type: object
      required:
        - id
        - location
      properties:
        id:
          type: integer
        description:
          type: string
          description: A string describing this step.
        location:
          type: array
          items:
            type: number
          minItems: 2
          maxItems: 2
          description: >-
            `[lng, lat]`. Optional if custom matrices cover all used profiles
            (then `location_index` is required).
        location_index:
          type: integer
          description: >-
            Row/column in custom matrices; required when custom matrices are
            provided.
        setup:
          type: integer
          default: 0
          description: Task setup duration in seconds (defaults to 0).
        service:
          type: integer
          default: 0
          description: Task service duration in seconds (defaults to 0).
        setup_per_type:
          type: object
          additionalProperties:
            type: integer
          description: >-
            Task setup durations per vehicle type; overrides `setup` for
            vehicles of that type.
        service_per_type:
          type: object
          additionalProperties:
            type: integer
          description: >-
            Task service durations per vehicle type; overrides `service` for
            vehicles of that type.
        time_windows:
          type: array
          items:
            $ref: '#/components/schemas/TimeWindow'
          description: Valid slots for service start.
    Violation:
      type: object
      properties:
        cause:
          type: string
          enum:
            - delay
            - lead_time
            - load
            - max_tasks
            - skills
            - precedence
            - missing_break
            - max_travel_time
            - max_distance
            - max_load
          description: Violation cause.
        duration:
          type: integer
          description: >-
            Earliness (resp. lateness) if `cause` is `lead_time` (resp.
            `delay`).
    Step:
      type: object
      properties:
        type:
          type: string
          enum:
            - start
            - job
            - pickup
            - delivery
            - break
            - end
          description: 'Step type: `start`, `job`, `pickup`, `delivery`, `break` or `end`.'
        id:
          type: integer
          description: Task id for job/pickup/delivery/break steps.
        arrival:
          type: integer
          description: Arrival time (same clock as input).
        duration:
          type: integer
          description: Cumulated travel time in seconds.
        setup:
          type: integer
          description: Setup time at this step.
        service:
          type: integer
          description: Service time at this step.
        waiting_time:
          type: integer
          description: Waiting time upon arrival at this step.
        distance:
          type: integer
          description: Cumulated distance in meters (with `options.g`).
        location:
          type: array
          items:
            type: number
          description: '`[lng, lat]`, if provided in input.'
        location_index:
          type: integer
          description: Row/column in custom matrices, if provided in input.
        load:
          type: array
          items:
            type: integer
          description: Vehicle load after this step.
        description:
          type: string
          description: Step description, if provided in input.
        violations:
          type: array
          items:
            $ref: '#/components/schemas/Violation'
          description: Violation objects for this step.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key created in the JustRouting dashboard.

````

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