Skip to content
D
Documentation

Options

reference
2 min readUpdated

Import it from ky.

Options are the same as window.fetch, except for the KyOptions

ts
interface Options extends KyOptions, RequestOptions

Properties

NameTypeDefaultDescription
method?LiteralUnion<HttpMethod, string> | undefinedHTTP method used to make the request.
headers?KyHeadersInit | undefinedHTTP headers used to make the request.
signal?AbortSignal | null | undefinedAn AbortSignal to abort the request.
json?unknownShortcut for sending JSON. Use this instead of the body option.
parseJson?((text: string, context: {request: Request; response: Response}) => unknown) | undefinedJSON.parse()User-defined JSON-parsing function.
stringifyJson?((data: unknown) => string) | undefinedJSON.stringify()User-defined JSON-stringifying function.
searchParams?SearchParamsOptionSearch parameters to include in the request URL. Setting this will merge with any existing search parameters in the input URL.
baseUrl?URL | string | undefinedA base URL to resolve the input against. When the input (after applying the prefix option) is only a relative URL, such as 'users', '/users', or '//my-site.com', it will be resolved against the baseUrl to determine the destination of the request.
prefix?URL | string | undefinedA prefix to prepend to the input before making the request (and before it is resolved against the baseUrl). It can be any valid path or URL, either relative or absolute. A trailing slash / is optional and will be added automatically, if needed, when it is joined with input. Only takes effect when input is a string.
retry?RetryOptions | number | undefinedControls retry behavior. Each field is documented in the RetryOptions type.
timeout?number | false | undefined10000Per-attempt timeout in milliseconds for getting a response, applied independently to each retry. Ky shortcut methods also use this value as a separate timeout for reading the response body. Cannot be greater than 2147483647. See also totalTimeout.
totalTimeout?number | false | undefinedfalseOverall timeout in milliseconds for the entire operation, including retries and delays. Throws a TimeoutError if exceeded. Cannot be greater than 2147483647.
maxResponseSize? (not released yet)number | undefinedInfinityMaximum response body size in bytes. Must be a non-negative safe integer or Infinity. Set to 0 to allow only empty bodies.
hooks?Hooks | undefinedHooks allow modifications during the request lifecycle. Hook functions may be async and are run serially, unless otherwise noted.
throwHttpErrors?boolean | ((status: number) => boolean) | undefinedtrueThrow an HTTPError when, after following redirects, the response has a non-2xx status code. To also throw for redirects instead of following them, set the redirect option to 'manual'.
onDownloadProgress?((progress: Progress, chunk: Uint8Array) => void) | undefinedDownload progress event handler.
onUploadProgress?((progress: Progress, chunk: Uint8Array) => void) | undefinedUpload progress event handler.
fetch?((input: Request, init?: RequestInit) => Promise<Response>) | undefinedfetchUser-defined fetch function. Has to be fully compatible with the Fetch API standard.
context?Record<string, unknown> | undefined{}User-defined data passed to hooks.

Was this page helpful?

Options — ky · GPT-6.1 Sol