Docs
Rendering
Rendering
The response never contains HTML. Presentation happens afterwards, in one of three channels that share one renderer:
- Web component
<webknox-answer>from@webknox/elements. It runs in your page and works in any framework. - Hosted embed:
render.embed_url, an iframe for webviews and no-code tools. - Image:
render.image_url, an image of the card for chat platforms, email and link previews.
A theme combines a style with layouts:
- The style is design tokens: preset
daylight(default),midnight,editorial,playfulormono, plus overrides such as an accent colour. - The layout is the structure: which fields appear and how they are arranged. Every type has
full; most haveglance; some have more (see the table above). A layout the card type does not have is ignored: the theme's layout for that type, then the theme's default, thenfullapplies.
A theme bundles both, for example {"style": {"preset": "midnight"}, "layouts": {"weather.forecast": "glance", "*": "full"}}. The element's theme property takes such an object. Besides the preset, style takes three safe options: accent (#rrggbb for highlights, buttons and the first chart colour; the ink on accent-coloured buttons is chosen for contrast, and text in the accent colour is shaded, darker on light styles and lighter on dark ones, until it reads at 4.5:1 on the style's surfaces), corners (0, 4, 10, 18 or 26: the card's radius in CSS pixels) and font (sans, serif, mono or rounded, the bundled families), and raw tokens, which win over the options; the element's accent attribute wins over both. Everywhere a theme is named (the element and render.theme) the built-in themes work by name:
| Theme | Style | Layouts |
|---|---|---|
kiosk |
midnight | glance for weather, nutrition, quick answers and sun & moon; full otherwise |
dashboard |
mono | weather and statistics as a table, nutrition as a label; full otherwise |
magazine |
editorial | weather as a headline; full otherwise |
kids |
playful | weather at a glance, nutrition as macros; full otherwise |
status |
daylight | weather and audio as a strip; glance otherwise |
An explicit layout always beats the theme. Every layout shows its sources, at least behind an info button.
v1 offers WebKnox's layouts only; custom layouts are not part of v1. A card type can have options inside its layouts: a theme's cards sets them per type. Today those are the search cards, whose results are drawn as tiles: {"cards": {"recipe.search": {"tile": "macros", "fields": ["time", "calories", "macros"]}}}. tile sets how each result is drawn and fields what a tile shows besides its image and title (the list layout always draws rows, the carousel the default tile):
| Card type | tile |
fields (default in bold) |
|---|---|---|
recipe.search |
photo (default), macros, row, overlay |
time, servings, diets, calories, macros, likes, health |
game.search |
cover (default), detail, row, overlay |
rating, platforms, genre, year, price, modes, developer |
artwork.search |
frame (default: the whole work on a mat, never cropped), label (a museum wall label), overlay, row |
artist, year, type, medium, museum |
book.search |
cover (default: the cover with the title under it), detail (the cover beside its details and a short description), row, overlay |
rating, author, year, pages, genre |
The element ships no fonts. The presets name DM Sans, DM Serif Display, DM Mono and Fredoka with system fallbacks; load them in your page if you want that exact look.
<webknox-answer theme="midnight" layout="glance"></webknox-answer>
<script type="module">
import '@webknox/elements';
document.querySelector('webknox-answer').answer = answer; // JSON from your server
</script>
The element emits webknox-follow-up (detail.text) when a follow-up chip is pressed or a quiz answer is confirmed (the text is the option key, e.g. B), and webknox-action (detail.action) when the user starts something such as a timer. Send a follow-up as the next user message.
A search card's filters, sort and "Show more", a recipe search's recipes, and an entity card's alternatives and related things, emit webknox-refine, with detail.refine (the request's refine), detail.text (the same change as a sentence; null for more recipes of the same search) and detail.done(). To answer it in place, call event.preventDefault(), send the conversation with refine, and set the new answer on the element; the card shows that it is searching until then. If the request fails, or you show the answer somewhere else, call detail.done(). If no handler calls preventDefault(), the element emits webknox-follow-up with detail.text instead (nothing when it is null).
Focus stays inside the card when a control disappears under it: Start cooking moves focus to the step, a video poster to the player, Show punchline to the punchline. After a follow-up, the card that asked is done; move focus to whatever your page shows next, such as the new answer or the question.
Hosted render
On Pro and Scale, a request can ask for hosted URLs of its answer: render: {theme?, layout?, formats}, where theme is a style preset, a built-in theme or the id of one of your saved themes, and formats lists embed, image or both.
- Only a matched answer with a card gets
render; otherwise it is absent and nothing extra is charged. The embed is free; an image adds 1 token, so a matched answer with an image costs 2. - Saved themes are made in the console's Themes section: a preset with the three safe options and a layout per card type (
schemas/theme.schema.jsonin the contract). Their ids look liketh_k2m7x4q6w3np. A render keeps the theme as it was when it was made, so editing or deleting a theme changes no existing embed or image. An id that is not one of your account's themes is a400 invalid_request. To show a saved theme with the element, copy its definition from the console into the element'sthemeproperty. - The answer (never your question) is stored until
render.expires_at, 30 days after the request, and deleted within a day after it. Once it has expired, the URLs answer410 Goneuntil it is deleted and404 Not Foundafter that. - On Free and Starter, a request with
renderis refused with403 plan_requiredbefore it is answered. If the URLs cannot be made, the request fails with503 unavailableand nothing is charged: you get the URLs or a retryable error, never an answer without them. - Embed (
embed_url): the interactive card, for an iframe on any site. A search card's filters, sort and "Show more", a recipe search's recipes, an entity card's related things and other meanings, and a statistic card's other measures and places, work in place: your page needs no key, these searches use none of your tokens, and a recipe opens with a link back to the results. The embed tells the page around it what happens throughpostMessage, as{source: "webknox", id, type, …}:type: "follow-up"withtext(send it as the next user message; a change to a search card arrives this way only if it could not be answered in place),"action"withaction, and"resize"withheightin CSS pixels. Add?follow_ups=0to the URL to hide the follow-up chips when your page doesn't handle them. - Image (
image_url): the card rendered on a 600 px wide page at 2x, so 1200 px wide, with square, opaque corners (chat apps and mail clients frame images themselves). It is a PNG, or a JPEG (.jpg) when the card shows photos, which keeps it small enough for chat apps: typically under 200 KB. It is rendered ahead of time, usually within seconds of the answer; a fetch that comes earlier waits while it renders.
<iframe src="https://embed.webknox.com/v1/…" title="Answer" style="border:0;width:100%"></iframe>
<script>
addEventListener('message', (event) => {
if (event.origin !== 'https://embed.webknox.com' || event.data?.source !== 'webknox') return;
if (event.data.type === 'resize') document.querySelector('iframe').style.height = `${event.data.height}px`;
});
</script>
Media
Answers never point at a third-party image host. Every image URL (image.url, gallery items[].url, video thumbnail_url, audio artwork_url, movie poster_url, game and book cover_url) is a WebKnox media URL:
https://webknox.com/media/v1/upload.wikimedia.org/wikipedia/commons/…/Aurora.jpg
Treat it as opaque. A media URL has no query string; the proxy ignores one if you add it. The original page stays in source_url and the credits, for attribution. WebKnox fetches the image from the host named in the path, caches it for a week and serves it with Access-Control-Allow-Origin: * and Cross-Origin-Resource-Policy: cross-origin, so img-src https://webknox.com is the only image rule your Content Security Policy needs.
Served hosts: wikimedia.org, ytimg.com, image.tmdb.org, img.spoonacular.com, img.gamebrain.co, img.artsearch.io, covers.openlibrary.org
A listed domain includes its subdomains. An image on any other host is left out of the answer: the field is null where the schema allows it, a gallery drops the item, a recipe card shows no photo frame, and a comparison keeps an empty frame so both sides line up. Only JPEG, PNG, WebP, GIF and AVIF up to 8 MB are served; SVG never is. Audio streams (stream_url) and video players stay with their provider and load only after the user presses play, so allow those origins in media-src and frame-src (https://www.youtube-nocookie.com) if you use those cards.
Maps are WebKnox's own images: an entity card's location.map.src is https://webknox.com/geo/v1/<country>.svg (ISO 3166-1 alpha-2) or world.svg, drawn from Natural Earth's public-domain outlines in translucent greys that read on any background, with the points to draw over them in the card data. They come from webknox.com like media URLs, so the same img-src rule covers them, and there are no map tiles.