Skip to content

How to design a prompt playground (frontend)

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Practice this question

The problem

A prompt playground is a form with many controls that feed one request: pick a model, set its parameters, write a prompt, run it and watch the output stream in, then save the setup as a preset a teammate can load. The answer turns on holding the whole setup in one place. Then a run sends a copy taken at the instant run was pressed, a preset loads with a single write, a model switch can check each value against the new limits, and a save can say which version it started from so two teammates don't overwrite each other.

Clarifying questions

AskWhy it mattersA typical answer

Which parameters does a setup hold, and are they the same for each model?

The count sizes the setup object and the preset, and whether limits differ per model decides whether a model switch can leave values out of range.

Say 8: model, temperature, max output tokens, top p, penalties, stop sequences, system prompt and response format. Limits differ per model: one allows up to 16,384 output tokens and others allow fewer, and GET /models returns each model's limits.

Does the output arrive whole or as a stream, and how long does a run take?

A stream turns a run from a request into a long-lived piece of state with its own stop button, and the duration says how long editing and running overlap.

A stream of events. The first output should show within 2 seconds and a run keeps streaming for about 20, so people will edit while one is running.

Who can see a preset, and can two people change the same one?

Private presets can live anywhere. Shared ones need a server, an owner and a rule for two saves that land on the same preset.

Shared with teammates, and two people can open the same preset. Live co-editing isn't required.

Does the browser call the model provider directly?

If it did, the page would need provider credentials or a delegated sign-in of its own, and streaming, cancel and run records would have to be rebuilt per provider.

No. The browser talks to our server, which holds the keys and runs the models. How the server runs them is not part of this round.

How many columns can a compare hold, and does each have its own model?

It sizes the number of streams open at once and how much state each column carries.

No maximum is given. Assume a few columns, each with its own model and parameters, all started from one press of run.

Do past runs need to be kept, and with what?

Comparing later and repeating a run need the setup that produced each output, not just the text.

Yes. A run keeps the setup it used, its output, how many tokens it used and how long the first output took.

The requirements menu

RequirementScopeWhy

Pick a model and set its parameters

Core

The setup is the heart of the page: 8 values that feed each run, with limits that change per model.

Write a system prompt and messages, run them and watch the output stream in

Core

A run streams for about 20 seconds, so the page keeps running and editing side by side.

Save the setup as a preset, then load, update and share it

Core

Presets are how a setup leaves one browser and reaches a teammate, and updating one brings versions.

Stop a run while it is still streaming

Core

Stopping a long run is a run-state transition and a cancel call, which shapes the run controller.

Compare runs of different setups side by side

Core

Several setups and several streams at once test whether the setup and run state were split per column.

Keep a history of past runs that can be reopened

Optional

Take it if there's time: it's what makes comparing later possible, and it raises the question of keeping full outputs or just metadata. Leave it if the core flow isn't finished.

Show each run's token usage and how long its first output took

Optional

Cheap once the stream carries a usage event, and it's how two columns get compared on cost and speed as well as on text.

Fill variables such as {{name}} into the prompt at run time

Optional

Take it for a team that reuses one prompt over many inputs. It adds a variables panel and a substitution step before the run; leave it for a first pass.

Add a model's reply to the conversation as the next turn

Optional

Take it if multi-turn testing matters: it's one button that appends the output as an assistant message. It makes the messages list grow, which matters for preset size and merging.

Define tools in JSON and show tool calls in the output

Out of scope

A large sub-feature with its own editor and output rendering. Name it and set it aside.

Two people editing one preset live, with cursors

Out of scope

Needs presence, and edits have to be merged while people type. A version check on save covers teammates who edit at different times; bring this back if the interviewer asks for live editing.

Billing and usage limits

Out of scope

The server owns quotas; the page shows an error when a run is refused.

How the server runs the models

Out of scope

The page sees a stream of events and a cancel endpoint, nothing more.

Managing provider keys

Out of scope

Keys stay on the server, so there's nothing for the page to manage.

Non-functional requirements

RequirementWhat it forces

A change to any control answers within 200 milliseconds

A control edit writes to local state and paints in the same frame, with no server round trip in the handler. Interaction to Next Paint measures this from the click, tap or key press to the next frame, and 200 milliseconds or less is the good threshold. So stream rendering for a run has to be batched, or chunks arriving several times a second compete with the slider for the main thread.

A run can be repeated: the exact setup it used is kept with it

The run takes a deep copy of the setup when run is pressed and stores it in the run record, next to the output and metrics. Edits made during the 20 seconds of streaming change the setup on screen, not the record.

Unsaved changes are kept, and the page warns before leaving when the browser allows it

