Skip to content

Add // @ai true to any script and get AI superpowers. No imports, no API key management, no SDK setup. The Vercel AI SDK helpers are injected directly into your script context — generateText, streamText, generateObject — ready to use with 300+ models via Hoody AI.

This is what happens when you combine “files are APIs” with “containers have AI access”: every script you write can be an AI-powered endpoint.


Add the @ai magic comment to any script:

// @mode serverless
// @ai true
const { text } = await generateText({
model,
prompt: 'Explain quantum computing in one sentence'
});
return { answer: text };

That’s it. The script now has:

  • model — Pre-configured AI model (from @ai-model or default)
  • openai — OpenAI SDK client instance
  • ai — Helper namespace (ai.generate, ai.stream, ai.object)
  • generateText() — Generate text completion
  • streamText() — Stream text responses
  • generateObject() — Generate structured JSON objects

Control AI behavior with these magic comments:

CommentValuesDefaultDescription
@aitrue | falsetrueEnable AI helpers
@ai-modelmodel nameminimax/minimax-m2.5Which model to use
@ai-temperature0 - 2Creativity level (0 = deterministic, 2 = very creative). Provider default when unset
@ai-max-tokensnumberMaximum response length. Provider default when unset
@ai-keystringserver-configuredAPI key override (default from server’s --ai-key flag)

The @ai-model value uses Hoody AI model identifiers in provider/model format:

// @ai-model anthropic/claude-sonnet-4.5 // Anthropic Claude
// @ai-model openai/gpt-4o // OpenAI GPT-4o
// @ai-model google/gemini-2.5-pro // Google Gemini
// @ai-model meta-llama/llama-3.3-70b // Meta Llama
// @ai-model mistralai/mistral-large // Mistral

When @ai true is set, these are automatically available in your script:

A pre-configured OpenAI SDK client instance. Connects to the Hoody AI gateway (default: https://ai.hoody.icu/api/v1) using a server-configured API key — no manual setup required.

// @ai true
// Use the OpenAI SDK directly for full control
const completion = await openai.chat.completions.create({
model: 'minimax/minimax-m2.5',
messages: [{ role: 'user', content: 'Hello!' }]
});
return { reply: completion.choices[0].message.content };

A pre-configured Vercel AI SDK model instance from the @ai-sdk/openai package. Uses the model name from @ai-model (default: minimax/minimax-m2.5). Pass this to generateText, streamText, or generateObject.

// @ai true
// @ai-model anthropic/claude-sonnet-4.5
// `model` is already configured with the above model
const { text } = await generateText({ model, prompt: 'Hello!' });

A high-level helper namespace that wraps common AI operations. Provides three convenience methods built on top of the Vercel AI SDK:

  • ai.generate(options) — Generate a complete text response (wraps generateText)
  • ai.stream(options) — Stream text chunks as they are produced (wraps streamText)
  • ai.object(options) — Generate structured JSON validated against a schema (wraps generateObject)
// @ai true
const { text } = await ai.generate({ prompt: 'Hello!' });
const { textStream } = await ai.stream({ prompt: 'Write a poem' });
const { object } = await ai.object({ schema, prompt: 'Classify this' });

Generate a complete text response. Returns when the full response is ready.

Options: { prompt?, messages?, model?, system?, temperature?, maxTokens? }

// @ai true
// @ai-model anthropic/claude-sonnet-4.5
const { text } = await generateText({
model,
prompt: 'Write a haiku about HTTP'
});
return { haiku: text };

streamText(options) — Streaming Responses

Section titled “streamText(options) — Streaming Responses”

Stream text response chunks as they are generated. Ideal for long responses or real-time UIs.

Options: { prompt?, messages?, model?, system?, temperature?, maxTokens? }

// @ai true
// @ai-model anthropic/claude-sonnet-4.5
// @timeout 60000
const { textStream } = await streamText({
model,
prompt: req.body.question
});
// Stream back to client
res.writeHead(200, { 'Content-Type': 'text/plain' });
for await (const chunk of textStream) {
res.write(chunk);
}
res.end();

generateObject(options) — Structured JSON Output

Section titled “generateObject(options) — Structured JSON Output”

Generate structured JSON that matches a provided schema. The AI response is validated against the schema automatically.

Options: { prompt?, messages?, model?, schema, system?, temperature?, maxTokens? }

// @ai true
// @ai-model anthropic/claude-sonnet-4.5
const { object } = await generateObject({
model,
schema: {
type: 'object',
properties: {
sentiment: { type: 'string', enum: ['positive', 'negative', 'neutral'] },
confidence: { type: 'number' },
keywords: { type: 'array', items: { type: 'string' } }
}
},
prompt: `Analyze the sentiment of: "${req.body.text}"`
});
return object;
// → { sentiment: 'positive', confidence: 0.92, keywords: ['great', 'love'] }

When @ai true is enabled, the following defaults are applied:

SettingDefaultOverride
AI URLhttps://ai.hoody.icu/api/v1Server-launch --ai-url flag
Modelminimax/minimax-m2.5@ai-model magic comment
API KeyServer-configured default (via --ai-key flag)@ai-key magic comment
TemperatureProvider default@ai-temperature magic comment
Max TokensProvider default@ai-max-tokens magic comment

Override any per-script default with the corresponding magic comment:

// @ai true
// @ai-model openai/gpt-4o
// @ai-key sk-custom-key-here
// @ai-temperature 0.3
// @ai-max-tokens 2048

AI calls respect the script’s @timeout setting. If the AI provider takes longer than the configured timeout, the request will be terminated.

// @ai true
// @timeout 30000 // AI call must complete within 30 seconds
const { text } = await generateText({
model,
prompt: req.body.question
});
return { answer: text };

There is no automatic retry for failed AI calls. If you need retry logic, implement it in your script:

// @ai true
// @timeout 60000
async function withRetry(fn, retries = 3) {
for (let i = 0; i < retries; i++) {
try {
return await fn();
} catch (err) {
if (i === retries - 1) throw err;
}
}
}
const { text } = await withRetry(() =>
generateText({ model, prompt: req.body.question })
);
return { answer: text };

To validate AI-related magic comments without executing a script, use the magic comments validation endpoint:

Terminal window
curl -s -X POST "https://PROJECT-CONTAINER-exec-1.SERVER.containers.hoody.icu/api/v1/exec/validate/magic-comments" \
-H "Content-Type: application/json" \
-d '{
"code": "// @ai true\n// @ai-model openai/gpt-4o\n// @ai-temperature 0.5\nreturn {};"
}'

