Optimization API

A newer version of Route Optimization API is available.
A newer version of the API is available and is recommended for all users. Learn about the latest optimization features at Route Optimization Flexible API

Introduction

Nextbillion.ai Optimization API computes and returns an optimized route between an origin and destination which have multiple stop points in between. With NextBillion.ai's Route Optimization API you get.

  • Optimized routing between way points

  • Highly accurate ETAs with customized routes

  • Roundtrip optimization with customized destinations

A list of all parameters is specified in the next section.

Parameters

Loading..

Response Schema

Loading..

Query Limits

Nextbillion.ai allows a maximum rate limit of 6000 queries per minute or 100 queries/second for continuous requests.

Note: We can increase the quota if needed on request. Contact [email protected] for more details.

Examples

Sample API Request

1{{base_url}}/optimization/json?coordinates=41.35544869444527,2.0747669962025292|41.37498154684205,2.103705 4530396886|41.38772862000152,2.1311887061315526&destination=last&key={{api_key}}&mode=4w&source=first& roundtrip=false&with_geometry=true

For the above example, here are the parameters we have used-

  • We have set 3 coordinates separated by pipe symbol.

  • We have set the destination property equal to last. This means that the last coordinate in our given list will be treated as the destination.

  • The source property is set to first, so the first coordinate pair in the coordinates object will be treated as the source.

  • We have set mode as 4w which will return a route pertaining to 4 wheelers only.

  • The roundtrip property is set to false, so there will be no roundtrip returned.

  • By setting the with_geometry property as true, we will ensure that the route geometry is returned for each leg of the journey.

Sample API Response

