AI Functions

ChromeShip separates generation from embeddings while keeping the provider key and model configuration on the server.

ai-chat

Handles text, structured JSON, multi-turn messages, tools, and streaming across the configured AI provider. Set the default through AI_PROVIDER and AI_MODEL, then override the model only when a request needs it.

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

Converts one string or a batch into vectors for semantic search, retrieval, clustering, or similarity. Configure its model with AI_EMBEDDING_MODEL.

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 }] }

Next

Wire up the AI integration to configure your provider. Deploy Stripe functions for paid AI features. Or see other function templates.