import { error, json, type RequestEvent } from '@sveltejs/kit'; import { env } from '$env/dynamic/private' /** @type {import('./$types').RequestHandler} */ export async function POST({ request }: RequestEvent) { const body = await request?.json().catch(() => {}); if (!body?.model) { throw error(400, 'missing model value') } if (!body?.inputs || body.inputs === null) { throw error(400, 'missing inputs value') } const response = await fetch(env.SECRET_INFERENCE_API_URL + "/models/" + body.model, { method: "POST", headers: { Authorization: `Bearer ${env.SECRET_HF_TOKEN}`, 'Content-Type': 'application/json', ['x-use-cache']: "0" }, body: JSON.stringify(body), }) .then((res) => res.json()) .then((res) => res) .catch((error) => { return { error: error.message, } }) if ("error" in response) { error(400, response.error as string) } return json(response) }