You can also retrieve the full magic comments schema (including all @ai-* directives) with:

Terminal window
curl "https://PROJECT-CONTAINER-exec-1.SERVER.containers.hoody.icu/api/v1/exec/magic-comments/schema"

api/summarize.ts
// @mode serverless
// @ai true
// @ai-model anthropic/claude-sonnet-4.5
// @ai-temperature 0.3
// @cors reflective
// @timeout 30000
if (!req.body?.content) {
res.statusCode = 400;
return { error: 'Missing content field' };
}
const { text } = await generateText({
model,
prompt: `Summarize the following text in 2-3 sentences:\n\n${req.body.content}`
});
return {
summary: text,
originalLength: req.body.content.length,
summaryLength: text.length
};
api/classify.ts
// @mode serverless
// @ai true
// @ai-model minimax/minimax-m2.5
// @ai-temperature 0
// @cors reflective
const { object } = await generateObject({
model,
schema: {
type: 'object',
properties: {
category: { type: 'string', enum: ['bug', 'feature', 'question', 'docs', 'other'] },
priority: { type: 'string', enum: ['low', 'medium', 'high', 'critical'] },
summary: { type: 'string' }
}
},
prompt: `Classify this support ticket:\n\n${req.body.ticket}`
});
return object;
api/chat.ts
// @mode serverless
// @ai true
// @ai-model anthropic/claude-sonnet-4.5
// @ai-temperature 0.7
// @ai-max-tokens 2048
// @cors reflective
// @timeout 60000
const messages = req.body.messages || [];
const { textStream } = await streamText({
model,
messages: [
{ role: 'system', content: 'You are a helpful assistant. Be concise.' },
...messages
]
});
// Stream Server-Sent Events
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
for await (const chunk of textStream) {
res.write(`data: ${JSON.stringify({ text: chunk })}\n\n`);
}
res.write('data: [DONE]\n\n');
res.end();

One of the most powerful patterns: use a hoody-exec worker script as a MITM (Man-In-The-Middle) proxy for AI requests. Intercept, analyze, modify, block, or enhance every AI interaction.

The simplicity: Deploy a MITM script once, then just change the URL in your AI client:

Without MITM: https://ai.hoody.icu/api/v1
With MITM: https://your-project-container-exec-1.node-us.containers.hoody.icu/api/v1

What you gain:

  • Tool Call Tampering — Redirect file writes, block dangerous commands
  • Human-in-the-Loop — Pause AI for approval on high-stakes operations
  • Cost Optimization — Compress prompts, cache responses, route to cheaper models
  • Context Injection — Auto-enhance prompts with your knowledge base
  • Complete Observability — Log every prompt, response, and decision

See Hoody AI Intercept & Control for the complete MITM guide with full examples.