import { z } from "zod" import { fetchJsonSafeWith } from "../request" import type { RequestError } from "../request" import type { Result } from "../result" const CAPTION_API_URL = "https://picsum-caption-worker.meatbagoverclocked.workers.dev/" const captionResponseSchema = z.object({ description: z.string(), }) export type CaptionResponse = z.infer export type GetCaptionParams = { imageUrl: string maxWords: number } export async function getCaption({ imageUrl, maxWords, }: GetCaptionParams): Promise> { return fetchJsonSafeWith(CAPTION_API_URL, (json) => captionResponseSchema.parse(json), { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ imageUrl, maxWords, }), }) }