Build with AI
Most apps get built with an AI coding assistant now. The trouble is that no assistant knows how Egg works: the Gateway, the SDK, and the way a web app reaches a local service are all newer than any model’s training data. Paste a starter prompt and the assistant has the contract it needs to scaffold a working app on the first try.
Why a starter prompt
Point Cursor, Claude Code, Copilot, or any assistant at “build me an app on Egg” with no context and it will invent a plausible, wrong client: a made-up endpoint, an API key that doesn’t exist, a fetch to a cloud server that isn’t there. The platform is local-first and the surface is specific, so the model has to be told.
The prompts below carry that surface. Each one states the discovery rule, the SDK or HTTP shape, the auth model, and the constraints, then asks for a concrete small app. Copy one, paste it into your assistant as the first message, and describe what you want. The assistant fills in the app; the prompt keeps it on the rails.
Prompt: a web app on Egg
Use this when you want a real app that runs in the browser, talks to the local Gateway, and can be listed in the gallery. It produces a portable Egglet built on @egg/sdk; the SDK handles discovery, the localhost permission, authorization, and the not-installed case for you.
Build a web app that runs on Egg, a browser with a local AI gateway on the
user's machine (macOS and Windows). The app is a portable "Egglet": a web bundle
that talks to the local Egg Gateway through the official SDK. Follow this
contract exactly. Do not invent endpoints, API keys, or a backend.
SDK, imported from "@egg/sdk":
- Entry: export default defineEgglet({ async activate(ctx) { ... } }).
- The runtime discovers the local Gateway, runs the user authorization
handshake, and gives you a scoped `ctx`. You never handle tokens or URLs.
- AI follows the browser Prompt API shape:
const s = await ctx.ai.text.chat.create({ initialPrompts: [{ role: "system", content: "..." }] });
const reply = await s.prompt("..."); // or s.promptStreaming("...") for chunks
- Data is SQL over your own tables, named with {{double_braces}}:
await ctx.database.exec("INSERT INTO {{notes}} (id, body, created_at) VALUES (?1, ?2, ?3)", [id, body, Date.now()]);
const rows = await ctx.database.all("SELECT * FROM {{notes}} ORDER BY created_at DESC");
- Outbound HTTP goes through ctx.fetch, never the global fetch.
- Mount the UI with ctx.routes.mount(() => import("./Page")).
manifest.json declares identity and what you use; the host enforces it:
{
"id": "notes", "label": "Notes", "icon": "notebook", "route": "/notes",
"runtime": "portable", "delivery": "iframe",
"tables": [{ "name": "notes", "columns": [
{ "name": "id", "type": "TEXT", "primary_key": true },
{ "name": "body", "type": "TEXT" },
{ "name": "created_at", "type": "INTEGER" } ] }],
"uses": { "llm": true, "gateway": { "writes": true } }
}
When Egg is not installed the SDK throws EggNotAvailable. Use the bundled helper
so the app degrades gracefully instead of crashing:
import { runWithInstallPrompt } from "@egg/sdk";
import module from "./index";
await runWithInstallPrompt(module, { appName: "Notes" });
Build this: a single-page Notes app. A text box adds a note, stored with
ctx.database. A "Summarize" button sends the notes to ctx.ai.text and shows the
summary. Handle the not-installed case with runWithInstallPrompt. No backend, no
API keys, no database other than ctx.database.
Reference for the assistant (or you): Egglets, the SDK reference, and On the web.
Prompt: a local script or tool
Use this when your code runs on the same machine as Egg, such as a Node or Python script, a CLI, or an agent harness. The Gateway speaks the OpenAI Chat Completions API, so any OpenAI client works; only the base URL and key change, and the user’s configured model does the work with no API key of your own.
Add Egg as the AI provider to a script that runs on the same machine as Egg
(macOS or Windows). Egg's local Gateway speaks the OpenAI Chat Completions API,
so use a standard OpenAI client and only change the base URL and key.
Discovery: read the Gateway's port and bearer token from its info file.
macOS: ~/Library/Application Support/com.eggbrowser.desktop/daemon_info.json
Windows: %APPDATA%\com.eggbrowser.desktop\daemon_info.json
shape: { "port": <number>, "token": "<bearer>" }
Use it like OpenAI:
baseURL = http://127.0.0.1:<port>/v1
apiKey = <token>
POST {baseURL}/chat/completions { "model": "", "messages": [...], "stream"?: true }
The model field is ignored; routing comes from the user's Egg settings. The
token is regenerated every time Egg restarts, so read it fresh at startup and
never hardcode it. Streaming responses are Server-Sent Events ending in
[DONE], exactly like OpenAI.
Build this: <describe your tool here>. Use the official OpenAI SDK for your
language, pointed at the base URL and token above.
Reference: Gateway API and Discovery & auth.
Machine-readable context
A pasted prompt is a one-time hit. If your assistant supports persistent context (Cursor’s docs sources, a project rules file, an agent’s context directory), point it at the machine-readable summary instead, so the Egg surface is loaded on every turn rather than just the first.
https://eggbrowser.com/developers/llms.txt
It is a compact, plain-text digest of the same contract the prompts carry, with links to the full reference. Add it once and your assistant keeps the discovery rule, the SDK shape, and the auth model in view for the whole session.
One caveat for both the prompts and the digest: they are a snapshot of the SDK. When in doubt, the linked reference pages are the source of truth, and the types in @egg/sdk are always current in your editor.