Direct Completions
Call a provider model directly without agent turns or tool execution.
Direct completions are for one model request when you do not need an agent runtime. Use them for small transformations, classifiers, summaries, or infrastructure code that already owns the prompt shape and does not need Anvia to execute tools.
If you need reusable agent configuration, automatic context loading, tool execution, memory, hooks, tracing, turn limits, or approval handling around the model, use agent.prompt(...).send() instead.
Create a Final Completion
import { createCompletion } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
const model = new OpenAIClient({ apiKey }).completionModel("gpt-5.5");
const result = await createCompletion(model, {
input: "Summarize this ticket in one sentence: password reset link expired.",
instructions: "Write for an internal support handoff.",
maxTokens: 120,
});
console.log(result.text);createCompletion always waits for the final provider response.
It returns:
| Field | Meaning |
|---|---|
text | Joined assistant text content |
content | Normalized assistant content parts |
usage | Normalized token usage |
response | Full normalized CompletionResponse, including the raw provider response |
When to Use Agents Instead
Direct completions do not run tools or own a multi-turn workflow. Use an agent when the run needs:
- reusable instructions and context setup
- dynamic context or retrieval
- tool execution
- memory or sessions
- hooks, approvals, or tracing
- turn limits and tool loops
Next
Read Messages and Multimodal Input to pass transcripts, images, and documents, or Structured Output to return schema-validated data.
