Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.stellartools.dev/llms.txt

Use this file to discover all available pages before exploring further.

The @stellartools/uploadthing-adapter meters file uploads by total byte size. It runs a preflight credit check, charges after a successful upload, and refunds if the upload fails.

Install

npm install @stellartools/uploadthing-adapter uploadthing

Usage

import { createMeteredUploadthing } from "@stellartools/uploadthing-adapter";
import { createUploadthing } from "uploadthing/server";

const ut = createUploadthing();
const f = createMeteredUploadthing({
  api_key: process.env.STELLAR_TOOLS_API_KEY!,
  product_id: "prod_uploads",
});

export const uploadRouter = f({
  image: ut.imageUploader().maxSize("4MB"),
}).middleware(async (opts) => {
  return { userId: opts.req.headers.get("x-user-id") ?? "" };
});
Each request must include an x-customer-id header with the StellarTools customer ID to charge.

Config options

api_key
string
required
Your StellarTools API key.
product_id
string
required
Credit product ID to charge for uploads.

Required headers

x-customer-id
string
required
The StellarTools customer ID to charge for the upload.
If the customer does not have enough credits, the adapter throws and the upload is rejected before any files are stored.