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