AI Recipe Remix Streamer
Full-stack + AI contract design · Rapid prototype and iteration over a few weeks
llmstreamingjson-schemadeveloper-toolsweb Strict JSON Schema contract shared between model and UISection-by-section streaming keeps TTFB low while preserving structured output
Problem / Context
Recipe generators typically trade reliability for novelty: they ignore pantry constraints, wander outside time budgets, and emit loosely structured text that is hard to reuse. I wanted a small app that treats generated recipes as data instead of paragraphs.
Approach
- Defined a versioned JSON Schema for recipes and used the Responses API with
json_schema+strict: trueso the model produces machine-checkable output by default. - Built a two-phase flow: an optional planning call for detailed reasoning, followed by a main generation call that must conform to the shared schema.
- Wrapped the streaming API in a server-side NDJSON pipeline that emits
accepted → heartbeat → delta → section → completedevents, which the client consumes via a plainReadableStream. - Implemented constraint checking (pantry mode, exclusions, time budget, servings) and a refinement pass that asks the model to repair violations instead of silently accepting bad recipes.
- Provided a mock streaming mode when no API key is set, so the UI and stream handling can be developed without calling the model.
Results
- The UI renders Summary → Ingredients → Steps → Nutrition cards incrementally while preserving a single, validated JSON recipe underneath.
- Constraint violations are surfaced explicitly and, when possible, corrected before the final sections reach the user.
- Developers can rely on a stable, schema-governed contract between frontend and model, which makes the system easier to test and evolve.
What I’d Do Next
- Add longitudinal logging of constraint violations to see where the schema and prompts still disagree.
- Experiment with smaller models for preview tiers and fallbacks while keeping the same JSON contract.