F
Flowman docsWorkflow SDK
Back to app
Workflow step actions

aiInvoke (AI SDK)

Source: src/workflows/shared/actions/ai.ts. Wraps generateText from the Vercel ai package with the @ai-sdk/openai provider. Journals an AI step in Convex.

Project environment variables

Set OPENAI_API_KEY under your project's Environment variables screen (/p/<slug>/environment). It is read from record.env at run start via createOpenAI(); the deployment's own .env is reserved for Flowman system use.

Arguments

  • record FlowmanRunRecord (use record.input for prompts and record.env for credentials loaded at run start)
  • stepKey, optional name
  • model — defaults to gpt-4o-mini
  • system, maxOutputTokens
  • Either prompt or non-empty messages — mutually exclusive inside one call

Prompt mode

typescript
import { aiInvoke } from "@/workflows/shared/actions";

const { text } = await aiInvoke({
  record,
  stepKey: "summarize",
  name: "Summarize thread",
  system: "Be concise.",
  prompt: "Summarize the excerpt in 3 bullets:\n\n" + snippet,
  model: "gpt-4o-mini",
});

Messages mode

typescript
import type { ModelMessage } from "ai";

const messages: ModelMessage[] = [
  { role: "user", content: "Explain this error in one line." },
];

const { text } = await aiInvoke({
  record,
  stepKey: "explain",
  name: "Explain error",
  messages,
  model: "gpt-4o-mini",
});