feat(api): X-RateLimit-* headers on /api/demo + createdAt/completedAt on job responses (#19) (#28)

This commit is contained in:
2026-03-18 21:41:14 -04:00
parent e088ca4cd8
commit b929e6d72f
2 changed files with 19 additions and 7 deletions

View File

@@ -255,11 +255,12 @@ router.post("/jobs", jobsLimiter, async (req: Request, res: Response) => {
const evalFee = pricingService.calculateEvalFeeSats();
const jobId = randomUUID();
const invoiceId = randomUUID();
const createdAt = new Date();
const lnbitsInvoice = await lnbitsService.createInvoice(evalFee, `Eval fee for job ${jobId}`);
await db.transaction(async (tx) => {
await tx.insert(jobs).values({ id: jobId, request, state: "awaiting_eval_payment", evalAmountSats: evalFee });
await tx.insert(jobs).values({ id: jobId, request, state: "awaiting_eval_payment", evalAmountSats: evalFee, createdAt });
await tx.insert(invoices).values({
id: invoiceId,
jobId,
@@ -276,6 +277,7 @@ router.post("/jobs", jobsLimiter, async (req: Request, res: Response) => {
res.status(201).json({
jobId,
createdAt: createdAt.toISOString(),
evalInvoice: {
paymentRequest: lnbitsInvoice.paymentRequest,
amountSats: evalFee,
@@ -303,7 +305,11 @@ router.get("/jobs/:id", async (req: Request, res: Response) => {
const advanced = await advanceJob(job);
if (advanced) job = advanced;
const base = { jobId: job.id, state: job.state };
const base = {
jobId: job.id,
state: job.state,
createdAt: job.createdAt.toISOString(),
};
switch (job.state) {
case "awaiting_eval_payment": {
@@ -350,6 +356,7 @@ router.get("/jobs/:id", async (req: Request, res: Response) => {
case "complete":
res.json({
...base,
completedAt: job.updatedAt.toISOString(),
result: job.result ?? undefined,
...(job.actualCostUsd != null ? {
costLedger: {