10.1 Remove // @ts-nocheck and enable strict TS.
10.2 Validate request JSON with Zod; reject negative or NaN token counts.
10.3 Add OPTIONS handler with CORS headers restricting to your first-party origin.
10.4 Catch DB errors and respond 400/429 to stop infinite Stripe retries.
10.5 Store usage metrics in a dedicated usage table with CHECK (tokens_in >= 0).
10.1 Remove // @ts-nocheck and enable strict TS.
10.2 Validate request JSON with Zod; reject negative or NaN token counts.
10.3 Add OPTIONS handler with CORS headers restricting to your first-party origin.
10.4 Catch DB errors and respond 400/429 to stop infinite Stripe retries.
10.5 Store usage metrics in a dedicated usage table with CHECK (tokens_in >= 0).