A dirty marker that compares the setup with the preset it was loaded from, a confirm before loading another preset over unsaved edits, and a beforeunload listener that's registered while the marker is set and removed when it clears. MDN notes that visibilitychange is a more reliable signal for saving state than beforeunload, so in this design the page also writes a local draft of unsaved edits at that point and treats the leave dialog as the fallback rather than the whole answer.

Provider keys never reach the browser

The browser calls our server for models, runs, cancels and presets. The stream is our server's event stream, not the provider's, and the server translates stop into whatever the provider needs.

Core entities

EntityWhat it holds

Setup

Everything one run needs, held in one object that the controls edit.

Preset

A saved setup with a name and an owner, stored server-side for teammates to load.

Run

One execution of one setup, from pressing run to done, failed or canceled.

Model

A model the server offers, with the limits its parameters must respect.

Compare column

One column in a side-by-side view, with a setup and a run of its own.

The API

EndpointNotes

GET /models → [{ id, limits }]

Fetched once when the page opens and cached. The limits drive the limit check on model switch and preset load, so the page needs them before the first run.

POST /runs { setup } → a stream of events: start, text, usage, done or error

The body is the deep copy of the setup. The response is read from response.body with a reader as chunks arrive; start carries the run id, text chunks append to the output, usage carries token counts, and the stream ends with done or error. The request's AbortController is kept for stop.

POST /runs/{id}/cancel → { status }

Sent after abort() closes the stream, so the server stops the model rather than streaming to a closed connection. The run state moves to canceled on the client without waiting for this reply.

GET /presets?cursor, GET /presets/{id} → presets with their version

The list is paged by cursor and cached in the client for the sidebar. Opening one fetches it by id so the setup and version are the latest, then writes the setup into the state in one step.

PUT /presets/{id} { setup, base_version } → preset, or a conflict with the latest version

base_version is the version the person loaded. A match stores a new version and returns it; a mismatch returns the latest version and setup so the client can show a merge, the same shape as If-Match and HTTP 412 Precondition Failed.

The high-level design

editcopyPOST /runseventsControlsSetup stateRun controllerServerOutput columns

Step 1 of 4

Controls, setup, run, output

Start with the four pieces the prompt names: controls for the model and its parameters, a setup object they edit, a run controller that posts the setup and an output panel that draws the events as they stream in. This works for one person running one setup, and it already has gaps: the run reads the live setup, so a keystroke in the prompt box during the 20 seconds of streaming is ambiguous; nothing checks values against the limits of the chosen model; and nothing survives a reload.

limitseditclampcomparebeforeunloadcopycancelPOST /runseventsbatchedrecordloadsetupsavePUTconflictModel pickerLimit checkParametercontrolsSetup stateDirty markerLeave warningRun controllerStop buttonServerFrame batcherOutput columnsRun recordsPreset sidebarPreset cacheMerge view
The whole design

What breaks first

The deep dives

One setup, many controls, one run. Someone switches the model, moves the temperature slider, edits the system prompt and presses run while still typing in the prompt box. Where does each value live, and what does the request carry?

A concept that helps here: Where state livesA concept that helps here: Form validationA concept that helps here: Streaming responses in the UI

Saving, sharing and loading presets. Someone saves a setup as a preset and shares it. A teammate opens it later with a different model chosen. What does the preset hold, and what happens to each value on the way into the controls?

A concept that helps here: Client caching and normalized storesA concept that helps here: Form validationA concept that helps here: Pagination and infinite scroll

Two people editing one preset. Two teammates open the same shared preset. One saves a new system prompt; the other, still on the old copy, changes the temperature and saves. What does each of them see?

A concept that helps here: Conflict resolution on the clientA concept that helps here: Optimistic and pessimistic lockingA concept that helps here: Operational transforms and CRDTs

Comparing runs side by side. Someone sets up three columns with different models and presses run once. What happens on the screen over the next 20 seconds, and what gets slow first?

A concept that helps here: Streaming responses in the UIA concept that helps here: Batching UI updatesA concept that helps here: Partial failure in the UI

Concepts this guide uses

Sources

  1. PostHog docs: LLM analytics playground
  2. PostHog docs: Prompt management
  3. web.dev: Web Vitals
  4. MDN: AbortSignal
  5. Front End Interview Handbook: OpenAI front end interview questions
  6. web.dev: Interaction to Next Paint (INP)
  7. MDN: Window beforeunload event
  8. MDN: If-Match header
  9. MDN: HTTP conditional requests
  10. MDN: AbortController
  11. MDN: Using the Fetch API
  12. MDN: Using readable streams
  13. MDN: Window requestAnimationFrame()
  14. MDN: Window structuredClone()
  15. MDN Glossary: Deep copy
Sign in to report a mistake