[{"data":1,"prerenderedAt":1884},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fconfigure-requests":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":1883,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fconfigure-requests.md",{},"Configure requests",{"type":8,"value":9,"toc":1864},"minimark",[10,14,19,31,116,147,378,382,385,458,473,485,489,504,592,598,739,750,761,765,771,850,1197,1242,1254,1383,1394,1399,1421,1529,1536,1543,1547,1550,1577,1593,1596,1606,1720,1723,1736,1745,1784,1787,1804,1807,1810,1820],[11,12,13],"p",{},"Set the base URL, credentials, shared headers, and interceptors on the generated Ky client, for every call or for one.",[15,16,18],"h2",{"id":17},"where-settings-apply","Where settings apply",[11,20,21,22,26,27,30],{},"Every generated function sends through the shared ",[23,24,25],"code",{},"client"," from ",[23,28,29],{},".kubb\u002Fclient.ts",", unless a call passes its own:",[32,33,34,50],"table",{},[35,36,37],"thead",{},[38,39,40,44,47],"tr",{},[41,42,43],"th",{},"Scope",[41,45,46],{},"How",[41,48,49],{},"Effect",[51,52,53,79,92,105],"tbody",{},[38,54,55,59,64],{},[56,57,58],"td",{},"Every call",[56,60,61],{},[23,62,63],{},"client.setConfig({ ... })",[56,65,66,67,70,71,74,75,78],{},"Merges into the shared config. ",[23,68,69],{},"headers",", ",[23,72,73],{},"mediaTypes",", and ",[23,76,77],{},"serializer"," merge per key.",[38,80,81,84,89],{},[56,82,83],{},"A separate client",[56,85,86],{},[23,87,88],{},"createClient({ ... })",[56,90,91],{},"Copies the shared config at creation, without its interceptors.",[38,93,94,97,102],{},[56,95,96],{},"A child client",[56,98,99],{},[23,100,101],{},"client.extend({ ... })",[56,103,104],{},"Copies the shared config and runs the parent's interceptors first.",[38,106,107,110,113],{},[56,108,109],{},"One call",[56,111,112],{},"The same key on the call",[56,114,115],{},"Wins over the client for that call.",[11,117,118,119,70,122,70,124,70,127,70,130,70,133,70,136,70,138,70,140,74,143,146],{},"The client takes ",[23,120,121],{},"baseURL",[23,123,69],{},[23,125,126],{},"auth",[23,128,129],{},"credentials",[23,131,132],{},"options",[23,134,135],{},"transport",[23,137,77],{},[23,139,73],{},[23,141,142],{},"validate",[23,144,145],{},"onValidationError",":",[148,149,153],"pre",{"language":150,"code":151,"class":152},"typescript","import { client, createClient } from '.\u002Fgen\u002F.kubb\u002Fclient'\nimport { getPetById } from '.\u002Fgen\u002Fclients\u002FgetPetById'\n\nclient.setConfig({ baseURL: import.meta.env.VITE_API_URL, headers: { 'X-Client': 'web' } })\n\nconst tenant = createClient({ baseURL: 'https:\u002F\u002Ftenant.example.com', auth: () => tenantToken })\nawait getPetById({ path: { petId: 1 }, client: tenant })\n\nawait getPetById({ path: { petId: 1 }, baseURL: 'http:\u002F\u002Flocalhost:3000' })","highlights",[23,154,156,187,188,187,204,187,206,187,262,187,264,187,305,187,343,187,345],{"class":155},"language-typescript",[157,158,161,165,169,172,174,177,180,183],"span",{"class":159,"style":160},"line","display: inline",[157,162,164],{"style":163},"color:#d73a49;--hls-dark:#f97583","import ",[157,166,168],{"style":167},"color:#005cc5;--hls-dark:#79b8ff","{ ",[157,170,25],{"style":171},"color:#24292e;--hls-dark:#e1e4e8",[157,173,70],{"style":163},[157,175,176],{"style":171},"createClient ",[157,178,179],{"style":167},"} ",[157,181,182],{"style":163},"from ",[157,184,186],{"style":185},"color:#032f62;--hls-dark:#9ecbff","'.\u002Fgen\u002F.kubb\u002Fclient'","\n",[157,189,190,192,194,197,199,201],{"class":159,"style":160},[157,191,164],{"style":163},[157,193,168],{"style":167},[157,195,196],{"style":171},"getPetById ",[157,198,179],{"style":167},[157,200,182],{"style":163},[157,202,203],{"style":185},"'.\u002Fgen\u002Fclients\u002FgetPetById'",[157,205],{"class":159,"style":160},[157,207,208,210,213,217,220,222,225,228,230,233,235,238,240,243,245,247,249,251,254,256,259],{"class":159,"style":160},[157,209,25],{"style":171},[157,211,212],{"style":163},".",[157,214,216],{"style":215},"color:#6f42c1;--hls-dark:#b392f0","setConfig",[157,218,219],{"style":167},"({ ",[157,221,121],{"style":167},[157,223,224],{"style":163},": ",[157,226,227],{"style":163},"import",[157,229,212],{"style":163},[157,231,232],{"style":167},"meta",[157,234,212],{"style":163},[157,236,237],{"style":167},"env",[157,239,212],{"style":163},[157,241,242],{"style":167},"VITE_API_URL",[157,244,70],{"style":163},[157,246,69],{"style":167},[157,248,224],{"style":163},[157,250,168],{"style":167},[157,252,253],{"style":185},"'X-Client'",[157,255,224],{"style":163},[157,257,258],{"style":185},"'web' ",[157,260,261],{"style":167},"} })",[157,263],{"class":159,"style":160},[157,265,266,269,272,275,278,280,282,284,287,289,291,293,296,299,302],{"class":159,"style":160},[157,267,268],{"style":163},"const ",[157,270,271],{"style":171},"tenant ",[157,273,274],{"style":163},"= ",[157,276,277],{"style":215},"createClient",[157,279,219],{"style":167},[157,281,121],{"style":167},[157,283,224],{"style":163},[157,285,286],{"style":185},"'https:\u002F\u002Ftenant.example.com'",[157,288,70],{"style":163},[157,290,126],{"style":167},[157,292,224],{"style":163},[157,294,295],{"style":167},"() ",[157,297,298],{"style":163},"=> ",[157,300,301],{"style":171},"tenantToken ",[157,303,304],{"style":167},"})",[157,306,307,310,313,315,318,320,322,325,327,330,333,335,337,339,341],{"class":159,"style":160},[157,308,309],{"style":163},"await ",[157,311,312],{"style":215},"getPetById",[157,314,219],{"style":167},[157,316,317],{"style":167},"path",[157,319,224],{"style":163},[157,321,168],{"style":167},[157,323,324],{"style":167},"petId",[157,326,224],{"style":163},[157,328,329],{"style":167},"1 ",[157,331,332],{"style":167},"}",[157,334,70],{"style":163},[157,336,25],{"style":167},[157,338,224],{"style":163},[157,340,271],{"style":171},[157,342,304],{"style":167},[157,344],{"class":159,"style":160},[157,346,347,349,351,353,355,357,359,361,363,365,367,369,371,373,376],{"class":159,"style":160},[157,348,309],{"style":163},[157,350,312],{"style":215},[157,352,219],{"style":167},[157,354,317],{"style":167},[157,356,224],{"style":163},[157,358,168],{"style":167},[157,360,324],{"style":167},[157,362,224],{"style":163},[157,364,329],{"style":167},[157,366,332],{"style":167},[157,368,70],{"style":163},[157,370,121],{"style":167},[157,372,224],{"style":163},[157,374,375],{"style":185},"'http:\u002F\u002Flocalhost:3000' ",[157,377,304],{"style":167},[15,379,381],{"id":380},"set-the-base-url","Set the base URL",[11,383,384],{},"A call uses the first base URL it finds:",[32,386,387,397],{},[35,388,389],{},[38,390,391,394],{},[41,392,393],{},"Order",[41,395,396],{},"Source",[51,398,399,409,423,433,443],{},[38,400,401,404],{},[56,402,403],{},"1",[56,405,406,408],{},[23,407,121],{}," on the call.",[38,410,411,414],{},[56,412,413],{},"2",[56,415,416,417,420,421,212],{},"The operation's own ",[23,418,419],{},"servers",", then its path's ",[23,422,419],{},[38,424,425,428],{},[56,426,427],{},"3",[56,429,430,431,212],{},"The client passed as ",[23,432,25],{},[38,434,435,438],{},[56,436,437],{},"4",[56,439,440,212],{},[23,441,442],{},"client.setConfig({ baseURL })",[38,444,445,448],{},[56,446,447],{},"5",[56,449,450,451,457],{},"The plugin's ",[452,453,455],"a",{"href":454},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Foptions#baseurl",[23,456,121],{}," option.",[459,460,462,463,465,466,469,470,212],"blockquote",{"as":461},"note","The spec's top-level ",[23,464,419],{}," URL is never used, even with the ",[23,467,468],{},"server"," option of ",[23,471,472],{},"adapterOas",[11,474,475,476,480,481,212],{},"See ",[452,477,479],{"href":478},"#which-server-a-call-picks","Which server a call picks"," and ",[452,482,484],{"href":483},"#named-servers","Named servers",[15,486,488],{"id":487},"authenticate-requests","Authenticate requests",[11,490,491,492,494,495,499,500,503],{},"Set ",[23,493,126],{}," to a token, or to a sync or async function that gets each ",[452,496,498],{"href":497},"https:\u002F\u002Fspec.openapis.org\u002Foas\u002Fv3.1.0#security-scheme-object","security scheme"," of the call. It returns the token, or ",[23,501,502],{},"undefined"," to skip the scheme:",[148,505,507],{"language":150,"code":506,"class":152},"client.setConfig({\n  auth: (auth) => (auth.type === 'apiKey' ? apiKey : localStorage.getItem('token') ?? undefined),\n})",[23,508,509,187,520,187,588],{"class":155},[157,510,511,513,515,517],{"class":159,"style":160},[157,512,25],{"style":171},[157,514,212],{"style":163},[157,516,216],{"style":215},[157,518,519],{"style":167},"({",[157,521,522,525,527,529,532,534,537,539,541,543,545,548,551,554,557,560,562,565,567,570,572,575,577,580,582,585],{"class":159,"style":160},[157,523,524],{"style":167},"  ",[157,526,126],{"style":167},[157,528,224],{"style":163},[157,530,531],{"style":167},"(",[157,533,126],{"style":171},[157,535,536],{"style":167},") ",[157,538,298],{"style":163},[157,540,531],{"style":167},[157,542,126],{"style":171},[157,544,212],{"style":163},[157,546,547],{"style":167},"type ",[157,549,550],{"style":163},"=== ",[157,552,553],{"style":185},"'apiKey' ",[157,555,556],{"style":163},"? ",[157,558,559],{"style":171},"apiKey ",[157,561,224],{"style":163},[157,563,564],{"style":171},"localStorage",[157,566,212],{"style":163},[157,568,569],{"style":215},"getItem",[157,571,531],{"style":167},[157,573,574],{"style":185},"'token'",[157,576,536],{"style":167},[157,578,579],{"style":163},"?? ",[157,581,502],{"style":167},[157,583,584],{"style":167},")",[157,586,587],{"style":163},",",[157,589,590],{"class":159,"style":160},[157,591,304],{"style":167},[11,593,594,595,597],{},"By default, ",[23,596,126],{}," adds no credentials. The scheme decides where the token goes:",[32,599,600,615],{},[35,601,602],{},[38,603,604,607,612],{},[41,605,606],{},"Scheme in the spec",[41,608,609,611],{},[23,610,126],{}," gets",[41,613,614],{},"The token goes to",[51,616,617,635,652,671,688,707,723],{},[38,618,619,625,630],{},[56,620,621,624],{},[23,622,623],{},"http"," bearer",[56,626,627],{},[23,628,629],{},"{ type: 'http', scheme: 'bearer' }",[56,631,632],{},[23,633,634],{},"Authorization: Bearer \u003Ctoken>",[38,636,637,642,647],{},[56,638,639,641],{},[23,640,623],{}," basic",[56,643,644],{},[23,645,646],{},"{ type: 'http', scheme: 'basic' }",[56,648,649],{},[23,650,651],{},"Authorization: Basic \u003Cbase64>",[38,653,654,660,665],{},[56,655,656,659],{},[23,657,658],{},"apiKey"," in header",[56,661,662],{},[23,663,664],{},"{ type: 'apiKey', name, in: 'header' }",[56,666,667,668],{},"the header named ",[23,669,670],{},"name",[38,672,673,678,683],{},[56,674,675,677],{},[23,676,658],{}," in query",[56,679,680],{},[23,681,682],{},"{ type: 'apiKey', name, in: 'query' }",[56,684,685,686],{},"the query parameter ",[23,687,670],{},[38,689,690,695,700],{},[56,691,692,694],{},[23,693,658],{}," in cookie",[56,696,697],{},[23,698,699],{},"{ type: 'apiKey', name, in: 'cookie' }",[56,701,702,703,706],{},"the ",[23,704,705],{},"Cookie"," header",[38,708,709,714,719],{},[56,710,711],{},[23,712,713],{},"oauth2",[56,715,716],{},[23,717,718],{},"{ type: 'oauth2', scopes, flows }",[56,720,721],{},[23,722,634],{},[38,724,725,730,735],{},[56,726,727],{},[23,728,729],{},"openIdConnect",[56,731,732],{},[23,733,734],{},"{ type: 'openIdConnect', scopes, url }",[56,736,737],{},[23,738,634],{},[459,740,741,742,745,746,749],{"as":461},"For basic auth, return the raw ",[23,743,744],{},"username:password",". The runtime base64-encodes it and adds the ",[23,747,748],{},"Basic"," prefix.",[11,751,752,753,480,757,212],{},"For a credential that no security scheme describes, such as a request signature, add a request interceptor. See ",[452,754,756],{"href":755},"#several-security-schemes","Several security schemes",[452,758,760],{"href":759},"#mutual-tls","Mutual TLS",[15,762,764],{"id":763},"add-interceptors","Add interceptors",[11,766,767,770],{},[23,768,769],{},"client.interceptors"," has three stacks. Each handler gets the value the one before it returned:",[32,772,773,789],{},[35,774,775],{},[38,776,777,780,783,786],{},[41,778,779],{},"Stack",[41,781,782],{},"Runs",[41,784,785],{},"Gets",[41,787,788],{},"Returns",[51,790,791,809,827],{},[38,792,793,798,801,806],{},[56,794,795],{},[23,796,797],{},"request",[56,799,800],{},"After the URL, body, and auth are built, before the send.",[56,802,803],{},[23,804,805],{},"ResolvedRequest",[56,807,808],{},"The request.",[38,810,811,816,819,824],{},[56,812,813],{},[23,814,815],{},"response",[56,817,818],{},"After the body is decoded, before the status check and validator.",[56,820,821],{},[23,822,823],{},"DecodedResponse",[56,825,826],{},"The result.",[38,828,829,834,844,847],{},[56,830,831],{},[23,832,833],{},"error",[56,835,836,837,840,841,212],{},"When a call fails: ",[23,838,839],{},"ResponseError",", network error, abort, ",[23,842,843],{},"ParseError",[56,845,846],{},"The error",[56,848,849],{},"Another error to throw, or nothing to keep it.",[851,852,853,933,1024],"code-group",{},[148,854,856],{"language":150,"filename":797,"code":855,"class":152},"client.interceptors.request.use((request) => {\n  request.headers['X-Request-ID'] = crypto.randomUUID()\n  return request\n})",[23,857,858,187,888,187,920,187,929],{"class":155},[157,859,860,862,864,867,869,871,873,876,879,881,883,885],{"class":159,"style":160},[157,861,25],{"style":171},[157,863,212],{"style":163},[157,865,866],{"style":167},"interceptors",[157,868,212],{"style":163},[157,870,797],{"style":167},[157,872,212],{"style":163},[157,874,875],{"style":215},"use",[157,877,878],{"style":167},"((",[157,880,797],{"style":171},[157,882,536],{"style":167},[157,884,298],{"style":163},[157,886,887],{"style":167},"{",[157,889,890,892,894,896,898,901,904,907,909,912,914,917],{"class":159,"style":160},[157,891,524],{"style":167},[157,893,797],{"style":171},[157,895,212],{"style":163},[157,897,69],{"style":167},[157,899,900],{"style":167},"[",[157,902,903],{"style":185},"'X-Request-ID'",[157,905,906],{"style":167},"] ",[157,908,274],{"style":163},[157,910,911],{"style":171},"crypto",[157,913,212],{"style":163},[157,915,916],{"style":215},"randomUUID",[157,918,919],{"style":167},"()",[157,921,922,924,927],{"class":159,"style":160},[157,923,524],{"style":167},[157,925,926],{"style":163},"return ",[157,928,797],{"style":171},[157,930,931],{"class":159,"style":160},[157,932,304],{"style":167},[148,934,936],{"language":150,"filename":815,"code":935,"class":152},"client.interceptors.response.use((result) => {\n  console.info(`${result.status} ${result.contentType}`)\n  return result\n})",[23,937,938,187,965,187,1012,187,1020],{"class":155},[157,939,940,942,944,946,948,950,952,954,956,959,961,963],{"class":159,"style":160},[157,941,25],{"style":171},[157,943,212],{"style":163},[157,945,866],{"style":167},[157,947,212],{"style":163},[157,949,815],{"style":167},[157,951,212],{"style":163},[157,953,875],{"style":215},[157,955,878],{"style":167},[157,957,958],{"style":171},"result",[157,960,536],{"style":167},[157,962,298],{"style":163},[157,964,887],{"style":167},[157,966,967,969,972,974,977,979,982,985,987,989,992,994,997,999,1001,1003,1006,1008,1010],{"class":159,"style":160},[157,968,524],{"style":167},[157,970,971],{"style":171},"console",[157,973,212],{"style":163},[157,975,976],{"style":215},"info",[157,978,531],{"style":167},[157,980,981],{"style":185},"`",[157,983,984],{"style":171},"${",[157,986,958],{"style":171},[157,988,212],{"style":163},[157,990,991],{"style":167},"status",[157,993,332],{"style":171},[157,995,996],{"style":185}," ",[157,998,984],{"style":171},[157,1000,958],{"style":171},[157,1002,212],{"style":163},[157,1004,1005],{"style":167},"contentType",[157,1007,332],{"style":171},[157,1009,981],{"style":185},[157,1011,584],{"style":167},[157,1013,1014,1016,1018],{"class":159,"style":160},[157,1015,524],{"style":167},[157,1017,926],{"style":163},[157,1019,958],{"style":171},[157,1021,1022],{"class":159,"style":160},[157,1023,304],{"style":167},[148,1025,1027],{"language":150,"filename":833,"code":1026,"class":152},"import { client, ResponseError } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nclass NotFoundError extends Error {}\n\nclient.interceptors.error.use((error) => {\n  if (ResponseError.is(error) && error.status === 401) scheduleTokenRefresh()\n  if (ResponseError.is(error) && error.status === 404) return new NotFoundError(error.message)\n})",[23,1028,1029,187,1048,187,1050,187,1067,187,1069,187,1095,187,1139,187,1193],{"class":155},[157,1030,1031,1033,1035,1037,1039,1042,1044,1046],{"class":159,"style":160},[157,1032,164],{"style":163},[157,1034,168],{"style":167},[157,1036,25],{"style":171},[157,1038,70],{"style":163},[157,1040,1041],{"style":215},"ResponseError ",[157,1043,179],{"style":167},[157,1045,182],{"style":163},[157,1047,186],{"style":185},[157,1049],{"class":159,"style":160},[157,1051,1052,1055,1058,1061,1064],{"class":159,"style":160},[157,1053,1054],{"style":163},"class ",[157,1056,1057],{"style":215},"NotFoundError ",[157,1059,1060],{"style":163},"extends ",[157,1062,1063],{"style":215},"Error ",[157,1065,1066],{"style":167},"{}",[157,1068],{"class":159,"style":160},[157,1070,1071,1073,1075,1077,1079,1081,1083,1085,1087,1089,1091,1093],{"class":159,"style":160},[157,1072,25],{"style":171},[157,1074,212],{"style":163},[157,1076,866],{"style":167},[157,1078,212],{"style":163},[157,1080,833],{"style":167},[157,1082,212],{"style":163},[157,1084,875],{"style":215},[157,1086,878],{"style":167},[157,1088,833],{"style":171},[157,1090,536],{"style":167},[157,1092,298],{"style":163},[157,1094,887],{"style":167},[157,1096,1097,1099,1102,1104,1106,1108,1111,1113,1115,1117,1120,1122,1124,1127,1129,1132,1134,1137],{"class":159,"style":160},[157,1098,524],{"style":167},[157,1100,1101],{"style":163},"if ",[157,1103,531],{"style":167},[157,1105,839],{"style":215},[157,1107,212],{"style":163},[157,1109,1110],{"style":215},"is",[157,1112,531],{"style":167},[157,1114,833],{"style":171},[157,1116,536],{"style":167},[157,1118,1119],{"style":163},"&& ",[157,1121,833],{"style":171},[157,1123,212],{"style":163},[157,1125,1126],{"style":167},"status ",[157,1128,550],{"style":163},[157,1130,1131],{"style":167},"401",[157,1133,536],{"style":167},[157,1135,1136],{"style":215},"scheduleTokenRefresh",[157,1138,919],{"style":167},[157,1140,1141,1143,1145,1147,1149,1151,1153,1155,1157,1159,1161,1163,1165,1167,1169,1172,1174,1176,1179,1182,1184,1186,1188,1191],{"class":159,"style":160},[157,1142,524],{"style":167},[157,1144,1101],{"style":163},[157,1146,531],{"style":167},[157,1148,839],{"style":215},[157,1150,212],{"style":163},[157,1152,1110],{"style":215},[157,1154,531],{"style":167},[157,1156,833],{"style":171},[157,1158,536],{"style":167},[157,1160,1119],{"style":163},[157,1162,833],{"style":171},[157,1164,212],{"style":163},[157,1166,1126],{"style":167},[157,1168,550],{"style":163},[157,1170,1171],{"style":167},"404",[157,1173,536],{"style":167},[157,1175,926],{"style":163},[157,1177,1178],{"style":163},"new ",[157,1180,1181],{"style":215},"NotFoundError",[157,1183,531],{"style":167},[157,1185,833],{"style":171},[157,1187,212],{"style":163},[157,1189,1190],{"style":167},"message",[157,1192,584],{"style":167},[157,1194,1195],{"class":159,"style":160},[157,1196,304],{"style":167},[11,1198,1199,1201,1202,70,1205,70,1208,70,1210,70,1213,70,1216,70,1218,74,1220,1223,1224,1201,1226,70,1229,70,1231,70,1234,70,1236,70,1238,74,1240,212],{},[23,1200,805],{}," has ",[23,1203,1204],{},"url",[23,1206,1207],{},"method",[23,1209,69],{},[23,1211,1212],{},"body",[23,1214,1215],{},"signal",[23,1217,129],{},[23,1219,132],{},[23,1221,1222],{},"stream",". ",[23,1225,823],{},[23,1227,1228],{},"data",[23,1230,991],{},[23,1232,1233],{},"statusText",[23,1235,69],{},[23,1237,1005],{},[23,1239,797],{},[23,1241,815],{},[11,1243,1244,1245,1247,1248,480,1251,146],{},"Handlers run in the order you register them. ",[23,1246,875],{}," returns an id for ",[23,1249,1250],{},"eject",[23,1252,1253],{},"update",[148,1255,1257],{"language":150,"code":1256,"class":152},"const id = client.interceptors.request.use((request) => request)\nclient.interceptors.request.update(id, (request) => ({ ...request, headers: { ...request.headers, 'X-Trace': 'on' } }))\nclient.interceptors.request.eject(id)",[23,1258,1259,187,1294,187,1361],{"class":155},[157,1260,1261,1263,1266,1268,1270,1272,1274,1276,1278,1280,1282,1284,1286,1288,1290,1292],{"class":159,"style":160},[157,1262,268],{"style":163},[157,1264,1265],{"style":171},"id ",[157,1267,274],{"style":163},[157,1269,25],{"style":171},[157,1271,212],{"style":163},[157,1273,866],{"style":167},[157,1275,212],{"style":163},[157,1277,797],{"style":167},[157,1279,212],{"style":163},[157,1281,875],{"style":215},[157,1283,878],{"style":167},[157,1285,797],{"style":171},[157,1287,536],{"style":167},[157,1289,298],{"style":163},[157,1291,797],{"style":171},[157,1293,584],{"style":167},[157,1295,1296,1298,1300,1302,1304,1306,1308,1310,1312,1315,1317,1319,1321,1323,1325,1327,1330,1332,1334,1336,1338,1340,1342,1344,1346,1348,1350,1353,1355,1358],{"class":159,"style":160},[157,1297,25],{"style":171},[157,1299,212],{"style":163},[157,1301,866],{"style":167},[157,1303,212],{"style":163},[157,1305,797],{"style":167},[157,1307,212],{"style":163},[157,1309,1253],{"style":215},[157,1311,531],{"style":167},[157,1313,1314],{"style":171},"id",[157,1316,70],{"style":163},[157,1318,531],{"style":167},[157,1320,797],{"style":171},[157,1322,536],{"style":167},[157,1324,298],{"style":163},[157,1326,219],{"style":167},[157,1328,1329],{"style":163},"...",[157,1331,797],{"style":171},[157,1333,70],{"style":163},[157,1335,69],{"style":167},[157,1337,224],{"style":163},[157,1339,168],{"style":167},[157,1341,1329],{"style":163},[157,1343,797],{"style":171},[157,1345,212],{"style":163},[157,1347,69],{"style":167},[157,1349,70],{"style":163},[157,1351,1352],{"style":185},"'X-Trace'",[157,1354,224],{"style":163},[157,1356,1357],{"style":185},"'on' ",[157,1359,1360],{"style":167},"} }))",[157,1362,1363,1365,1367,1369,1371,1373,1375,1377,1379,1381],{"class":159,"style":160},[157,1364,25],{"style":171},[157,1366,212],{"style":163},[157,1368,866],{"style":167},[157,1370,212],{"style":163},[157,1372,797],{"style":167},[157,1374,212],{"style":163},[157,1376,1250],{"style":215},[157,1378,531],{"style":167},[157,1380,1314],{"style":171},[157,1382,584],{"style":167},[459,1384,1385,1386,1389,1390,1393],{"as":461},"With ",[23,1387,1388],{},"throwOnError: false",", a non-2xx response resolves, so no error handler runs for it. An error thrown while a stream is read, in the ",[23,1391,1392],{},"for await"," loop, does not reach the error handlers either.",[1395,1396,1398],"h3",{"id":1397},"native-ky-hooks","Native Ky hooks",[11,1400,1401,1402,480,1405,1408,1409,1413,1414,1416,1417,1420],{},"For the native ",[23,1403,1404],{},"Request",[23,1406,1407],{},"Response",", pass ",[452,1410,1412],{"href":1411},"https:\u002F\u002Fgithub.com\u002Fsindresorhus\u002Fky#hooks","Ky hooks"," in ",[23,1415,132],{},". An ",[23,1418,1419],{},"afterResponse"," hook sees the response before Kubb decodes it:",[148,1422,1424],{"language":150,"code":1423,"class":152},"import { client } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nclient.setConfig({\n  options: {\n    hooks: { beforeRequest: [({ request }) => request.headers.set('traceparent', currentTraceparent())] },\n  },\n})",[23,1425,1426,187,1441,187,1443,187,1453,187,1463,187,1517,187,1525],{"class":155},[157,1427,1428,1430,1432,1435,1437,1439],{"class":159,"style":160},[157,1429,164],{"style":163},[157,1431,168],{"style":167},[157,1433,1434],{"style":171},"client ",[157,1436,179],{"style":167},[157,1438,182],{"style":163},[157,1440,186],{"style":185},[157,1442],{"class":159,"style":160},[157,1444,1445,1447,1449,1451],{"class":159,"style":160},[157,1446,25],{"style":171},[157,1448,212],{"style":163},[157,1450,216],{"style":215},[157,1452,519],{"style":167},[157,1454,1455,1457,1459,1461],{"class":159,"style":160},[157,1456,524],{"style":167},[157,1458,132],{"style":167},[157,1460,224],{"style":163},[157,1462,887],{"style":167},[157,1464,1465,1468,1471,1473,1475,1478,1480,1483,1486,1489,1491,1493,1495,1497,1499,1502,1504,1507,1509,1512,1515],{"class":159,"style":160},[157,1466,1467],{"style":167},"    ",[157,1469,1470],{"style":167},"hooks",[157,1472,224],{"style":163},[157,1474,168],{"style":167},[157,1476,1477],{"style":167},"beforeRequest",[157,1479,224],{"style":163},[157,1481,1482],{"style":167},"[({ ",[157,1484,1485],{"style":171},"request ",[157,1487,1488],{"style":167},"}) ",[157,1490,298],{"style":163},[157,1492,797],{"style":171},[157,1494,212],{"style":163},[157,1496,69],{"style":167},[157,1498,212],{"style":163},[157,1500,1501],{"style":215},"set",[157,1503,531],{"style":167},[157,1505,1506],{"style":185},"'traceparent'",[157,1508,70],{"style":163},[157,1510,1511],{"style":215},"currentTraceparent",[157,1513,1514],{"style":167},"())] }",[157,1516,587],{"style":163},[157,1518,1519,1521,1523],{"class":159,"style":160},[157,1520,524],{"style":163},[157,1522,332],{"style":167},[157,1524,587],{"style":163},[157,1526,1527],{"class":159,"style":160},[157,1528,304],{"style":167},[11,1530,1531,1532,212],{},"For the order hooks and core handlers run in, see ",[452,1533,1535],{"href":1534},"#hook-order","Hook order",[11,1537,1538,1539,212],{},"Next, ",[452,1540,1542],{"href":1541},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Ftransport","use a custom transport",[15,1544,1546],{"id":1545},"less-common-cases","Less common cases",[1395,1548,479],{"id":1549},"which-server-a-call-picks",[11,1551,1552,1553,1555,1556,1562,1563,1565,1566,1569,1570,1573,1574,212],{},"When an operation or path has its own ",[23,1554,419],{},", the ",[452,1557,1559],{"href":1558},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas\u002Foptions#server",[23,1560,1561],{},"server.index"," of ",[23,1564,472],{}," picks the entry, falling back to the first. A relative URL such as ",[23,1567,1568],{},"\u002Fv2",", or one with ",[23,1571,1572],{},"{variable}"," placeholders, is skipped, so the call uses the next source in ",[452,1575,381],{"href":1576},"#set-the-base-url",[11,1578,450,1579,1583,1584,1587,1588,1590,1591,212],{},[452,1580,1581],{"href":454},[23,1582,121],{}," option is written into ",[23,1585,1586],{},".kubb\u002Fconfig.ts",", which ",[23,1589,29],{}," passes to ",[23,1592,216],{},[1395,1594,484],{"id":1595},"named-servers",[11,1597,1598,1599,70,1601,1603,1604,146],{},"When an OpenAPI 3.2 server has a ",[23,1600,670],{},[23,1602,29],{}," exports its URL in ",[23,1605,419],{},[851,1607,1608,1670],{},[148,1609,1613],{"language":1610,"filename":1611,"code":1612,"class":152},"yaml","petStore.yaml","servers:\n  - url: https:\u002F\u002Fapi.example.com\n    name: production\n  - url: https:\u002F\u002Fstaging.example.com\n    name: staging",[23,1614,1616,187,1622,187,1634,187,1645,187,1659],{"class":1615},"language-yaml",[157,1617,1618,1620],{"class":159,"style":160},[157,1619,419],{"style":167},[157,1621,146],{"style":163},[157,1623,1624,1627,1629,1631],{"class":159,"style":160},[157,1625,1626],{"style":163},"  - ",[157,1628,1204],{"style":167},[157,1630,224],{"style":163},[157,1632,1633],{"style":185},"https:\u002F\u002Fapi.example.com",[157,1635,1636,1638,1640,1642],{"class":159,"style":160},[157,1637,1467],{"style":185},[157,1639,670],{"style":167},[157,1641,224],{"style":163},[157,1643,1644],{"style":185},"production",[157,1646,1647,1649,1652,1654,1656],{"class":159,"style":160},[157,1648,524],{"style":185},[157,1650,1651],{"style":163},"- ",[157,1653,1204],{"style":167},[157,1655,224],{"style":163},[157,1657,1658],{"style":185},"https:\u002F\u002Fstaging.example.com",[157,1660,1661,1663,1665,1667],{"class":159,"style":160},[157,1662,1467],{"style":185},[157,1664,670],{"style":167},[157,1666,224],{"style":163},[157,1668,1669],{"style":185},"staging",[148,1671,1674],{"language":150,"filename":1672,"code":1673,"class":152},"src\u002Fapi.ts","import { client, servers } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nclient.setConfig({ baseURL: servers.staging })",[23,1675,1676,187,1695,187,1697],{"class":155},[157,1677,1678,1680,1682,1684,1686,1689,1691,1693],{"class":159,"style":160},[157,1679,164],{"style":163},[157,1681,168],{"style":167},[157,1683,25],{"style":171},[157,1685,70],{"style":163},[157,1687,1688],{"style":171},"servers ",[157,1690,179],{"style":167},[157,1692,182],{"style":163},[157,1694,186],{"style":185},[157,1696],{"class":159,"style":160},[157,1698,1699,1701,1703,1705,1707,1709,1711,1713,1715,1718],{"class":159,"style":160},[157,1700,25],{"style":171},[157,1702,212],{"style":163},[157,1704,216],{"style":215},[157,1706,219],{"style":167},[157,1708,121],{"style":167},[157,1710,224],{"style":163},[157,1712,419],{"style":171},[157,1714,212],{"style":163},[157,1716,1717],{"style":167},"staging ",[157,1719,304],{"style":167},[1395,1721,756],{"id":1722},"several-security-schemes",[11,1724,1725,1726,1728,1729,1732,1733,1735],{},"When an operation lists several security requirements, the runtime sends the first one whose schemes all get a token. A requirement that needs an API key and a session cookie sends both. A header or query key you set yourself wins over the token. An ",[23,1727,713],{}," scheme also passes ",[23,1730,1731],{},"metadataUrl"," to ",[23,1734,126],{}," when the spec has one.",[11,1737,1738,1740,1741,1744],{},[23,1739,29],{}," exports the spec's schemes by name as ",[23,1742,1743],{},"securitySchemes",", and each generated call points at its own, with the scopes it needs:",[148,1746,1748],{"language":150,"code":1747,"class":152},"security: [{ ...securitySchemes.petstore_auth, scopes: ['write:pets'] }]",[23,1749,1750],{"class":155},[157,1751,1752,1755,1757,1760,1762,1764,1766,1769,1771,1774,1776,1778,1781],{"class":159,"style":160},[157,1753,1754],{"style":171},"security",[157,1756,224],{"style":163},[157,1758,1759],{"style":167},"[{ ",[157,1761,1329],{"style":163},[157,1763,1743],{"style":171},[157,1765,212],{"style":163},[157,1767,1768],{"style":167},"petstore_auth",[157,1770,70],{"style":163},[157,1772,1773],{"style":167},"scopes",[157,1775,224],{"style":163},[157,1777,900],{"style":167},[157,1779,1780],{"style":185},"'write:pets'",[157,1782,1783],{"style":167},"] }]",[1395,1785,760],{"id":1786},"mutual-tls",[11,1788,1789,1790,1793,1794,1796,1797,1800,1801,212],{},"When the spec has a ",[23,1791,1792],{},"mutualTLS"," scheme, ",[23,1795,1743],{}," leaves it out, because its credential is a client certificate on the connection, not on the request. In Node.js, send through an undici ",[23,1798,1799],{},"Agent"," that holds the certificate, with a ",[452,1802,1803],{"href":1541},"custom transport",[11,1805,1806],{},"In the browser, the browser picks the client certificate itself.",[1395,1808,1535],{"id":1809},"hook-order",[11,1811,1812,1813,1817,1818,146],{},"When you register ",[452,1814,1816],{"href":1815},"#native-ky-hooks","native Ky hooks"," next to ",[23,1819,769],{},[1821,1822,1823,1833,1841,1855],"ul",{},[1824,1825,1826,1828,1829,1832],"li",{},[23,1827,1477],{}," hooks run after the ",[23,1830,1831],{},"client.interceptors.request"," handlers.",[1824,1834,1835,1837,1838,1832],{},[23,1836,1419],{}," hooks see the raw response, before Kubb decodes it and before the ",[23,1839,1840],{},"client.interceptors.response",[1824,1842,1843,1845,1846,1848,1849,1851,1852,1854],{},[23,1844,1470],{}," in the ",[23,1847,132],{}," of a call replace the ",[23,1850,1470],{}," in the client's ",[23,1853,132],{},". They do not merge.",[1824,1856,1857,1858,1861,1862,212],{},"An instance you pass to ",[23,1859,1860],{},"createKyTransport"," keeps its own hooks, which run before the ones in ",[23,1863,132],{},{"title":1865,"searchDepth":1866,"depth":1866,"links":1867},"",5,[1868,1870,1871,1872,1876],{"id":17,"depth":1869,"text":18},2,{"id":380,"depth":1869,"text":381},{"id":487,"depth":1869,"text":488},{"id":763,"depth":1869,"text":764,"children":1873},[1874],{"id":1397,"depth":1875,"text":1398},3,{"id":1545,"depth":1869,"text":1546,"children":1877},[1878,1879,1880,1881,1882],{"id":1549,"depth":1875,"text":479},{"id":1595,"depth":1875,"text":484},{"id":1722,"depth":1875,"text":756},{"id":1786,"depth":1875,"text":760},{"id":1809,"depth":1875,"text":1535},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fconfigure-requests",1795015653396]