OpenAPI to Fetch Client

Paste an OpenAPI 3.x or Swagger 2.0 spec and generate a dependency-free TypeScript fetch client with typed operations, path/query/body wiring, and your preferred call style.

Try:
Generated TypeScript client

What this tool does

Paste an OpenAPI 3.x or Swagger 2.0 document and this tool generates a single TypeScript file: a dependency-free client that calls your API with fetch. It focuses on the operations layer (paths): function names, path parameters, query parameters, header parameters, request bodies, response types, and the small runtime helpers needed to call fetch safely.

Use it when you already have, or plan to generate, schema types from components.schemas separately. Local $ref schema names become imported TypeScript types from your types_module; blank types_module emits placeholder aliases so the output still compiles while you wire real types in later.

It can generate:

Worked example

Use a spec like this:

{"openapi":"3.1.0","servers":[{"url":"https://api.example.com"}],"paths":{"/pets/{petId}":{"get":{"operationId":"getPet","parameters":[{"name":"petId","in":"path","required":true,"schema":{"type":"string"}},{"name":"include","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Pet"}}}}}}}}}

With the default functions, request object, and throw ApiError settings, the output contains a call shaped like:

export interface GetPetRequest {
  petId: string;
  include?: string;
}

export async function getPet(params: GetPetRequest, options: RequestOptions = {}): Promise<Pet> {
  return apiFetch("GET", `/pets/${encodeURIComponent(String(params.petId))}`, { include: params.include }, {}, undefined, options);
}

Point types_module at your generated schema declarations (for example ./types) so local refs such as #/components/schemas/Pet are imported as Pet. Use base_url when you want the generated file to call staging, production, or a test server regardless of the spec's servers section.

Limits and edge cases

FAQ

Does this replace a full OpenAPI SDK generator?

No. It is intentionally smaller: one dependency-free TypeScript file for operations over fetch. Full SDK generators can produce package metadata, model files, API class folders, auth middleware, and many naming knobs; this tool is for a quick client layer you can paste into an existing project.

Where do the TypeScript model types come from?

Local schema refs become imported names from types_module, which defaults to ./types. Generate those model types separately, or leave types_module blank to emit placeholder type Name = unknown aliases while prototyping.

Can it call private or remote refs while generating?

No. The block is pure Rust/WASM and never fetches referenced documents. External refs are represented as unknown so the generated client remains deterministic and safe to run locally.

How should I add authentication?

Pass auth headers with RequestOptions.headers, either per call or in the client-class constructor. For retries, refresh tokens, logging, or tracing, pass a wrapped fetch implementation through RequestOptions.fetch.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool openapi-to-fetch-client "openapi: 3.1.0
servers:
  - url: https://api.example.com
paths:
  /pets/{petId}:
    get:
      operationId: getPet
      parameters:
        - name: petId
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: OK"

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/openapi-to-fetch-client/?spec=openapi%3A%203.1.0%0Aservers%3A%0A%20%20-%20url%3A%20https%3A%2F%2Fapi.example.com%0Apaths%3A%0A%20%20%2Fpets%2F%7BpetId%7D%3A%0A%20%20%20%20get%3A%0A%20%20%20%20%20%20operationId%3A%20getPet%0A%20%20%20%20%20%20parameters%3A%0A%20%20%20%20%20%20%20%20-%20name%3A%20petId%0A%20%20%20%20%20%20%20%20%20%20in%3A%20path%0A%20%20%20%20%20%20%20%20%20%20required%3A%20true%0A%20%20%20%20%20%20%20%20%20%20schema%3A%20%7B%20type%3A%20string%20%7D%0A%20%20%20%20%20%20responses%3A%0A%20%20%20%20%20%20%20%20%27200%27%3A%0A%20%20%20%20%20%20%20%20%20%20description%3A%20OK&input_format=auto&style=functions&client_name=ApiClient&naming=operation_id&param_style=object&error_handling=throw&base_url=https%3A%2F%2Fapi.example.com%2Fv1&types_module=.%2Ftypes&tags=pets%2C%20admin&jsdoc=true&indent=2

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.