1{
2 "code": "Ok",
3 "waypoints": [
4 {
5 "name": "",
6 "location": {
7 "latitude": 41.35544869444527,
8 "longitude": 2.0747669962025292
9 },
10 "trips_index": 0,
11 "waypoint_index": 0
12 },
13 {
14 "name": "",
15 "location": {
16 "latitude": 41.37498154684205,
17 "longitude": 2.1037054530396886
18 },
19 "trips_index": 0,
20 "waypoint_index": 1
21 },
22 {
23 "name": "",
24 "location": {
25 "latitude": 41.38772862000152,
26 "longitude": 2.1311887061315526
27 },
28 "trips_index": 0,
29 "waypoint_index": 2
30 }
31 ],
32 "trips": [
33 {
34 "geometry": "sjc{mA_hs}BtDcGlHkMrEgIpD}H~A}ErAqGj@iFRaHYwI_AsJi@_GcB_PIw@c@_JK{HJwHp@{LHwGAkFr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iBgAqA}@yAi@}@aGuIwEiHg@y @yBkDyEiH{FwJiEoHcHsHkB}CeBuCwIoNsE}GqDmFmFyHcEaF}CoDg@yC{FqGmEaGeEwFsJqM{AaCmByCqD_Hi@mAq@{AyB iG}@yC_A}Dc@}B}@sE_@aCy@oFgAoHmA}HkB}I_@oAQo@a@cAk@}AwAwBgFqGeCcCo@e@cAk@iAg@{CwA[QqCo@kD w@aAOkEo@sNaCuF_BmCqA{DsCm@{@gBsB_@i@w@cBg@cAi@sA_AaDk@mC[oBiAkBsH{_@{D_SsC{Ni@gDUsAmGoYqK{ i@[aBuAeFo@qBaAgBcAoA{@yDmC}NmC{D_CcNkEcWgAeGy@gD_AeGeAwF]uBu@wDOcAsCaOgF_Xi@mGoBmIwDcVo@iFm _@oaCiEmQmAsH{AqJYgBaDgT{AcIaEwX_CkU|DqZ^mMgJcl@uCiReUwyAeQ_z@gOg_AaAoFuB_MkEsVgCkQIg@SiAmA{GmFq ZoE_WmByKk@qDmRgmAoEmYuB}M_BmKcHae@eBgL{AuJeMcx@k@eESwA_A}FwEuVwB}Kk@sDw@sF}DaX_FqXmJog@_BuI sBuMuAyIa@mCwIuk@oBaLU{A}AyJk@sDgCiPiAkH_DcScEyW`ZaK|WcJ|d@eQs@_FeFi^wCg[kQzN",
35 "legs": [
36 {
37 "distance": 4777.4,
38 "duration": 561.1064897726275,
39 "summary": "Carretera del Hospitalet, Ronda de Dalt",
40 "steps": [
41 {
42 "distance": 547.3,
43 "duration": 64.28048349574225,
44 "geometry": "sjc{mA_hs}BtDcGlHkMrEgIpD}H~A}ErAqGj@iFRaHYwI_AsJi@_GcB_PIw@c@_JK{HJwHp@{LHwGAkFr@so@V uYTcYNsJXqG|@wLdC}PhAmEbB_ExDaIzPmK"
45 },
46 {
47 "distance": 23.4,
48 "duration": 2.7483342112193836,
49 "geometry": "}fa{mAq|~}Bx@dArAr@v@N^@f@GXE^Sn@m@"
50 },
51 {
52 "distance": 21,
53 "duration": 2.4664537792994468,
54 "geometry": "e{`{mAuz~}B|@_Bd@oBNiBUmC"
55 },
56 {
57 "distance": 872.7,
58 "duration": 102.49877205688702,
59 "geometry": "gx`{mA}h_~Bc@oBi@m@iAi@{@[mAIkNqe@eTix@iHqXeOod@gC{Hy`@cmAiOme@}D{LoEgNqJeZ}Ii\\cM} e@oEyPsHkWcDiNsAyFk@cDi@aDk@eF{DcYg@cF{@oFWyBiDuRq@{L"
60 },
61 {
62 "distance": 77,
63 "duration": 9.043663857431305,
64 "geometry": "ksg{mAckq~BhD}Ava@yQ"
65 },
66 {
67 "distance": 252.5,
68 "duration": 29.656170441576684,
69 "geometry": "ikf{mA{`r~B`HrA~Al@~ApAbBhB~ArBlA|BbCxH~AzJElFOfGi@nEsAlFoB|EiBfDyHtGeEnD{ElCuDjAaF~ AwD`AiDbAyAx@{@~Bc@V{@^"
70 },
71 {
72 "distance": 1817.2,
73 "duration": 213.4304670353788,
74 "geometry": "kng{mAcln~B}A\\uGdB_Ex@_@DgNdC{@NyOzCwMlAgCHoHXwFPsLFkQKcBGsLc@_Mq@oLcAoJcAuGw @yHuAwJuBwFkAgHeBcJuB}IqBgAWwFoAsu@wP{G}AaASiB]}WeFeGmAiCg@mMwCaJaCkEiAqFeAkB_@qB_@gFaAaOiDi@K iSmEeNsC_NgCiJgBkZcGqUcFsMkCaB]kAW{KwByA[_Ey@qAYaWsFmXuH{JoD}QaHuEaCmNqHyOsIkM{IwGsF_WyRyH_Hg[}Wy JeJ_[kV}LkIaEaCwG{DiN}HqQyHgE_B_EyAe@Q}@]eKuDiAe@eA[qUiGeMkCcAQ"
75 },
76 {
77 "distance": 364.5,
78 "duration": 42.810590597840395,
79 "geometry": "mue|mAmfy~BuFuDsAq@sC{A{As@_LaEuKwD_JyC{LaFmLoF{KyFwHcEgIeEiFoCkGoEoYcTeB{AwEcF_BmB yAkBaAiCsAwDYsB"
80 },
81 {
82 "distance": 91.7,
83 "duration": 10.770181502940918,
84 "geometry": "qgk|mAcd}~BgRl@e_@nA"
85 },
86 {
87 "distance": 327.1,
88 "duration": 38.41795386708805,
89 "geometry": "_{l|mAe`}~Bb@iQrAgj@d@uRr@oYlDc|@\\yMt@uZlAuZJwC"
90 },
91 {
92 "distance": 211.7,
93 "duration": 24.864203098937757,
94 "geometry": "qil|mA_td_CFqBf@{F?eFzDu}ATgIHuINqH`@aM"
95 },
96 {
97 "distance": 171.3,
98 "duration": 20.11921582828549,
99 "geometry": "s_l|mA{qi_Cb`@e]tZkXdNoMfBuA"
100 },
101 {
102 "distance": 0,
103 "duration": 0,
104 "geometry": "kpi|mAszk_C"
105 }
106 ]
107 },
108 {
109 "distance": 4335.4,
110 "duration": 509.1935102273724,
111 "summary": "Avinguda Diagonal, Avenida Diagonal",
112 "steps": [
113 {
114 "distance": 47,
115 "duration": 5.520158458432095,
116 "geometry": "kpi|mAszk_CvI}GbJwI"
117 },
118 {
119 "distance": 44.2,
120 "duration": 5.191297954525503,
121 "geometry": "ozh|mAinl_C|@^p@L~@L|BUbCoBjA{CRqD?gA"
122 },
123 {
124 "distance": 55.5,
125 "duration": 6.518484988148538,
126 "geometry": "}ih|mAi}l_Ci@aBu@iBaAk@gBQu@?cCVkA|@_AxAi@dBM~ACnC"
127 },
128 {
129 "distance": 208.1,
130 "duration": 24.44138245105785,
131 "geometry": "i~h|mAmul_CwJtIiLpKeUbS{o@jl@"
132 },
133 {
134 "distance": 233.4,
135 "duration": 27.412872004213853,
136 "geometry": "m~k|mAu|i_CyG|FQzI?bDQ|CIvFOvCUnIuEf_BUzFEtAOdH"
137 },
138 {
139 "distance": 247.5,
140 "duration": 29.06891954174348,
141 "geometry": "}ql|mAytd_Cu@dTMfJi@jQaB|l@sBbu@iAt`@"
142 },
143 {
144 "distance": 367.3,
145 "duration": 43.13945110174699,
146 "geometry": "k~l|mAg|~~BmHlGgA~@u@^kA^gARaAHkBCmAU_Cq@{Aq@}A}@gBeA}AsA_CiCiByBqAiBgAqA}@yAi@} @aGuIwEiHg@y@yBkDyEiH{FwJiEoHcHsHkB}CeBuCwIoNsE}GqDmFmFyHcEaF}CoD"
147 },
148 {
149 "distance": 688,
150 "duration": 80.80572381704854,
151 "geometry": "syq|mAqoc_Cg@yC{FqGmEaGeEwFsJqM{AaCmByCqD_Hi@mAq@{AyBiG}@yC_A}Dc@}B}@sE_@aCy@o FgAoHmA}HkB}I_@oAQo@a@cAk@}AwAwBgFqGeCcCo@e@cAk@iAg@{CwA[QqCo@kDw@aAOkEo@sNaCuF_BmCqA{DsCm@ {@gBsB_@i@w@cBg@cAi@sA_AaDk@mC[oBiAkBsH{_@{D_SsC{Ni@gDUsAmGoYqK{i@[aBuAeFo@qBaAgBcAoA"
152 },
153 {
154 "distance": 274.2,
155 "duration": 32.20483934685278,
156 "geometry": "gvx|mAyro_C{@yDmC}NmC{D_CcNkEcWgAeGy@gD_AeGeAwF]uBu@wDOcAsCaOgF_Xi@mGoBmIwDcV"
157 },
158 {
159 "distance": 366.1,
160 "duration": 42.99851088578703,
161 "geometry": "emz|mAuqu_Co@iFm_@oaCiEmQmAsH{AqJYgBaDgT{AcIaEwX_CkU"
162 },
163 {
164 "distance": 805.1,
165 "duration": 94.55913989114212,
166 "geometry": "qm||mA{u}_C|DqZ^mMgJcl@uCiReUwyAeQ_z@gOg_AaAoFuB_MkEsVgCkQIg@SiAmA{GmFqZoE_WmB yKk@qDmRgmAoEmY"
167 },
168 {
169 "distance": 291,
170 "duration": 34.17800237029233,
171 "geometry": "so`}mA{po`CuB}M_BmKcHae@eBgL{AuJeMcx@k@eESwA_A}FwEuVwB}Kk@sD"
172 },
173 {
174 "distance": 407.6,
175 "duration": 47.8726933544026,
176 "geometry": "qcb}mAo_v`Cw@sF}DaX_FqXmJog@_BuIsBuMuAyIa@mCwIuk@oBaLU{A}AyJk@sDgCiPiAkH_DcScEyW"
177 },
178 {
179 "distance": 169.3,
180 "duration": 19.88431546835221,
181 "geometry": "_md}mAq`_aC`ZaK|WcJ|d@eQ"
182 },
183 {
184 "distance": 92.2,
185 "duration": 10.828906592924238,
186 "geometry": "asa}mA}i`aCs@_FeFi^wCg["
187 },
188 {
189 "distance": 39,
190 "duration": 4.580557018698973,
191 "geometry": "s`b}mAolbaCkQzN"
192 },
193 {
194 "distance": 0,
195 "duration": 0,
196 "geometry": "_sb}mAs|aaC"
197 }
198 ]
199 }
200 ],
201 "duration": 1070.3,
202 "distance": 9112.8
203 }
204 ]
205}

API Error Codes

Response CodeDescriptionAdditional Notes
200Normal success case.Normal success case.
400Input validation failed.Such as missing parameter or parameter with invalid value type (for example value cannot be parsed into number).
401APIKEY not supplied or invalid.This error occurs when the wrong API key is passed in the request or the key is missing altogether
403APIKEY is valid but does not have access to requested resources.You might be querying for a geographical region which is not valid for your account, or requesting a service which is not enabled for you.
404Requested host/path not found.This error occurs when there is a malformed host name used.
422Could not process the request.There is an underlying map issue which prevents the processing of the request.
429Too many requests.QPM reached or API request count quota reached.
500Internal Service error.There was an internal issue with NextBillion.ai services. You can reach out to [[email protected]](mailto:[email protected]) for an explanation.