AI and file storage
≈ 10 min · you will have an app that suggests replies with AI and stores attachments, with no API key.
manh.run holds the credentials for the built-in services. App code only imports a module; the app never sees a key and cannot read another app’s files. These modules work in server .ts files only. Email and Telegram have their own pages: Send and receive email, Telegram bot.
Call AI
new OpenAI() from manh/openai is called like the official openai SDK. Write a familiar OpenAI model name; manh.run maps it to the open-weight gpt-oss models.
import { OpenAI } from "manh/openai";
const openai = new OpenAI();
export async function suggestReply(ticket: { subject: string; body: string }) {
try {
const r = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: "You are a support agent. Reply briefly and politely." },
{ role: "user", content: `${ticket.subject}\n\n${ticket.body}` },
],
max_tokens: 400,
});
return r.choices[0].message.content || null; // empty content = failed
} catch {
return null; // the feature still works when AI fails
}
}gpt-4o-mini,gpt-4.1-mini,gpt-5-miniuse the fast model; othergpt-*names (such asgpt-4o) use the stronger reasoning model. Other model names are refused.- Chat (including streaming and
tools) and embeddings (text-embedding-*, which read Vietnamese) are available.max_tokensis at most 4096. - No image generation, speech or image input. Don’t build features on them.
Store and share files
Each app has its own folder in file storage. A key is a relative path, with no leading / and no ...
import { blob } from "manh/blob";
// inside an async repository function; `bytes` is the file content
await blob.set("invoices/42.pdf", bytes, { contentType: "application/pdf" });
const res = await blob.get("invoices/42.pdf"); // Response
const files = await blob.list("invoices/"); // every file under the prefix
await blob.delete("invoices/42.pdf");
blob.getUrl("public/products/t-shirt.jpg"); // permanent public link
await blob.presignGet("contracts/7.pdf", { expiresIn: 3600 }); // expiring signed linkThe key decides public or private. Files under public/ (product photos, avatars) have a permanent link; every other file opens only through an expiring signed link. Store the key on the record and build the link when you return it.
Let the browser upload a file
The server hands out a signed upload link with blob.presignPut(key). The browser sends the file straight to storage, then sends the key with the form.
import { z } from "@hono/zod-openapi";
import { blob } from "manh/blob";
export const schema = { body: z.object({ name: z.string().max(200), type: z.string() }) };
export default async (c, { body }) => {
const key = `uploads/${crypto.randomUUID()}-${body.name.replace(/[^\w.-]/g, "_")}`;
return { key, url: await blob.presignPut(key) };
};// inside the handler that runs when the user picks `file`; `api` = useApiClient()
const { key, url } = await api.uploads.sign({ name: file.name, type: file.type });
await fetch(url, { method: "PUT", body: file }); // goes to file storage, not through the app's APIGood to know
- AI tokens per month and file storage size depend on the plan. See Plan limits.
- One file sent with
blob.setis at most 100 MB. Checkfile.sizein the UI and state the limit. blob.getUrlon a key outsidepublic/throws.blob.head(key)returns size, type and last change, ornull.- The app owner sees and manages files in the project’s Files tab.
- For PDFs (receipts, invoices with Vietnamese text) use
manh/pdf, notpdf-lib. - For an outside service with its own key, see Call outside APIs.
Next steps
- Send and receive email — send order confirmations and receive mail into the app.
- std/openai — every option for calling AI.
- std/blob — every file storage function.