Restyle any photo with AI. React frontend + Hono API in a single val, backed by ByteDance PuLID on Replicate.
Live: https://glowcast.val.run — open index.ts
Environment variables do not transfer when a val is created, so this val
does not have the key yet. The health check currently reports
"hasReplicateKey": false.
👉 Add REPLICATE_API_KEY here: https://www.val.town/x/manassehRight/glowcast/environment-variables?key=REPLICATE_API_KEY
PuLID is a paid model and the account has no credit, so every generation
returns 402 Insufficient credit. Add credit at
https://replicate.com/account/billing#billing, then wait a few minutes.
Without a payment method on file, Replicate also throttles prediction creation
to 6/min with a burst of 1, so two people generating simultaneously will make
one of them get a 429. Adding the payment method lifts that too.
Confirm both are sorted without spending credit:
curl https://glowcast.val.run/api/health # {"ok":true,"model":"bytedance/pulid","hasReplicateKey":true}
Rendering mermaid diagram...
index.ts ← Hono: routes + HTML shell
replicate.ts ← server-side PuLID call (testable in isolation)
frontend/
root.tsx ← HTML shell, stamps immutable asset URLs
index.tsx ← React entrypoint
favicon.svg
lib/resize.ts ← browser: downscale + download helpers
components/
App.tsx ← screen layout and state
StylePicker.tsx ← preset styles (label → prompt)
Why the UI and API live in one val: they are same-origin, so the browser
calls /api/restyle with a relative path. No CORS, no absolute URL that can be
misconfigured, no third-party host in the middle. This was the single biggest
source of bugs in the previous Netlify setup.
{ "ok": true, "model": "bytedance/pulid", "hasReplicateKey": true }
{ "imageBase64": "<data URI, raw base64, or https URL>", "prompt": "..." }
Returns { "output": ["https://replicate.delivery/..."], "predictionId": "..." }.
imageBase64 is normalised server-side: a bare base64 string is wrapped in a
data: URI automatically, because Replicate rejects bare base64.
| Status | Meaning |
|---|---|
400 | Missing input, or Replicate rejected the image/prompt |
402 | No Replicate credit |
429 | Replicate rate limit |
502 | Upstream/generation error — detail carries the raw message |
504 | Exceeded the 50s generation deadline |
- Version-based endpoint.
/v1/models/bytedance/pulid/predictionsreturns404 The requested resource could not be found.for this account even thoughGET /v1/models/bytedance/pulidsucceeds.replicate.tsuses/v1/predictionswith a pinned version hash instead. - Images are downscaled in the browser to 1024px before encoding
(
lib/resize.ts). Phone photos base64-encoded can exceed 10MB, and an oversized body is rejected before it reaches the server — which the browser surfaces as a bareTypeError: Failed to fetch. - Downloads fetch into a blob first, because Replicate serves results from a
different origin where the
downloadattribute is ignored.
- "Free generations left today" counter. The old app showed one, but it was
cosmetic. A real per-day limit needs
std/sqliteplus some notion of user identity — worth adding if you want to cap usage. - Shared types between the API and the UI.
replicate.tsexportsRestyleOutcome; wiring it through to the client would catch shape drift.
Template: templates/react-hono-starter.
The earlier Netlify-based backend remains at
manassehRight/glowcast-backend.