TakumiTakumi

Response

Web Response subclass and factory for serving images from API routes.

takumi-js/response wraps render() in a Response-compatible object: stream the image directly back to the client, set headers once, drop into any handler that returns a Response. The class is a drop-in for next/og's ImageResponse.

Classes

ImageResponse

A Response subclass that begins rendering on construction and resolves through the ready promise.

import {  } from "takumi-js/response";

export function () {
  return new (
    < ="flex h-full w-full items-center justify-center bg-white text-6xl">Hello</>,
    { : 1200, : 630 },
  );
}

Functions

createImageResponse

Returns a factory pre-bound to shared options — fonts, stylesheets, cache headers — so individual routes only supply per-request overrides.

import {  } from "takumi-js/response";

const  = ({
  : 1200,
  : 630,
  : { "Cache-Control": "public, max-age=31536000, immutable" },
});

export function () {
  return (< ="flex h-full w-full bg-black text-white">OG</>);
}

Options

Prop

Type

Description

width?number

The width of the image. If not provided, the width will be automatically calculated based on the content.

height?number

The height of the image. If not provided, the height will be automatically calculated based on the content.

format?union

The format of the image.

quality?number

The quality of JPEG format (0-100).

drawDebugBorder?union

Whether to draw debug borders.

fetchedResources?union

The fetched resources to use. The resources fetched externally. You should collect the fetch tasks first using extractResourceUrls and then pass the resources here.

stylesheets?array

CSS stylesheets to apply before rendering.

keyframes?union

Structured keyframes to register alongside stylesheets.

devicePixelRatio?number

The device pixel ratio. Defines the ratio resolution of the image to the physical pixels.

timeMs?number

The animation timeline time in milliseconds.

dithering?union

The output dithering algorithm.

signal?object

jsx?object

resourcesOptions?FetchResourcesOptions

emoji?union

headers?union

status?number

statusText?string

onError?function

Result

Prop

Type

Description

headersobject

The headers read-only property of the Response interface contains the Headers object associated with the response.

MDN Reference

okunion

The ok read-only property of the Response interface contains a Boolean stating whether the response was successful (status in the range 200-299) or not.

MDN Reference

redirectedunion

The redirected read-only property of the Response interface indicates whether or not the response is the result of a request you made which was redirected.

MDN Reference

statusnumber

The status read-only property of the Response interface contains the HTTP status codes of the response.

MDN Reference

statusTextstring

The statusText read-only property of the Response interface contains the status message corresponding to the HTTP status code in Response.status.

MDN Reference

typeResponseType

The type read-only property of the Response interface contains the type of the response. The type determines whether scripts are able to access the response body and headers.

MDN Reference

urlstring

The url read-only property of the Response interface contains the URL of the response. The value of the url property will be the final URL obtained after any redirects.

MDN Reference

clonefunction

The clone() method of the Response interface creates a clone of a response object, identical in every way, but stored in a different variable.

MDN Reference

bodyunion

bodyUsedunion

arrayBufferfunction

blobfunction

bytesfunction

formDatafunction

jsonfunction

textfunction

readyobject

Factory

Prop

Type

Description

ImageResponseOptions extends RenderOptions and ResponseInit, plus onError for catching render failures without crashing the stream. The default Content-Type is derived from format (pngimage/png, etc.).

Edit on GitHub

Last updated on

On this page