[{"data":1,"prerenderedAt":560},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-client":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":559,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-client\u002Findex.md",{},"Client",{"type":8,"value":9,"toc":550},"minimark",[10,14,53,58,144,165,169,228,232,265,272,276,282],[11,12,13],"p",{},"The Client plugin turns each operation in your OpenAPI spec into a typed function that calls a client module you write. The generated code has no Fetch, axios, or Kubb runtime dependency.",[11,15,16,17,21,22,21,25,28,29,32,33,36,37,40,41,44,45,48,49,52],{},"Each function takes grouped ",[18,19,20],"code",{},"path",", ",[18,23,24],{},"query",[18,26,27],{},"headers",", and ",[18,30,31],{},"body"," parameters and passes the operation's auth requirements to your client in a ",[18,34,35],{},"security"," list. A single call can pass its own ",[18,38,39],{},"client"," to replace the default. For a ready-made client, use ",[18,42,43],{},"@kubb\u002Fplugin-fetch"," or ",[18,46,47],{},"@kubb\u002Fplugin-axios"," instead. The query plugins and ",[18,50,51],{},"@kubb\u002Fplugin-mcp"," work with this plugin too, and their hooks and handlers then call your client module.",[54,55,57],"h2",{"id":56},"installation","Installation",[59,60,62,91,109,127],"code-group",{"sync":61},"package-manager",[63,64,69],"pre",{"language":65,"filename":66,"code":67,"class":68},"shell","bun","bun add -d @kubb\u002Fplugin-client","highlights",[18,70,72],{"class":71},"language-shell",[73,74,77,81,85,88],"span",{"class":75,"style":76},"line","display: inline",[73,78,80],{"style":79},"color:#6f42c1;--hls-dark:#b392f0","bun ",[73,82,84],{"style":83},"color:#24292e;--hls-dark:#e1e4e8","add -d ",[73,86,87],{"style":83},"@",[73,89,90],{"style":83},"kubb\u002Fplugin-client",[63,92,95],{"language":65,"filename":93,"code":94,"class":68},"pnpm","pnpm add -D @kubb\u002Fplugin-client",[18,96,97],{"class":71},[73,98,99,102,105,107],{"class":75,"style":76},[73,100,101],{"style":79},"pnpm ",[73,103,104],{"style":83},"add -D ",[73,106,87],{"style":83},[73,108,90],{"style":83},[63,110,113],{"language":65,"filename":111,"code":112,"class":68},"npm","npm install --save-dev @kubb\u002Fplugin-client",[18,114,115],{"class":71},[73,116,117,120,123,125],{"class":75,"style":76},[73,118,119],{"style":79},"npm ",[73,121,122],{"style":83},"install --save-dev ",[73,124,87],{"style":83},[73,126,90],{"style":83},[63,128,131],{"language":65,"filename":129,"code":130,"class":68},"yarn","yarn add -D @kubb\u002Fplugin-client",[18,132,133],{"class":71},[73,134,135,138,140,142],{"class":75,"style":76},[73,136,137],{"style":79},"yarn ",[73,139,104],{"style":83},[73,141,87],{"style":83},[73,143,90],{"style":83},[11,145,146,147,150,151,156,157,160,161,164],{},"Or run ",[18,148,149],{},"kubb add plugin-client"," to install the version the ",[152,153,155],"a",{"href":154},"\u002Fregistry","Kubb registry"," pins and add ",[18,158,159],{},"pluginClient()"," to ",[18,162,163],{},"kubb.config.ts",".",[54,166,168],{"id":167},"setup","Setup",[170,171,172,201,215],"ul",{},[173,174,175,176,179,180,182,183,186,187,190,191,182,194,186,197,200],"li",{},"Set the required ",[18,177,178],{},"importPath"," option to your client module. The module must export ",[18,181,39],{}," and the ",[18,184,185],{},"Options"," and ",[18,188,189],{},"RequestResult"," types. When the spec has server-sent event operations, it must also export ",[18,192,193],{},"toEventStream",[18,195,196],{},"EventStreamResult",[18,198,199],{},"SuccessOf"," types.",[173,202,203,204,207,208,211,212,164],{},"Add ",[18,205,206],{},"@kubb\u002Fplugin-ts"," for the operation types, or ",[18,209,210],{},"@kubb\u002Fplugin-zod"," with ",[18,213,214],{},"inferred: true",[173,216,203,217,219,220,223,224,227],{},[18,218,210],{}," when you set ",[18,221,222],{},"validator",", and install ",[18,225,226],{},"zod"," v4. Generation fails without the plugin.",[54,229,231],{"id":230},"options-worth-knowing","Options worth knowing",[170,233,234,239,252],{},[173,235,236,238],{},[18,237,178],{}," is written into every generated import as given, so it must resolve from the generated file. A relative path, a package name, or an alias works.",[173,240,241,244,245,247,248,251],{},[18,242,243],{},"validator: 'zod'"," passes response schemas from ",[18,246,210],{}," to your client. Use ",[18,249,250],{},"{ request: 'zod', response: 'zod' }"," to also pass request body schemas.",[173,253,254,257,258,261,262,164],{},[18,255,256],{},"throwOnErrorDefault"," is the ",[18,259,260],{},"throwOnError"," value each call passes to your client. The default is ",[18,263,264],{},"true",[11,266,267,268,271],{},"See ",[152,269,185],{"href":270},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Foptions"," for every option and its default.",[54,273,275],{"id":274},"example","Example",[11,277,278,279,164],{},"The config below groups the generated functions by tag and points them at the client module in ",[18,280,281],{},"src\u002Fclient.ts",[63,283,286],{"language":284,"filename":163,"code":285,"class":68},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\nimport { pluginClient } from '@kubb\u002Fplugin-client'\n\nexport default defineConfig({\n  input: '.\u002FpetStore.yaml',\n  output: { path: '.\u002Fsrc\u002Fgen' },\n  plugins: [\n    pluginTs(),\n    pluginClient({\n      output: { path: 'clients', mode: 'directory', barrel: { type: 'named' } },\n      group: { type: 'tag' },\n      \u002F\u002F resolved from each generated file: src\u002Fgen\u002Fclients\u002F\u003Ctag>\u002F to src\u002Fclient.ts\n      importPath: '..\u002F..\u002F..\u002Fclient',\n    }),\n  ],\n})",[18,287,289,312,313,312,329,312,345,312,347,312,361,312,378,312,401,312,413,312,426,312,435,312,485,312,507,312,515,312,528,312,537,312,546],{"class":288},"language-typescript",[73,290,291,295,299,302,305,308],{"class":75,"style":76},[73,292,294],{"style":293},"color:#d73a49;--hls-dark:#f97583","import ",[73,296,298],{"style":297},"color:#005cc5;--hls-dark:#79b8ff","{ ",[73,300,301],{"style":83},"defineConfig ",[73,303,304],{"style":297},"} ",[73,306,307],{"style":293},"from ",[73,309,311],{"style":310},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[73,314,315,317,319,322,324,326],{"class":75,"style":76},[73,316,294],{"style":293},[73,318,298],{"style":297},[73,320,321],{"style":83},"pluginTs ",[73,323,304],{"style":297},[73,325,307],{"style":293},[73,327,328],{"style":310},"'@kubb\u002Fplugin-ts'",[73,330,331,333,335,338,340,342],{"class":75,"style":76},[73,332,294],{"style":293},[73,334,298],{"style":297},[73,336,337],{"style":83},"pluginClient ",[73,339,304],{"style":297},[73,341,307],{"style":293},[73,343,344],{"style":310},"'@kubb\u002Fplugin-client'",[73,346],{"class":75,"style":76},[73,348,349,352,355,358],{"class":75,"style":76},[73,350,351],{"style":293},"export ",[73,353,354],{"style":293},"default ",[73,356,357],{"style":79},"defineConfig",[73,359,360],{"style":297},"({",[73,362,363,366,369,372,375],{"class":75,"style":76},[73,364,365],{"style":297},"  ",[73,367,368],{"style":297},"input",[73,370,371],{"style":293},": ",[73,373,374],{"style":310},"'.\u002FpetStore.yaml'",[73,376,377],{"style":293},",",[73,379,380,382,385,387,389,391,393,396,399],{"class":75,"style":76},[73,381,365],{"style":293},[73,383,384],{"style":297},"output",[73,386,371],{"style":293},[73,388,298],{"style":297},[73,390,20],{"style":297},[73,392,371],{"style":293},[73,394,395],{"style":310},"'.\u002Fsrc\u002Fgen' ",[73,397,398],{"style":297},"}",[73,400,377],{"style":293},[73,402,403,405,408,410],{"class":75,"style":76},[73,404,365],{"style":293},[73,406,407],{"style":297},"plugins",[73,409,371],{"style":293},[73,411,412],{"style":297},"[",[73,414,415,418,421,424],{"class":75,"style":76},[73,416,417],{"style":297},"    ",[73,419,420],{"style":79},"pluginTs",[73,422,423],{"style":297},"()",[73,425,377],{"style":293},[73,427,428,430,433],{"class":75,"style":76},[73,429,417],{"style":293},[73,431,432],{"style":79},"pluginClient",[73,434,360],{"style":297},[73,436,437,440,442,444,446,448,450,453,455,458,460,463,465,468,470,472,475,477,480,483],{"class":75,"style":76},[73,438,439],{"style":297},"      ",[73,441,384],{"style":297},[73,443,371],{"style":293},[73,445,298],{"style":297},[73,447,20],{"style":297},[73,449,371],{"style":293},[73,451,452],{"style":310},"'clients'",[73,454,21],{"style":293},[73,456,457],{"style":297},"mode",[73,459,371],{"style":293},[73,461,462],{"style":310},"'directory'",[73,464,21],{"style":293},[73,466,467],{"style":297},"barrel",[73,469,371],{"style":293},[73,471,298],{"style":297},[73,473,474],{"style":297},"type",[73,476,371],{"style":293},[73,478,479],{"style":310},"'named' ",[73,481,482],{"style":297},"} }",[73,484,377],{"style":293},[73,486,487,489,492,494,496,498,500,503,505],{"class":75,"style":76},[73,488,439],{"style":293},[73,490,491],{"style":297},"group",[73,493,371],{"style":293},[73,495,298],{"style":297},[73,497,474],{"style":297},[73,499,371],{"style":293},[73,501,502],{"style":310},"'tag' ",[73,504,398],{"style":297},[73,506,377],{"style":293},[73,508,509,511],{"class":75,"style":76},[73,510,439],{"style":293},[73,512,514],{"style":513},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F resolved from each generated file: src\u002Fgen\u002Fclients\u002F\u003Ctag>\u002F to src\u002Fclient.ts",[73,516,517,519,521,523,526],{"class":75,"style":76},[73,518,439],{"style":513},[73,520,178],{"style":297},[73,522,371],{"style":293},[73,524,525],{"style":310},"'..\u002F..\u002F..\u002Fclient'",[73,527,377],{"style":293},[73,529,530,532,535],{"class":75,"style":76},[73,531,417],{"style":293},[73,533,534],{"style":297},"})",[73,536,377],{"style":293},[73,538,539,541,544],{"class":75,"style":76},[73,540,365],{"style":293},[73,542,543],{"style":297},"]",[73,545,377],{"style":293},[73,547,548],{"class":75,"style":76},[73,549,534],{"style":297},{"title":551,"searchDepth":552,"depth":552,"links":553},"",5,[554,556,557,558],{"id":56,"depth":555,"text":57},2,{"id":167,"depth":555,"text":168},{"id":230,"depth":555,"text":231},{"id":274,"depth":555,"text":275},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-client",1793747911631]