AI Functions
Two generated Edge Functions for AI: chat and embeddings. Both run through a Supabase Edge Function — the provider key stays server-side.
ai-chat
The most powerful function. Calls OpenAI (Responses API or Chat Completions), DeepSeek, or any OpenAI-compatible provider. Supports text, structured JSON output, multi-turn messages, tool-calling, and SSE streaming. Configure via AI_MODEL and AI_PROVIDER env vars.
import { functions } from "@/integrations/supabase";
// Simple text
const reply = await functions.invoke("ai-chat", {
input: "Summarize the quarterly report",
instructions: "Be concise.",
});
// Structured output — result is nested under data
const { data } = await functions.invoke("ai-chat", {
input: emailText,
mode: "json",
schema: { name: { type: "string" }, email: { type: "string" } },
});
// data.name, data.email
// Or use the ai helper (simpler — handles nesting for you)
import { ai } from "@/integrations/ai";
const { name, email } = await ai.json(emailText, {
name: { type: "string" },
email: { type: "string" },
});ai-embeddings
Turn text into vectors for semantic search, RAG, or similarity matching. Accepts a single string or an array. Configure via AI_EMBEDDING_MODEL env var.
const vectors = await functions.invoke("ai-embeddings", {
input: ["How to build a Chrome extension", "Best pasta recipes"],
});
// { ok: true, model: "...", embeddings: [{ embedding: [0.1, ...], index: 0 }] }