AI
Add AI features without shipping a provider key in the extension. Start with a focused helper, then drop to the request API when the product needs more control.
Import
import { ai } from "@/integrations/ai";ai.text — text responses
Return plain text for summaries, rewriting, classification, translation, or generated copy.
const summary = await ai.text(pageContent, {
instructions: "Summarize in 3 bullets."
});ai.json — structured output
Describe the fields you expect and receive structured data instead of parsing model prose yourself.
const fields = await ai.json("Extract name and email from this email", {
name: { type: "string" },
email: { type: "string" },
});ai.stream — streaming tokens
Render output as it arrives for chat, long generations, or any interface where immediate feedback matters.
await ai.stream("Write a poem about shipping code", (chunk) => appendToUI(chunk));ai.embed — vector embeddings
Turn text into vectors for semantic search, retrieval, clustering, or similarity matching.
const vectors = await ai.embed(["doc a", "doc b"]);ai.request — advanced
Use the lower-level API for multi-turn messages, tools, multimodal input, or a per-request model override.
const result = await ai.request({
messages: [{ role: "user", content: "..." }],
tools: [...],
model: "gpt-4o", // optional — overrides the configured default
});Next
See the generated AI Edge Functions that power these helpers. Set the AI_API_KEY in environment variables. Combine with Stripe for paid AI features.
