Skip to content

apps/demo

The demo application: the phone page, the big-screen page, a job queue and the agent loop. One of the two pieces of first-party code the design allows (../../docs/demo.md, section 6). This is the reduced demo for the Local option: Act 1 (the group photo) and Act 3 (the rate limit, the blocked egress, the trace of one request). How to run it as a show: ../../docs/runbook.md.

What a job does

  1. The presenter's phone uploads the room photo and starts a job with a theme (chosen by the vote, or directly). Both go through Agentgateway's public listener.
  2. The job takes the sandbox that stands ready (OpenSandbox SDK, gVisor, with the gateway's egress listener as its HTTP proxy) and puts the photo in it. One sandbox serves one job and is then deleted; it is only started ahead of its job.
  3. The job takes the DeepSeek Harness runtime that stands ready, started through the SDK with a generated profile patch (ail_demo/agent.py): the model provider and the one MCP server are Agentgateway, each with the job's traceparent; the harness's own tools (shell, files, web, subagents) are switched off, so the agent has exactly what the gateway's /mcp endpoint offers; session-log upload and telemetry are off. One runtime serves one job. Its trace id is chosen when it starts, and the job that takes the runtime takes that trace id.
  4. The agent, with Qwen3-4B, makes three tool calls through the gateway, one per model turn: normalize in the sandbox (the first place the upload is decoded), edit_image with a prompt it writes from the theme's instruction, finish in the sandbox (the label). edit_image answers at once and the edit runs on while the agent makes its third call; finish waits in the sandbox for the edited picture.
  5. The application shows the picture as soon as finish has written it, while the agent is still writing its closing word; then it deletes the sandbox, closes the runtime and starts the next sandbox and runtime.

The application does not trust the agent's own account. A job is done only if edit_image really produced a picture; otherwise the agent gets one more attempt, and then the job fails. If the agent stops after the edit without the last step, it is reminded once in the same session, so that the step is still its own tool call; the screen shows the reminder. If it still does not, the application runs the step and the screen says so.

How fast a job is

The owner's target (2026-11-29) is under 10 seconds from "Start" to the picture, with the agent really planning and calling tools through the gateway, in a sandbox, traced.

Measured, final configuration, real provider, the agent making all three calls: 8.5 to 9.7 s, median 8.8 s, in 11 jobs out of 11 (2026-11-29, Mac Mini, tracing on, a synthetic group picture, themes in turn, each job started 3 s after the screen said a sandbox and a runtime stood ready). After ten minutes without a job, which is what the show is like: 9.9 s, and 8.9 and 8.7 s for two more jobs a minute and a half apart. It is not a guarantee: on two freshly built clusters later that day, a few minutes after the deploy and with other work on the Mac, seven jobs took 8.2 to 12.3 s and only two were under 10 s (in three of them the image provider took 3.5 to 4.5 s instead of 3). Of the 22 jobs run with the final configuration, 16 were under 10 s and none over 12.3 s. Before these changes the same job took 24 to 39 s.

Where the 8.8 s go (one job, from its trace):

Seconds
Photo into the sandbox that stood ready 0.1
Harness, until its first model call 0.3
Model turn 1: decide to call normalize (about 65 tokens out) 2.0
normalize in the sandbox, through the gateway 0.5
Model turn 2: read the result, write the prompt, call edit_image (about 40 tokens out) 2.5
The image provider, at 0.4 megapixels 2.9 to 3.2
meanwhile: model turn 3, calling finish, which waits for the picture (1.3)
Edited picture into the sandbox, label, picture read out 0.3
after the picture: the agent's closing word (1.2)

What was changed, and what each change was measured to do:

Change Before After
The sandbox is started ahead of its job 5 to 14 s in the job 0.04 to 0.4 s (the photo upload)
The harness runtime is started ahead, and one turn in a throwaway session pays for the harness's slow first turn and puts the system prompt and tool list into the model server's cache 3.0 s before the first model call 0.3 s
The edit runs beside the agent; finish waits for it image time and model turn 3 one after the other they overlap: about 1.3 s less
The picture is shown when finish has written it the agent's last turn (1.2 to 2.5 s) was waited for it is not
llama.cpp guesses runs of tokens from n-grams of the context and checks them in one batch (--spec-type ngram-mod): a tool call mostly repeats what the model has just read 27 to 31 tokens a second; 2.6 s for the first tool call 43 to 51 tokens a second; 1.65 s
Fewer tokens to write: normalize and finish instead of two paths; no job_id parameter (the model filled it with the 34-token sandbox id); short theme instructions; "done" as the last word image call up to 104 tokens about 40
Output of 0.4 megapixels instead of the provider's default of 1 3.6 to 4.8 s 2.7 to 3.3 s
While something stands ready, the path a job takes is walked every 40 s (a command in the waiting sandbox through the gateway, a file into it, a turn of the waiting runtime in a throwaway session) first job after 12 idle minutes: 14.1 s (the model server took 4 s to read 100 tokens); with only the model kept awake: 12.8 s 9.9 s after 10 idle minutes
Qwen3's thinking block off at the server (--reasoning-budget 0) 1 job in 8 failed: the model wrote its tool call inside the empty thinking block none in the 37 jobs since

Tried and dropped:

  • A warm-up turn in the job's own session. It left a turn in the job's context, and the model then called the tools in the wrong order (4 jobs of 4). The warm-up now runs in a session of its own.
  • All three tool calls in one model turn. The model does that when asked less strictly. It is slower, not faster: nothing runs until the whole turn is written (about 210 tokens, 4.7 s), so the edit starts later.
  • Other models of the provider. qwen-image-2.0-pro: 12.8 s. qwen-image-2.1-turbo: 4.5 s at the same size. qwen-image-3.0: 32 s. The provider has no asynchronous variant for this API, and one would not be quicker.
  • Putting the photo into the sandbox while the agent already runs (0.1 to 0.4 s): not done, because a prepared sandbox that turns out dead must be replaced before the agent is told its id.
  • A smaller local model (Qwen3-1.7B, about twice as fast): downloaded, not tried; the under-10 figure was reached without it and tool-calling quality was the risk.
  • Not tried: llama.cpp flash-attention and KV-cache settings, a second slot.

What it depends on, plainly:

  • Chance. A job that starts in the second or two in which the waiting runtime is taking its keep-awake turn waits for it: seen once, 11.1 s. And a model check from outside (hack/preshow.sh, make verify) pushes the agent's prompt out of the model server's cache until the next keep-awake turn, up to 40 s later: a job started in between took 10 to 11 s.
  • Something must stand ready. A job started while nothing does (right after another job, or after a restart) waits for it or creates its own, and takes about 8 s longer (measured: 19.9 s for a job started 1.5 s after the one before). The clock on the screen includes that wait. The pre-show check and the screen's state say whether something stands ready; after a job it takes 5 to 15 s. AIL_WARM=off switches starting ahead off.
  • A quiet Mac. These figures were taken while other work ran on the same Mac (load average 3 to 5). Under heavier load the same job took 11 to 16 s, and with the node stalling far longer.
  • The provider. 2.7 to 3.3 s in the final runs; 7 to 8 s was seen twice in about 80 calls that day. Three requests at once drew one HTTP 429 (Throttling.RateQuota).
  • The agent. Since the thinking block was switched off, 37 jobs of 37 were finished by the agent with three calls in order. Once, after a long idle, it passed on the description of the prompt parameter instead of a prompt; the tool now refuses that and tells it what to send.

What the real agent costs

Owner decision, 2026-11-29: the real agent stays. The model plans and makes the tool calls itself, through the gateway, in a sandbox, traced; under 10 s is the aim, not a reason to script the job. No hybrid and no scripted variant is in the code.

So that the cost of the choice is visible: both variants were built and measured while this was being decided, and then removed. With the application running the two sandbox steps and the agent only writing the prompt and making the image call, four jobs took 6.8, 7.4, 8.8 and 11.8 s: about 2 s less than the real agent. With no agent and no model at all, three jobs took 4.1 to 4.3 s (a fourth 10.9 s, when the provider took 8 s): about 4.5 s less. Those 2 to 4.5 s are what the two model turns before the edit cost.

Each further second with the real agent, and what it would cost: the two model turns before the edit are 4.5 s. A model twice as fast (Qwen3-1.7B) could take about 1.5 s off, at the risk of worse tool calls; it was not tried. The image provider's 3 s has no cheaper setting that was found; 0.26 megapixels is the documented minimum and was not tried.

On the big screen

With Azure the room waits about 18 s (17.5 to 21 s), and the screen shows that wait as it is.

A clock runs from "Start" and turns green at the picture ("25.4 s to the picture"); it follows the application's own count, so a page opened in the middle of a job is right. Each step appears as it starts, with its time; the sandbox line says that the sandbox stood ready and what starting it had cost. The photo appears when the agent calls the image tool (about 5.5 s in), so the room sees itself while the edit runs. From then a line counts how long the image model has been working ("12.6 s so far"), and under the photo it says that nothing is shown until it is done. The agent's repeated calls of the last step are one line: "finish (the image model was still working; asked again at 15.9 s, 24.9 s)".

The trace view (key 4) works during a job: the application sends each of its spans when it ends, the gateway's arrive as its calls end, and the image model's is drawn as "still running" until it is there. It is asked for every second while a job runs.

None of this makes the wait shorter. What the presenter can do with it is in ../../docs/runbook.md, "The eight minutes".

Act 3

  • Rate limit. /api/tap counts and does nothing else; the gateway limits the route. The screen shows the gateway's own counters, read through Prometheus (passed, and rejected with 429), beside what reached the application and what the phones counted.
  • Blocked egress. A drill the presenter starts: the application creates a sandbox, puts a generated test card in it and, with the operator key, runs two upload attempts through the gateway's tool endpoint, as a tricked agent would: through the proxy to an outside host name, which the gateway must refuse, and around the proxy straight to the application's own receiving end (/api/drop), which the NetworkPolicy must stop. The screen shows the command, the answers as the tool result carries them, the gateway's counter of refused egress requests before and after, and how many requests arrived at that receiving end, which must be none.
  • Trace. The application sends its own spans of a job (the job, its stages, the image backend) to Jaeger under the job's trace id, which is also the parent the harness sends with every model and tool call. The screen draws the hops that matter out of the trace: 13 rows of 41 spans in a run. With tracing off it shows the application's stage timings and says that they are not a trace.

Prometheus and Jaeger are read with a fixed list of queries (ail_demo/telemetry.py); there is no free-form query endpoint.

The image step

One interface, edit(image, prompt) -> image (ail_demo/imaging/), selected by AIL_IMAGE_BACKEND. Since 2026-11-29 the provider is Azure, a gpt-image-2.5-flare deployment on an Azure account. With Azure's three settings present and nothing else configured, azure runs; without them, dashscope if its key is present; without any, the stub. When Azure refuses a picture or fails and a Bailian key is present, Bailian edits that picture instead, and the screen says so. Whatever runs, the big screen shows the photo and the result side by side and says what the result is.

Azure costs the show its speed: a job takes 17.5 to 21 s with it, against 8 to 12 s with Bailian. See "Azure" below before choosing.

Backend What the result is What it is Evidence
stub (no key) Not an image model A local recolouring with the banner "STUB: no image model was called". No network, no key Runs
azure (with its settings) An edit of the photo Azure, a GPT-image deployment (gpt-image-2.5-flare) Read against the official how-to and reference, held by unit tests, run against the provider on 2026-11-29 (drawn and synthetic people only)
dashscope (with a key) An edit of the photo Alibaba Model Studio, Qwen-Image-Edit. Default model qwen-image-2.0 Read twice against the official API reference, held by unit tests; run against the provider on 2026-11-29 (13 pictures, none with people)
ark An edit of the photo Volcengine Ark, Doubao Seedream 4.0. Default model doubao-seedream-4-0-250828 Read against the official API reference, held by a unit test. The model id comes from third-party copies of that page. Never called
zhipu A re-imagining, not an edit Zhipu's vision model describes the photo; glm-image draws a new picture from the description Request shapes read against the official documentation on 2026-11-29 and held by unit tests; run in the cluster against a stand-in server only. Never called
gateway An edit of the photo OpenAI-shaped /v1/images/edits through Agentgateway (the image-edit route), which holds the key Written from the API shape; not re-checked; never called
bfl An edit of the photo Black Forest Labs, FLUX.2 Same

Azure: the provider

One Azure AI resource holds one image deployment (model gpt-image-2.5-flare, version 2026-09-08, GlobalStandard, capacity 3, which is three requests a minute). The application needs its endpoint, the deployment's name and the resource's key (AZURE_IMAGE_ENDPOINT, AZURE_IMAGE_DEPLOYMENT, AZURE_IMAGE_KEY).

What the official pages say (read 2026-11-29) and what the calls showed:

The documentation says The adapter, and what was seen
Variants gpt-image-2.5-flare and gpt-image-2.5-sunburst are listed side by side, both with image edits; nothing says how they differ Both were deployed and tried once on the same picture: 23.2 s and 27.4 s, pictures alike, same price. flare was kept, sunburst deleted
Endpoint POST {endpoint}/openai/v1/images/edits (the how-to also gives the older /openai/deployments/{name}/images/edits?api-version=...) The v1 path. Works on the resource's cognitiveservices.azure.com address
Authentication An api-key header, or a bearer token from Entra ID (recommended) The api-key header, with the key in the application's Secret
Request Multipart form data, not JSON: image, prompt, model (the deployment's name), n, size, quality, output_format, optional mask, input_fidelity, output_compression Exactly those first seven
The photo PNG or JPEG, under 50 MB, up to 16 of them The normalised JPEG, at most 1536 px a side
Size 1024x1024, 1536x1024, 1024x1536; for gpt-image-2: any size with both sides multiples of 16, 655,360 to 8,294,400 pixels, ratio up to 3:1 The photo's shape at the smallest allowed total: 1008x672 for a 3:2 photo. Accepted
Quality low, medium, high; "lower quality images can be generated faster"; default high low (AIL_AZURE_IMAGE_QUALITY)
Keeping faces input_fidelity=high: "faces are preserved more accurately" Refused by this model: "The model 'gpt-image-2.5-flare' does not support the 'input_fidelity' parameter". Not sent. Faces are kept well without it
Output Always base64 in the answer; PNG by default, JPEG possible JPEG. No second request, so no download to fail
Moderation A safety system on input and output A refusal is HTTP 400 with code moderation_blocked and the stage. Seen four times; see below
Background background (transparent, opaque, auto) Not sent; the answer reports opaque

Latency, measured. From this Mac, one call at a time, low quality: 15.3 to 27.4 s in eight direct calls, 16.2 to 18.1 s in the five stage jobs. Output size and input size made no difference worth having (1536x1024: 23.2 s; 1008x672: 20.6 s; input scaled to 768 or 512 px: 20.3 and 19.4 s). low is already the fastest quality. The endpoint is in the eastern United States; an unauthenticated request alone takes 1.4 s from here, against 0.06 s for Bailian. So a stage job takes 25.0 to 28.1 s (four jobs with a sandbox and runtime standing ready; make verify's job 26 s), against 8.2 to 12.3 s with Bailian. The 10-second aim cannot be met with this model from this Mac.

Where the seconds go, and what else was tried (2026-11-29, later; 30 requests). A stage job took 20 to 26 s, median 21 s then, with one request (17.5 to 21 s since, with three at once on an idle Mac: "Three requests at once" below) (seven jobs and the two checks; five in a row: 21.3, 20.4, 19.8, 22.5, 26.1 s), from the trace and the provider's own phases, which the job's trace now carries as two spans under "image backend: azure":

Part Seconds Avoidable?
Before the edit starts: the agent's first turn, normalize in the sandbox, the agent's second turn writing the prompt 4.8 to 8.7 Only by not letting the agent plan: it is the price of the real loop (decided)
Azure, from the request to the first byte of the answer: its own work 11.9 to 14.8 No. Input size (720 to 1536 px, 160 to 470 kB), output size and JPEG compression made no difference; low is the lowest quality; 1008x672 is the smallest output the model takes
Connection set-up to the endpoint (TCP and TLS) 0.8 to 1.4 Yes, done: the connection is opened when the job starts and kept
Upload of the photo 0.0 to 0.8 No (0.3 s for a phone photo at 1008 px)
Download of the picture (250 to 340 kB) 1.1 to 1.6 on a new connection, 0.2 to 0.5 on the kept one Yes, done, with the same change
After the picture is there: label in the sandbox, fetch, show 0.3 to 0.9, once 4 s on a loaded Mac Hardly
The agent asking finish again (the 10 s cut on tool calls) 0 to 1.5: only when the picture arrives between two calls Not worth a longer wait in the sandbox, which would sit against the cut

The earlier 25 to 28 s were the same job with Azure answering in 16 to 18 s; on this afternoon it answered in 13 to 15 s. That part is Azure's and moves with the hour: plan for about 20 s and do not be surprised by 30. The resource is in the eastern United States and a resource's region cannot be changed; a deployment elsewhere would need a new resource in that region, which was not created. Nor would it help: the model is not offered in East Asia, Southeast Asia, Japan East, Korea Central, Australia East or South India (asked of Azure for each on 2026-11-29); of the regions asked, it is in East US 2, West US 3, Sweden Central, Poland Central and UAE North, always as "Global Standard", where the work is done wherever Azure has capacity. Only the second of network time above would be in play.

(A passage is left out of the public edition of this page.)

Three requests at once (owner, 2026-11-29: several requests at once are fine). One edit sends AIL_AZURE_RACE identical requests (default 3; 1 sends one) to the same deployment at the same moment. The first that comes back as a picture is used and the others are cancelled. A request that is refused or dropped does not matter while another is still under way; only when all have failed does Bailian step in, as before. Every request is billed, a cancelled one very probably too: it was cancelled after Azure had worked on it for the whole time.

What it is for is the live show, not the clock. Azure refused 4 of 19 test pictures, some without a visible cause, and dropped 2 connections in 13: with one request each of those is a fallback to Bailian or a failed job, with three it is a line on the screen. In time it gives about a second: of three at once the first answered after 14.6, 13.5 and 15.7 s while the middle one took 16.7, 16.4 and 15.9 s (direct calls); in stage jobs the first answer came after 12.4 to 14.1 s.

Nothing is hidden: while the edit runs the screen says "3 identical requests at once, the first picture is used"; afterwards a line says what became of each ("request 2 answered first and is used (13.3 s); request 1 cancelled, another had answered; ..."), and the trace has one span for each request under "image backend: azure", named with its outcome, the used one with its two phases. The job's state carries the same as race. Connections for all the requests are opened when the job starts.

The deployment's capacity is its requests a minute: it was raised from 3 to 9, which is three jobs a minute at three requests each.

Measured with it (2026-11-29, the Mac otherwise idle): make verify's job 19 and 20 s, hack/preshow.sh --job 19 and 21 s, eight stage jobs in 17.5 to 20.0 s, median 18.4 s. Before the edit starts the agent took 4.2 to 5.3 s this time (4.8 to 8.7 s on the loaded Mac earlier): the Mac being idle is worth more seconds than the race. Against a stand-in for Azure (no model, no bill): one request refused, one dropped and one answering gave the picture with the line above; all three failing went to the second provider (also a stand-in) with "all 3 requests failed (1 refused, 2 dropped)" on the screen.

The last step in the background. Found on the way: about one time in six (2 of 5, then 1 of 9 jobs) the small model ran finish with background: true. Such a step returns at once and waits for nobody, the agent says "done", and the application then waited 10 s before labelling the picture itself: jobs of 27 to 29 s. Now the image tool's answer says "finish and background false (it waits for the picture)" (0 of 19 jobs since), a step run in the background is shown as such on the screen, and when the agent has ended without the picture the application steps in after 1.5 s, not 10.

How the job copes with 20 s. A tool call through the gateway is cut after 10 s. So the last sandbox step waits at most 7 s, answers that the image model is still working, and the agent calls it again: three finish calls in a typical job, each the agent's own. In one job of six the agent did not call it again; the application then ran the step and the screen said so.

How well people survive. Better than with Bailian. Test picture: eight different synthetic adults in a meeting room (made by the same Azure model from a text; nobody real). In every edit looked at (Moon five times, flying twice, ink twice) all eight people were there, each plainly themselves: face, hair, glasses, beard, build, clothes. On the Moon every one of them held a helmet. Flying lifted everyone clear of the floor. Bailian on the same picture and prompt: all eight there and recognisable, softer faces, two helmets among eight. Drawn figures: eight of eight unchanged, each with a helmet. Real faces remain the owner's rehearsal. This picture, scaled down, is now the test card of make verify and hack/preshow.sh --job (ail_demo/static/testcard.jpg).

Refusals. Four of the 19 edits asked of Azure were refused by its safety system, with no reason given beyond the stage: twice a synthetic group in which some figures looked like children (output stage; the adults-only picture was never refused), once a plain gradient with a prompt about "everyone" (input stage), and once the drawn test card with the flying theme (output stage), which the same card and theme had passed minutes before. So a refusal can come without a visible cause. Twice in 21 requests the connection also dropped with no answer; the adapter tries once more. When Azure refuses or fails, Bailian edits the picture if its key is present (AIL_IMAGE_FALLBACK=off stops that): seen working twice, the jobs taking 15 and 27 s. Bailian never refused anything in about 110 calls.

Price (official Retail Prices API, eastus2, 2026-11-29; both variants the same): text input 5 USD, image input 8 USD, image output 30 USD per million tokens. One job as configured used 1536 image tokens and about 120 text tokens in, 118 image tokens out: about 0.016 USD a picture, some 0.12 yuan. Bailian's price page: qwen-image-2.0 0.2 yuan a picture at any size, qwen-image-2.0-pro 0.5 yuan, qwen-image-2.1-turbo 0.1 yuan with ten free pictures (it took 4.5 s in one call and was not looked at for how it keeps people).

Azure for the show (owner decision, 2026-11-29, made with the figures below in front of him): the show itself runs on Azure, at about 26 s a job then (17.5 to 21 s since the connection is kept open and three requests are sent at once), and the aim of a job under 10 seconds is knowingly given up for it. The automatic fallback to Bailian when Azure refuses or fails stays on. What the choice costs either way:

Azure gpt-image-2.5-flare Bailian qwen-image-2.0
A stage job 25 to 28 s then; 17.5 to 21 s since 8 to 12 s
People 8 of 8, faces crisp, everyone with a helmet 8 of 8 on this picture, faces softer, two helmets; on the earlier test picture it dropped people in one run of five
Refusals 4 of 19, some without a visible cause none in about 110
Price about 0.12 yuan a picture 0.2 yuan a picture

If the owner changes his mind, Bailian for the whole show is one line: AIL_IMAGE_BACKEND=dashscope in .env.local and make deploy.

Streaming partial pictures: tried, not built. The how-to documents stream and partial_images (1 to 3) for generation requests, names the gpt-image-1 series and gpt-image-2 for it, and says edits take the generation parameters too; the edit reference lists neither parameter; neither page gives a price for a partial picture. One real request settled it (2026-11-29, an edit with stream=true, partial_images=2, low quality): the deployment accepts it and answers as an event stream, but only one partial picture came, 18.6 s into a request that ended at 19.4 s, at full size, and the request used 185 output tokens instead of 118 (about 0.002 USD more). A picture 0.8 s before the final one gives the room nothing to watch, so the adapter does not stream. Not tried: whether medium or high quality sends partial pictures earlier; both are slower in total.

Not tried: medium and high quality in an edit (the setting reaches the request: checked against a stand-in); Entra ID instead of the key; the gateway holding the key.

Alibaba Model Studio (Bailian): the second provider

The dashscope backend sends the photo, after the sandbox normalised it, and the prompt the agent wrote to Qwen-Image-Edit, and gets the edited photo back: the same room and the same people, changed as the theme asks. On screen its result is labelled "AI-edited".

What the official API reference says, read on 2026-11-29 (twice; the second time fact by fact from the page itself), and what the adapter does with it. Evidence status: every row verified by reading the official page; the rows on endpoint, key, sync, request, how the photo is passed, output and what comes back also confirmed by real calls on 2026-11-29 (below). Watermark and prompt rewriting were only ever sent as off; the limits and the price were not tested.

The reference says The adapter
Model qwen-image-2.0 (the faster one) and qwen-image-2.0-pro, plus dated snapshots of each qwen-image-2.0; AIL_IMAGE_MODEL selects another
Endpoint, mainland-China account Beijing region. Recommended: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/...; "the existing address can still be used" The existing address, https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation, because it needs no workspace id. AIL_IMAGE_BASE_URL selects the other
Key Authorization: Bearer. Beijing and Singapore have separate keys that do not work across regions IMAGE_API_KEY, from the application's Secret
Sync or async One synchronous POST. The page lists no asynchronous variant and says the SDK has none One request, then one download
Request model; input.messages with exactly one message of role user, whose content holds 1 to 3 {"image": ...} and exactly one {"text": ...} Exactly that, with one image
How the photo is passed A public URL, a temporary oss:// URL, or data:image/jpeg;base64,... The data: string. Nothing is uploaded anywhere else
Limits on the photo JPG, PNG, BMP, TIFF, WEBP, GIF; at most 10 MB; 384 to 3072 px a side recommended A JPEG of at most 1536 px on the long side: a few hundred kilobytes
Output A PNG, about 1024x1024 pixels in total by default, in the input's aspect ratio; size can set 512x512 to 2048x2048 in total The default; the sandbox then labels it and writes a JPEG
What comes back output.choices[0].message.content[].image: a URL, valid 24 hours. A failure can come as {"code", "message"} Downloads the URL at once; reports code and message
Watermark watermark, off by default Sent as off
Prompt rewriting prompt_extend, on by default Sent as off, so that the prompt is the one the agent wrote. Worth trying both once a key exists
Price "Billed per picture produced"; failed calls are not billed One picture a job

What the calls showed (2026-11-29, 13 pictures, test pictures without people; the owner's key, used with his permission):

  • The existing address accepts the key, and the request and the answer are as read: HTTP 200, output.choices[0].message.content[0].image, a signed URL of a PNG on dashscope-0484.oss-accelerate.aliyuncs.com, usage with image_count: 1 and the output's width and height. No workspace address was needed.
  • Latency: the provider answered in 3.6 to 4.8 s in all 13 calls; the download took 0.1 to 0.2 s (a PNG of 1.3 to 1.4 MB).
  • Output size: 1248x832 for a 3:2 photo, 1184x896 for 4:3, 1024x1024 for a square.
  • Faithfulness depends on the prompt. A style prompt (ink-wash) keeps the picture: the layout, every object's place and colour, and the text on the screen in the drawn room, letter for letter; the road photo stayed the same road. A prompt about "everyone" on a picture with no people makes the model invent people: on the drawn room it added a dozen figures and kept the room ("fly"), or kept the wall and replaced the floor and chairs with the moon ("astronauts on the moon"); on the road and the abstract picture it replaced the whole scene. What it does with real people in a real room is still not known: these pictures had none, on purpose.
  • Refusals, content policy: none seen in 13 calls with harmless pictures and prompts. Nothing was done to provoke one.
  • Price: not shown in the answer, and the console was not looked at. The page says "billed per picture produced".
  • One failure, not the provider's: in one job the name of the result's host did not resolve in the cluster, twice within 20 s, after the provider had answered both times, so two paid pictures were lost and the job failed. The name resolved from the same pod minutes later and the cause was not established. The download is now tried four times over 7 s before a paid picture is given up, and the error names the host.
  • Signed URLs of results were being written to the application's log by the HTTP library; that is off now.
  • Not tried: prompt_extend on, qwen-image-2.0-pro, the per-workspace address, a larger size.

The people stay themselves

One rule for every theme (owner, 2026-11-29): the people stay themselves, the world around them changes. Closed spacesuits, in which nobody can be told apart, are out.

How it is done. A theme has a short instruction, which the agent is given and writes its prompt from, and a detail, which the application adds to the agent's prompt together with one sentence that is the same for every theme (ail_demo/config.py, imaging.KEEP_PEOPLE):

Keep every person from the photo: the same number of people, each with their own face, hairstyle, skin tone, glasses, beard, body shape and clothing colours, every face fully visible. Do not add or remove anyone.

The screen shows the agent's prompt and, marked as added by the application, the rest. What must not change does not hang on how a 4B model words a sentence. A negative prompt goes with it (covered face, helmet on head, changed face, extra or missing people).

What the provider's documentation offers for this, read on 2026-11-29 (guide, API reference): no identity switch or parameter. Its own examples keep a person by saying so in the prompt ("the person perfectly keeps the facial features of the woman in the input picture", "do not change the buildings, vehicles or people in the photo"); negative_prompt exists for the qwen-image-2.0 series (500 characters); prompt_extend is recommended off for detailed prompts and where latency matters, which is how it is sent; the pro model is described as stronger in text, realism and following the prompt, with no claim about faces.

What was measured, with drawn and synthetic figures only: no photo of a real person was used. Two test pictures: eight plainly different drawn figures in a drawn room, and a photo-like picture of eight different synthetic people that the provider made from that drawing. 16 calls outside the cluster, then the jobs of the timing runs.

Theme, final wording Drawn figures Synthetic people
On the Moon: "change only what is around them", own clothes, a helmet under the arm 8 of 8 unchanged, each with a helmet 8 of 8 recognisable (face, hair, clothes) in 4 of the 5 runs looked at, two or three of them holding a helmet; in the fifth, 6 of 8, one of them altered
Flying not run 8 of 8 recognisable; the room unchanged; some float above the table, some barely leave the floor
Ink painting not run 7 of 8 in each of 2 runs: one person at the edge is left out

What did worse, on the same synthetic picture:

  • The old Moon prompt ("turn everyone into astronauts on the moon"): on the drawing, eight closed suits with the faces barely visible, the owner's objection; on the synthetic picture it changed almost nothing.
  • Asking for spacesuits with the helmets off: six tries, three kinds of result. Once nobody was in a suit; once half of them were; four times everyone was, but then only 4 to 6 of the 8 people came out, with weaker likeness, twice with the helmets back on (clear visors) and once with one person headless. The more of a person the prompt asks to change, the less of the person is kept. That is why the theme leaves the clothes alone and adds the helmet as something held. The owner accepted the theme in this form (2026-11-29).
  • "Remove the furniture": the two people standing behind the table's corners went with it.
  • qwen-image-2.0-pro, same prompt: every person unchanged, nobody in a suit, and 12.8 s instead of 3.8 s. It keeps people best and is too slow for the show.
  • Drawn figures lose their features whenever they are redrawn in another style (hair colour and length went in the spacesuit versions); the synthetic people held up better.

Real faces remain the owner's rehearsal. Nothing here says how well a real room of real people comes through: these were eight figures, evenly lit, each large in the frame. A room photo has more people, smaller, some half hidden, and the model left people out once the scene changed much. Expect it to keep the front rows better than the back.

Zhipu: looked at, built, and set aside

The owner chose Zhipu (bigmodel.cn) on 2026-11-29 and replaced it the same day with Alibaba Model Studio (and that, later the same day, with Azure), because of what follows. The backend stays, selectable with AIL_IMAGE_BACKEND=zhipu, and is not the default.

Zhipu cannot edit a photo. Read in its documentation on 2026-11-29 (image generation API, GLM-Image): the image models take text only ("input modality: text, at most 1000 characters"), and the request has model, prompt, quality, size, watermark_enabled and user_id; no field takes an input image. So the zhipu backend does something else, in two calls, both to Zhipu (ail_demo/imaging/zhipu.py):

  1. Describe. A vision model (glm-4.6v-flash by default, which the documentation calls free; AIL_ZHIPU_VISION_MODEL selects another) gets the photo, after the sandbox normalised it, and is asked for one paragraph of at most 250 Chinese characters: about how many people and how they are arranged, the room, the colours and light, notable objects. It is told not to identify anyone or describe an individual's looks.
  2. Draw. glm-image gets the theme the agent wrote, then that description, and draws a new picture in the recommended size closest to the photo's shape.

What this means, and where it is said. The result is a new picture of a room like the one in the photo, with the theme applied. The people in it are invented by the image model and do not look like the people in the photo. It is not an edit and must not be called one:

  • the big screen shows a banner saying so, the photo and the result side by side, and the vision model's description in full;
  • the label the sandbox puts on the picture reads "AI-generated from a description of the photo", not "AI-edited";
  • the phone page, the job's trace ("vision model: describe the photo", "image model: draw from the description"), make deploy, make verify and hack/preshow.sh each name it a re-imagining.

What ran, and against what. Not Zhipu. On 2026-11-29 the pipeline ran in the cluster against a stand-in server on the Mac that answers the two paths with a fixed sentence and a blank picture (it is not in the repository): eight stage jobs, all done, 22 to 37 s each with the stand-in's 1.5 s and 3 s delays; the stand-in received the photo as base64 with the bearer header, and an image request with only model, prompt and size; the screen, the label, the trace and the checks all named the result a re-imagining. That shows the wiring. It shows nothing about Zhipu.

Not known without a key: whether the request shapes work as read; latency (the documentation says about 20 s for a glm-image picture, to which the vision call adds); what the pictures look like; whether the free vision model is fast and available enough for a show; how the service treats a photo of people.

The 1000-character prompt limit. It does constrain the description, and how much depends on something the documentation does not say: whether a Chinese character counts as one character or as its three UTF-8 bytes. The image prompt is the theme (41 to 48 characters), a fixed sentence of 38, and the description. Counted in characters, about 915 are left for the description; counted in bytes, about 280 Chinese characters. The backend stays within 1000 by both counts: the vision model is asked for at most 250 characters, which fits whole either way, and anything longer is cut at the end, which the screen says. 250 characters is a few sentences: enough for the number and arrangement of people, the room, colours and a few objects, not for much more.

The probe: does the image endpoint take a photo after all? One request, to be run once when a key exists (billed as one picture if it is accepted):

IMAGE_API_KEY=... python -m ail_demo.imaging --probe-image-input test-card.jpg probe-out.jpg

It sends the documented request plus two undocumented fields carrying the picture, and an instruction that only makes sense if the picture is seen ("keep this photo unchanged, make it black and white, add a large red dot"). If the service refuses the request, the answer is no. If a picture comes back, look at it: the test card in black and white with a red dot means the endpoint edits, and real editing should then replace the two-step pipeline; any other picture means the photo was ignored. Use a picture without people.

The key. The image API needs a standard API key. A GLM Coding Plan key is a separate kind, not interchangeable since 2026-10-16, and the plan's quota is for the listed coding tools only (key management, usage notes). glm-image is listed at 0.1 yuan a picture.

Volcengine Ark: the other one that edits

ark (Doubao Seedream 4.0) also edits the photo itself. It stays selectable (AIL_IMAGE_BACKEND=ark) and is not the default. What reading its API reference settled, once, and what only a call can:

ark
Endpoint POST https://ark.cn-beijing.volces.com/api/v3/images/generations
Key Authorization: Bearer
The photo The same kind of string, in image
Limits on the photo 30 MB. Ours fits
What comes back Base64 in the answer (response_format: b64_json)
Output shape 2048x2048 by default, so the adapter sends the photo's own shape as size, scaled up to the documented minimum of 921,600 pixels
Watermark On by default; sent as off
Prompt rewriting Not sent
Not known without a call Whether the model id is right and enabled for the account; latency; what it does with a photo of people

Switching it on

Lines in .env.local at the repository root and one command:

AZURE_IMAGE_ENDPOINT=https://<resource>.cognitiveservices.azure.com
AZURE_IMAGE_DEPLOYMENT=<deployment>
AZURE_IMAGE_KEY=...             # never committed, never printed
IMAGE_API_KEY=...               # optional: a Model Studio key of the Beijing region, the second provider
make deploy PROFILE=local       # puts them into the application's Secret
make verify PROFILE=local       # its stage job goes through the provider: billed (Azure: three requests)

Other choices, each one line more: AIL_IMAGE_BACKEND=dashscope (Bailian, the fast one), stub (no image model, for work on everything else with the keys left in place), ark, zhipu; AIL_IMAGE_FALLBACK=off (Azure alone). The Bailian key is read from IMAGE_API_KEY only; a DASHSCOPE_API_KEY in the shell is not picked up.

The keys are git-ignored and must stay out of git. Two guards: make deploy stops if a tracked file contains either key, and the self-check that CI runs fails on anything in a tracked file that has the shape of a Model Studio key or of an Azure AI services key.

To try a backend once without the cluster (one billed call; without credentials it runs the stub):

python -m ail_demo.imaging in.jpg out.jpg "make everyone fly"

The key's place

A deliberate, temporary deviation (owner decision, 2026-11-29; ../../docs/design.md, section 10). The design has the gateway hold the provider's key, so that neither the application nor the sandbox sees it and the image call is a gateway span. With azure, zhipu, dashscope, ark and bfl the key is in the application's Secret (demo-app, key image-api-key) and the application calls the provider directly. The sandbox still never sees it. What is lost meanwhile: the image call does not pass the gateway, so it has no gateway span (the application sends its own span, "image backend"), no gateway metric and no gateway policy.

What moving it back would take, none of it tried:

  1. (Only if the Zhipu backend were used: its vision call is an OpenAI-shaped chat completion and could be an AgentgatewayModel like the qwen3-4b route. Not done.)
  2. A route on the gateway's internal listener to the provider as an external HTTPS backend, with a policy that adds the Authorization header from a Secret in inference. For Ark the path is OpenAI-shaped (/images/generations); whether Agentgateway v1.7.0 treats it as model traffic, as it does /v1/images/edits, or needs a plain HTTP route is not known. DashScope's API is its own JSON shape and needs the plain HTTP route.
  3. The adapter then calls the gateway's address instead of the provider's and sends no key: AIL_IMAGE_BASE_URL already allows the address; dropping the header is a one-line change per adapter.
  4. Remove image-api-key from the application's Secret, and check that the call shows up as a gateway span in the job's trace.

Who may do what

  • Presenter controls (room photo, vote, start, views, purge) and the big-screen page need the presenter token, generated at deploy time (Secret demo-app). It is given once in the URL (?token=) and then kept in an HttpOnly cookie.
  • Audience phones can vote and tap. Uploading is off unless AIL_AUDIENCE_UPLOADS=on.
  • Uploads are capped at 8 MB and must be JPEG, PNG or WebP; the page scales a photo to 1536 px and re-encodes it before upload, which also drops EXIF data.
  • The queue runs max_concurrent_jobs jobs at once, from the demo-limits ConfigMap: 1 in the Local option.

Layout

ail_demo/config.py      settings from the environment; the three themes
ail_demo/state.py       jobs, the vote, the WebSocket hub (in memory)
ail_demo/worker.py      the queue and the stages of a job; the edit_image tool
ail_demo/agent.py       the harness: profile patch, system prompt, one runtime per job
ail_demo/sandboxes.py   one sandbox per job (OpenSandbox SDK)
ail_demo/gateway.py     the application's own MCP call through the gateway (operator key)
ail_demo/imaging/       the backend interface, the stub, the editing adapters (Bailian is the default), Zhipu's re-imagining
ail_demo/telemetry.py   fixed queries to Prometheus and Jaeger; the application's own spans
ail_demo/web.py         pages and API on 8080
ail_demo/main.py        entry point; the MCP tool on 8081
ail_demo/static/        phone.html, screen.html
sandbox/                normalize.py, finish.py (labels the picture with what it is) and upload.py (the drill)
tests/                  no cluster, no model, no network

The image built from here is also the OpenSandbox MCP server (upstream ships it as a package without an image) and the sandbox image.

Tests

pip install -r requirements-test.txt && python -m pytest tests

Observed

On the Mac Mini, 2026-11-28, Local option with tracing on, stub backend, a test picture without people: 13 jobs by hand, all done at the first attempt, 14 to 22 s each after the first (31 s); sandbox 3 to 5 s, agent 10 to 18 s. The agent often stops after the edit and skips the last step (labelling): four times in the first seven jobs, none in the next six after the tool result was made more explicit, then three of six again. Since 2026-11-29 the agent is reminded once in the same session when that happens: in ten jobs it was needed once, and the agent then ran the step; all ten were finished by the agent. One job is one trace in Jaeger (36 spans). The application's pod used about 480 Mi. With a stand-in in Alibaba Model Studio's place (2026-11-29): the default selection, the documented request, the PNG through the last step and the edit view on the screen, in two jobs (../../docs/runbook.md, "What was run"). With the real provider (2026-11-29, tracing on, pictures without people): ten stage jobs, nine done at the first attempt in 24 to 39 s (sandbox 5 to 14 s, agent 17 to 24 s, of which the image model 3.8 to 4.8 s), one failed on the download described under "What the calls showed", before the fix; at least one needed the reminder; one job is one trace (43 spans) with the application's "image backend: dashscope" span in it. Since the changes for speed (2026-11-29; "How fast a job is"): about 70 more jobs with the real provider; with the final configuration 11 in a row in 8.5 to 9.7 s. With Azure (2026-11-29, later): eight stage jobs, six edited by Azure and two by Bailian after Azure refused the test card; 25 to 28 s when a sandbox and runtime stood ready; details under "Azure". Later still: seven stage jobs and the two checks' jobs in 20 to 26 s, all edited by Azure, and one more picture through the image models directly, not through a stage job. Not observed: a photo of real people on the stage path, real phones on a network, more than one job waiting, anything over a longer time.