How Total.js helps developers integrate AI models into real applications with routing, actions, streaming, tools, validation, and business logic in one coherent stack.

Total.js AIModel: a practical foundation for AI-powered workflows
AI is becoming part of normal business software. Not as an isolated chatbot, but as a feature inside real workflows:
- code generation
- translations
- support automation
- summaries
- internal assistants
- monitoring analysis
- content review
- document processing
- knowledge-base assistants
- tool-driven workflows
The important part is not only calling an AI provider. The important part is connecting the provider cleanly with the application.
Total.js AIModel gives developers a simple foundation for building AI-powered workflows directly inside Total.js applications. It provides named AI models, fluent message building, streaming, parsing, thinking output, contextual tools and controlled execution through Total.js actions.
The result is simple: you can build AI features without scattering provider-specific HTTP calls across your codebase.
One AI layer for your application
With AIModel, the provider implementation is registered once with NEWAIMODEL().
Then the application uses the model by name:
This is the main idea: the application does not need to know which HTTP endpoint, token, payload format or streaming format is used. That knowledge stays in the model registration.
This makes AI integration easier to maintain, easier to deploy and easier to change later.
Register once, use everywhere
NEWAIMODEL() can register one or more model names and keep custom configuration in one place.
Then any part of the application can use:
The provider can be local, private, cloud-hosted or OpenAI-compatible. The Total.js application calls a named model and keeps moving.
A fluent API for AI workflows
AIModel provides a practical fluent API for building conversations:
This makes common AI tasks readable:
- generate code
- explain a log entry
- summarize a ticket
- translate text
- classify content
- prepare an answer
- extract useful fields from a customer request
AIModel becomes a normal building block in the application.
Streaming and thinking
Many AI features feel better when the response is streamed. AIModel supports streaming through .stream().
For lower-level streaming integrations, Total.js also provides AIPARSER(). It can parse provider streams and expose useful events such as content, thinking and tool calls.
This is useful when a provider returns streamed chunks, reasoning output or tool-call instructions. Instead of writing a custom parser for every workflow, the parser becomes part of the Total.js AI layer.
Context-aware assistants
The real value of AI appears when it understands the application's own context.
Peter's example shows a simple and powerful pattern: store markdown contexts, parse them, and expose them to the model as readable files. The assistant can then ask for the exact context it needs.
A context file can contain rules for generating Flow components, PostgreSQL scripts, Total.js coding conventions or application-specific business rules.
This turns a generic model into a focused assistant for your product.
Tools connected to Total.js actions
The most powerful part of AIModel is tool execution. In Total.js, tools can be normal NEWACTION() handlers.
The AI model does not execute application code directly. It asks for a tool call. Total.js builds the tool schema from the action input, calls the action and sends the result back to the model.
Here is a complete example:
This creates a complete AI workflow:
- The user asks a question.
- The model decides it needs a tool.
- Total.js validates and executes the action.
- The tool result is sent back to the model.
- The model produces the final answer.
That is how AI moves from "chat" to real application automation.
Full test
The following actions are enough to test the functionality. The model can call Math|add and then finish the workflow with AI|done.
This example is intentionally small, but the same pattern can execute any Total.js action: read a document, search a database, create a ticket, call an internal API or generate a Flow component.
Memory for conversations
AIModel workflows can also keep conversation history.
This makes it possible to build assistants that remember the current session, keep context for a customer, continue code-generation tasks or guide an operator through a workflow.
The memory can expire automatically:
Again, the application remains in control.
What you can build
With AIMODEL, NEWAIMODEL and AIPARSER, Total.js applications can support many AI-powered features:
- a coding assistant trained with project rules
- a Flow component generator
- a PostgreSQL script assistant
- a support-ticket summarizer
- a documentation assistant
- a translation workflow
- a product-search helper
- an incident-analysis assistant
- a back-office operator assistant
- a controlled automation layer with Total.js actions as tools
This is the practical potential of AIModel. It is not only a wrapper around an AI provider. It is a foundation for AI-powered workflows inside real applications.
Conclusion
Total.js AIModel gives developers a clean, lightweight and flexible way to add AI capabilities to Total.js applications.
NEWAIMODEL() keeps provider integration in one place. AIMODEL() gives the application a simple fluent API. AIPARSER() handles streaming, thinking output and tool calls. Total.js actions can become controlled AI tools.
The result is a practical architecture for building AI features that are useful, maintainable and ready for real business software.
Other posts from Total.js Platform
- 2026-07-01June report 2026
- 2026-06-0214 Years of Building the Total.js Platform - Day by Day 🚀
- 2026-06-01May report 2026
- 2026-05-01April report 2026
- 2026-04-28Total.js without NPM? Absolutely. Run the framework from pure Node.js
- 2026-04-01March report 2026
- 2026-03-02February report 2026
- 2026-02-02January report 2026
- 2026-01-02December report 2025
- 2025-12-15Totally Merry Christmas and a Happy New Year 2026!
