Messages and Multimodal Input
Pass transcripts, text, images, and documents into direct completions.
Use messages when your application already owns the transcript. If you also pass input, Anvia appends it as the final message.
Transcript Messages
import { Message, createCompletion } from "@anvia/core";
const result = await createCompletion(model, {
messages: [
Message.system("You classify support tickets."),
Message.user("My invoice is wrong."),
Message.assistant("billing"),
],
input: "I cannot log in.",
});Message.user("...") and Message.assistant("...") create Anvia's normalized content arrays for you.
Multimodal User Messages
User messages can contain multiple content parts, including text, images, and documents:
import { Message, UserContent, createCompletion } from "@anvia/core";
const result = await createCompletion(model, {
messages: [
Message.system("Inspect the user-provided materials."),
Message.user([
UserContent.text("Summarize what is shown here."),
UserContent.imageUrl("https://example.com/screenshot.png", {
detail: "auto",
}),
UserContent.documentUrl(
"https://example.com/spec.pdf",
"application/pdf",
{ filename: "spec.pdf" },
),
]),
],
});Provider support still matters. If the selected model does not support image or document input, Anvia rejects before calling the provider.
Raw Normalized Shape
Raw objects are also valid when they match Anvia's normalized message shape:
const message = {
role: "user",
content: [
{ type: "text", text: "Summarize what is shown here." },
{
type: "image",
source: { type: "url", url: "https://example.com/screenshot.png" },
},
],
};This is different from plain OpenAI-style user messages with string content:
// Not the normalized Anvia user message shape.
const message = { role: "user", content: "Summarize this." };Use the factory helpers unless you need to construct content arrays manually.
Static Documents
Use documents for text context that should be attached to the request rather than stored in the transcript:
const result = await createCompletion(model, {
input: "Answer using the attached policy.",
documents: [
{
id: "refund-policy",
text: "Refunds are available within 30 days for annual plans.",
},
],
});documents are text context. File-like document inputs belong in UserContent.documentUrl(...) or UserContent.documentBase64(...).
