AI Decorators
Define AI completion, embeddings, RAG pipelines, safety policies, model capabilities, and token budgets with AxilJS semantic decorators.
On this page13
AxilJS AI decorators describe AI-powered behavior without coupling application code to a specific model provider.
They declare the capability or constraint an operation requires. An AI consumer can then interpret that metadata and select the appropriate model, provider, safety policy, retrieval pipeline, or resource limits.
This keeps AI semantics in the application contract while allowing the underlying AI infrastructure to evolve independently.
@tAIComplete
Declares that a method produces its result through LLM completion.
1import { tAIComplete } from '@axiljs/decorator'
2
3@tAIComplete({
4 task: 'summarization',
5 temperature: 0.3
6})
7async summarize(text: string) {}Tasks
| Task | Description |
|---|---|
'summarization' | Condense text |
'classification' | Categorize content |
'extraction' | Extract structured data |
'generation' | Generate new content |
'reasoning' | Perform complex reasoning |
The task describes the intended AI capability rather than a specific model or vendor.
@tAIEmbed
Declares that an operation produces embeddings for vector storage or search.
1import { tAIEmbed } from '@axiljs/decorator'
2
3@tAIEmbed({
4 storeIn: 'documents',
5 dimensions: 1536
6})
7async embedDocument(text: string) {}The metadata describes the embedding requirement and target storage context so an AI consumer can handle the embedding operation.
@tAIRAG
Declares a retrieval-augmented generation pipeline.
1import { tAIRAG } from '@axiljs/decorator'
2
3@tAIRAG({
4 collection: 'support-docs',
5 topK: 5,
6 includeSources: true
7})
8async answerQuestion(question: string) {}The declaration specifies the retrieval collection, number of results, and whether retrieved sources should be included in the result.
@tAIGuard
Declares content-safety checks for AI input or output.
1import { tAIGuard } from '@axiljs/decorator'
2
3@tAIGuard({
4 policies: ['toxicity', 'pii', 'jailbreak'],
5 action: 'block'
6})
7async generateContent(prompt: string) {}Policies
| Policy | Description |
|---|---|
'toxicity' | Hate speech and harassment |
'pii' | Personal information leakage |
'spam' | Spam and promotional content |
'nsfw' | Not-safe-for-work content |
'jailbreak' | Prompt injection attempts |
Actions
| Action | Description |
|---|---|
'block' | Reject the request |
'flag' | Allow the request but flag it for review |
'warn' | Allow the request with a warning |
The decorator describes the required safety policy; the AI consumer is responsible for enforcing it.
@tAIModel
Selects an AI model by capability rather than by vendor or model name.
1import { tAIModel } from '@axiljs/decorator'
2
3@tAIModel({ capability: 'reasoning' })
4async analyze(data: string) {}Capabilities
| Capability | Description |
|---|---|
'reasoning' | Complex logical reasoning |
'coding' | Code generation and review |
'summarization' | Text condensation |
'vision' | Image understanding |
'embedding' | Vector embeddings |
This allows the application to describe the required model capability while leaving model selection to the AI infrastructure.
@tAITokenBudget
Declares input, output, and cost limits for an AI operation.
1import { tAITokenBudget } from '@axiljs/decorator'
2
3@tAITokenBudget({
4 maxInput: 4000,
5 maxOutput: 1000,
6 costLimit: 0.05
7})
8async summarize(text: string) {}The budget provides explicit resource constraints for AI execution.
Full AI Example
AI decorators can be composed with HTTP, authentication, quota, caching, and other AxilJS semantics:
1import {
2 tHttp,
3 tAuth,
4 tAIGuard,
5 tAIModel,
6 tAITokenBudget,
7 tAIComplete,
8 tQuota,
9 tCache,
10 tBody
11} from '@axiljs/decorator'
12
13@tHttp({
14 method: 'POST',
15 path: '/api/ai/summarize'
16})
17@tAuth({ required: true })
18@tAIGuard({
19 policies: ['toxicity', 'pii'],
20 action: 'block'
21})
22@tAIModel({
23 capability: 'summarization'
24})
25@tAITokenBudget({
26 maxInput: 4000,
27 maxOutput: 500
28})
29@tAIComplete({
30 task: 'summarization',
31 temperature: 0.3
32})
33@tQuota({
34 resource: 'ai.tokens',
35 amount: 1000
36})
37@tCache({
38 key: (text) => `summary:${hash(text)}`,
39 ttl: 3600_000
40})
41async summarize(@tBody('text') text: string) {
42 // AI infrastructure consumes the declared metadata.
43}The AI consumer can read the tAI* metadata and orchestrate the provider call, safety checks, budget enforcement, and other declared semantics.
Composable AI Semantics
AI decorators describe independent concerns:
tAICompletedefines the AI task.tAIModeldefines the required model capability.tAIGuarddefines content-safety requirements.tAITokenBudgetdefines execution limits.tAIRAGdefines retrieval-augmented generation.tAIEmbeddefines embedding requirements.
They can also be composed with non-AI decorators such as tAuth, tQuota, tCache, and tHttp.
This gives an AI operation a declarative contract without requiring its business logic to directly encode provider-specific orchestration.
Reference
| Decorator | Purpose |
|---|---|
tAIComplete | Declare an LLM completion task |
tAIEmbed | Produce embeddings for storage or search |
tAIRAG | Declare a retrieval-augmented generation pipeline |
tAIGuard | Define AI content-safety policies |
tAIModel | Select a model by capability |
tAITokenBudget | Define input, output, and cost limits |
AxilJS AI decorators make AI behavior explicit, composable, and provider-independent. The application declares what AI capability it needs; an AI consumer can determine how that capability is fulfilled.
Was this page helpful?