
stitch-sdk-usage
Use the Stitch SDK to generate, edit, and iterate on UI screens from text prompts, manage projects, and retrieve screen HTML/images. Use when the user wants to consume the SDK in their application.
- Installs
- 570
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/google-labs-code/stitch-sdk --skill stitch-sdk-usage- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads stitch-sdk-usage automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Using the Stitch SDK
The Stitch SDK provides a TypeScript interface for Google Stitch, an AI-powered UI generation service.
Installation
npm install @google/stitch-sdk
Environment Variables
export STITCH_API_KEY="your-api-key"
Quick Start
import { stitch } from "@google/stitch-sdk";
const project = await stitch.createProject({ title: "My App" });
const generation = await project.generate("A settings page with dark theme");
const screen = generation.first; // all screens: generation.screens
const html = await screen.getHtml(); // the HTML content
const png = await screen.getImage(); // screenshot bytes (Uint8Array)
The stitch singleton reads STITCH_API_KEY from the environment and connects on first use — no setup code required.
Working with Projects
import { stitch } from "@google/stitch-sdk";
// List all projects
const projects = await stitch.projects();
// Reference a project by ID (no network call)
const project = stitch.project("4044680601076201931");
// Create a new project
const newProject = await stitch.createProject({ title: "My App" });
Design Systems
// Create a design system for a project
const ds = await project.createDesignSystem({ displayName: "My Theme" });
// List design systems
const systems = await project.listDesignSystems();
// Reference by ID (no network call)
const dsRef = project.designSystem("existing-asset-id");
// Update a design system
const updated = await ds.update({ displayName: "Updated Theme" });
// Apply to screens (requires SelectedScreenInstance objects from project.data.screenInstances)
// Returns a Generation — all updated screens are in .screens
const applied = await ds.apply([
{ id: "instance-id", sourceScreen: "projects/123/screens/456" },
]);
applied.screens;
Uploading Images
Upload an existing image file (PNG, JPG, JPEG, WEBP) to create a screen directly from a mockup or asset.
import { stitch } from "@google/stitch-sdk";
const project = stitch.project("your-project-id");
// Upload a local image file
const [screen] = await project.upload("./mockup.png", {
title: "Home Screen",
});
console.log(screen.id);
const html = await screen.getHtml(); // HTML content
const png = await screen.getImage(); // screenshot bytes (Uint8Array)
The method reads the file from disk and posts it directly to the Stitch REST API — no output token constraints apply (unlike agent-driven MCP calls).
Supported formats: .png, .jpg, .jpeg, .webp
Options:
| Option | Type | Default | Description |
|---|---|---|---|
title | string | — | Display title for the created screen |
createScreenInstances | boolean | true | Whether to add the screen to the canvas |
Throws StitchError with codes: NOT_FOUND (file not found), UNKNOWN_ERROR (unsupported format or upload failure), AUTH_FAILED (invalid API key).
Generating and Iterating on Screens
// Generate screens from a prompt. Stitch can return MANY screens per
// generation — a Generation carries all of them plus the raw response.
const generation = await project.generate(
"Login page with email and password fields",
);
generation.screens; // every generated Screen
generation.first; // convenience: the first screen
generation.raw; // full typed tool response
// Optional settings go in a trailing options object
const mobile = await project.generate("A settings page", {
deviceType: "MOBILE",
});
// Edit an existing screen (also returns a Generation)
const edited = await generation.first.edit(
"Make the background dark and add a subtitle",
);
// Generate variants of a screen
const variants = await generation.first.variants(
"Try different color schemes",
{
variantCount: 2,
creativeRange: "EXPLORE",
aspects: ["COLOR_SCHEME", "LAYOUT"],
},
);
variants.screens; // all variant Screens
Retrieving Screen Assets
// CONTENT (fetched for you)
const html = await screen.getHtml(); // HTML string
const png = await screen.getImage(); // Uint8Array
// Or just the signed download URLs
const htmlUrl = await screen.getHtmlUrl();
const imageUrl = await screen.getImageUrl();
URL accessors use cached data from the generation response when available and write fetched responses back to the cache. A missing artifact throws StitchError with code NOT_FOUND (never a silent empty string).
Dynamic Tool Client (for agents)
For agents and orchestration scripts that forward JSON payloads to MCP tools:
import { stitch } from "@google/stitch-sdk";
// Find available tools
const { tools } = await stitch.listTools();
for (const tool of tools) {
console.log(`${tool.name}: ${tool.description}`);
}
// Call a tool with a JSON payload
const result = await stitch.callTool("generate_screen_from_text", {
projectId: "123",
prompt: "A login page",
});
await stitch.close();
Error Handling
All SDK methods throw StitchError on failure. Use try/catch:
import { stitch, StitchError } from "@google/stitch-sdk";
try {
const project = stitch.project("bad-id");
await project.screens();
} catch (e) {
if (e instanceof StitchError) {
console.log(e.code); // "AUTH_FAILED", "NOT_FOUND", etc.
console.log(e.message); // Human-readable description
console.log(e.recoverable); // Whether retrying might succeed
}
}
Error codes: AUTH_FAILED, NOT_FOUND, PERMISSION_DENIED, RATE_LIMITED, NETWORK_ERROR, VALIDATION_ERROR, CLARIFICATION_REQUIRED, UNKNOWN_ERROR
CLARIFICATION_REQUIRED is recoverable: generate()/edit()/variants() got a question instead of screens. Read e.clarification.question / e.clarification.suggestions and call the same method again with an answering prompt.
API Reference
Stitch Class
| Method | Returns | Description |
|---|---|---|
createProject(options?) | Promise<Project> | Create a new project (options.title) |
projects() | Promise<Project[]> | List all projects |
project(id) | Project | Reference a project by ID (no network call) |
Project Class
| Method | Returns | Description |
|---|---|---|
generate(prompt, options?) | Promise<Generation<Screen>> | Generate screens — .screens, .first, .raw (options.deviceType, options.modelId) |
screens() | Promise<Screen[]> | List all screens in the project |
getScreen(screenId) | Promise<Screen> | Retrieve a specific screen by ID |
upload(filePath, opts?) | Promise<Screen[]> | Upload an image/HTML file and create screen(s) from it |
createDesignSystem(designSystem) | Promise<DesignSystem> | Create a design system for this project |
listDesignSystems() | Promise<DesignSystem[]> | List all design systems |
designSystem(id) | DesignSystem | Reference by ID (no API call) |
deviceType: "MOBILE" | "DESKTOP" | "TABLET" | "AGNOSTIC"
upload supported formats: .png .jpg .jpeg .webp .html
DesignSystem Class
| Method | Returns | Description |
|---|---|---|
update(designSystem) | Promise<DesignSystem> | Update the design system's theme |
apply(selectedScreenInstances) | Promise<Generation<Screen>> | Apply this design system to screens (.screens) |
Screen Class
| Method | Returns | Description |
|---|---|---|
getHtml() | Promise<string> | Fetch the screen's HTML content |
getImage() | Promise<Uint8Array> | Fetch the screenshot bytes |
getHtmlUrl() / getImageUrl() | Promise<string> | Signed download URLs (cache-aware) |
edit(prompt, options?) | Promise<Generation<Screen>> | Edit the screen using a text prompt |
variants(prompt, variantOptions, options?) | Promise<Generation<Screen>> | Generate variants of the screen |
modelId: "GEMINI_3_8_FLASH" | "GEMINI_3_5_FLASH_LITE" (optional, defaults to backend default)
StitchToolClient (for agents)
| Method | Returns | Description |
|---|---|---|
callTool(name, args) | Promise<T> | Call any MCP tool by name |
listTools() | Promise<Tools> | Discover available tools |
connect() | Promise<void> | Establish MCP connection (auto-called by callTool) |
close() | Promise<void> | Close the connection |
Explicit Configuration
import { Stitch, StitchToolClient } from "@google/stitch-sdk";
const client = new StitchToolClient({
apiKey: "your-api-key",
baseUrl: "https://stitch.googleapis.com/mcp",
timeout: 300_000,
});
const sdk = new Stitch(client);
const projects = await sdk.projects();
| Option | Env Variable | Description |
|---|---|---|
apiKey | STITCH_API_KEY | API key for authentication |
accessToken | STITCH_ACCESS_TOKEN | OAuth access token |
projectId | GOOGLE_CLOUD_PROJECT | GCP project ID (required with OAuth) |
baseUrl | — | MCP server URL (default: https://stitch.googleapis.com/mcp) |
timeout | — | Request timeout in ms (default: 300000) |
FAQ
What does the stitch-sdk-usage skill do?
Use the Stitch SDK to generate, edit, and iterate on UI screens from text prompts, manage projects, and retrieve screen HTML/images. Use when the user wants to consume the SDK in their application.
How do I install stitch-sdk-usage?
Run npx skills add https://github.com/google-labs-code/stitch-sdk --skill stitch-sdk-usage in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/stitch-sdk-usage/ (personal) or .claude/skills/stitch-sdk-usage/ (project).
Which AI agents can use stitch-sdk-usage?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is stitch-sdk-usage safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains stitch-sdk-usage?
It is published by google-labs-code in google-labs-code/stitch-sdk, and it is an official skill from the maker of the technology it covers. It has 570 recorded installs.
More from google-labs-code/stitch-sdk
stitch-sdk-readme
google-labs-code/stitch-sdk
Open the skill to read its SKILL.md instructions.
stitch-sdk-development
google-labs-code/stitch-sdk
Develop the Stitch SDK. Covers the generation pipeline, dual modality (agent vs SDK), error handling, and Traffic Light (Red-Green-Yellow) implementation workflow. Use when adding features, fixing bugs, or understanding the architecture.
stitch-sdk-domain-design
google-labs-code/stitch-sdk
Design the domain model for the Stitch SDK. Use when mapping MCP tools to domain classes and bindings in domain-map.json. This is Stage 2 of the generation pipeline.
tdd-red-green-refactor
google-labs-code/stitch-sdk
Open the skill to read its SKILL.md instructions.
stitch-sdk-pipeline
google-labs-code/stitch-sdk
Open the skill to read its SKILL.md instructions.
stitch-sdk-bug-bash
google-labs-code/stitch-sdk
Find bugs in the Stitch SDK using a real API key. Covers standard functional edges and tricky situations.
Popular frontend & design skills
setup-matt-pocock-skills
mattpocock/skills
Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
hyperframes-animation
heygen-com/hyperframes
All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.
prototype
mattpocock/skills
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
hyperframes-core
heygen-com/hyperframes
The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.
vercel-react-best-practices
vercel-labs/agent-skills
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.