AI
Generate text using AI models directly, without creating a full Claude Code session. Useful for lightweight tasks like summarization, classification, or title generation.
Availability: Both (backend ctx.ai / frontend Omniscio.ai) Required Permission: ai
Methods
generateMessage(systemPrompt: string, userPrompt: string): Promise<string>
Send a system prompt and user prompt to an AI model and receive a text response.
Parameters:
| Name | Type | Description |
|---|---|---|
systemPrompt | string | Instructions for the AI model (its role and behavior) |
userPrompt | string | The user's request or the content to process |
Returns: Promise<string> -- the model's text response.
Example:
// Frontend
const summary = await Omniscio.ai.generateMessage(
'You are a technical writer. Summarize code changes in 2-3 sentences.',
'Added pagination to the /users endpoint with cursor-based navigation...',
)
// Backend
const review = await ctx.ai.generateMessage(
'You are a senior code reviewer. Identify potential bugs and suggest fixes.',
`Review this function:\n\n${functionCode}`,
)
ctx.log.info(`Review: ${review}`)generateTextViaSubscription(systemPrompt: string, userPrompt: string, opts?: { model?: string }): Promise<string>
Write text on the person's own Claude plan instead of a stored API key. Use it first, and fall back to generateMessage only when it refuses.
Parameters:
| Name | Type | Description |
|---|---|---|
systemPrompt | string | Instructions for the AI (up to 32 KB; may be empty) |
userPrompt | string | The request (1 character to 32 KB) |
opts.model | string | Optional Claude model id; any other key (a provider, a picture) is refused |
Returns: Promise<string> -- the text. On the window bridge a failed call resolves null; the backend rejects.
What it can and cannot do:
- Text only. The AI behind it has no tools and no tool servers, so it cannot run a command, read a file, browse or act on anything in your prompt.
- Only while the person has your plugin turned on, and only with both the
aiandai.subscriptionpermissions in your manifest. - It counts against your plugin's daily AI limit (the one the person sets in Settings), with at most 3 AI calls running at once. A limit of $0 stops it.
- It never falls back to an API key by itself. When the plan cannot answer, it refuses with the code
plugin-ai-plan-unavailableand the fixed message "Your Claude plan could not write this right now. Try again later, or use your API key instead." The refusal never says why, by design: a plugin cannot learn which sign-in the person uses. - Check
host.getCapabilities()for theai-plan-texttoken before calling. Omniscio lists it only for a plugin whose manifest declaresai.subscription, and an older Omniscio does not have this method. A call from a plugin without the permission is refused with the sameplugin-ai-plan-unavailablecode, so falling back to your API key on that code still works.
Example:
const caps = await ctx.host.getCapabilities()
async function write(system: string, prompt: string): Promise<string> {
if (caps.includes('ai-plan-text')) {
try {
return await ctx.ai.generateTextViaSubscription(system, prompt)
} catch {
// the plan could not answer; use the stored key as the backup
}
}
return ctx.ai.generateMessage(system, prompt)
}generateTitle(text: string): Promise<string>
Generate a short, descriptive title from a block of text. Useful for automatically naming sessions, reports, or documents.
Parameters:
| Name | Type | Description |
|---|---|---|
text | string | The text to generate a title from |
Returns: Promise<string> -- a short title.
Example:
// Frontend
const title = await Omniscio.ai.generateTitle(
'This PR migrates the authentication system from session cookies to JWT tokens, ' +
'adds refresh token rotation, and updates all middleware...',
)
// title: "JWT Auth Migration with Refresh Token Rotation"
// Backend
const title = await ctx.ai.generateTitle(reportContent)
await ctx.db.update('reports', reportId, { title })generateStructured(opts): Promise<Record<string, unknown>>
Ask for a JSON answer in a shape you define, instead of prose you have to parse. You pass a JSON Schema, the host forces the model to fill it, and you get the filled object back.
Parameters:
| Name | Type | Description |
|---|---|---|
opts.prompt | string | What to extract or decide, up to 32 KB |
opts.tool | object | The shape to fill: { name, description?, inputSchema } — name up to 64 characters, inputSchema a JSON Schema object of at most 128 keys |
opts.systemPrompt | string | Optional instructions, up to 32 KB |
opts.model | string | Optional Anthropic model id |
opts.premium | boolean | Optional: use the premium model (Opus) instead of the default |
opts.maxOutputTokens | number | Optional answer length, 1 to 16,384 — a value outside it is refused, never clamped |
Returns: Promise<Record<string, unknown>> — the object that fills inputSchema.
Metered against your plugin's own daily AI cap, the same one generateMessage uses, so a plugin can never spend past it by looping on this call.
Example:
const lead = await ctx.ai.generateStructured({
prompt: `Extract the contact from this email:\n\n${emailBody}`,
tool: {
name: 'contact',
description: 'The person the email is about.',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string' },
company: { type: 'string' },
intent: { type: 'string', enum: ['buy', 'support', 'other'] },
},
required: ['name', 'intent'],
},
},
})
ctx.log.info(`${lead.name} at ${lead.company}`)isConfigured(): Promise<boolean>
Whether an AI key account exists, checked before you offer to generate anything.
Returns: Promise<boolean> — true when generateMessage, generateTitle and generateStructured will run; false when they would fail.
Use it to disable a Generate button and say why, rather than letting the person click and read an error. It asks the same resolver those calls use, so a key saved in an isolated slot counts.
Example:
const ready = await Omniscio.ai.isConfigured()
if (!ready) {
Omniscio.toast.show({ type: 'info', message: 'Add an AI API key in Settings first.' })
}listEngines(): Promise<PluginEngineCatalog>
The engines and models this person can actually use, so a plugin can offer the same choice a session does instead of hard-coding a model name.
Returns: Promise<PluginEngineCatalog> — { version, defaults, engines, agentsLocked }. Each entry of defaults (session and writing) is { provider, model, label }, and each engine carries { id, label, ready, writing, writingReady, canRunNoTools, defaultModel, models, data }. ready: false means that engine cannot run here (no account, or the person's settings floor it).
Example:
const { engines } = await Omniscio.ai.listEngines()
const usable = engines.filter((engine) => engine.ready)
const model = usable[0]?.defaultModel
if (!model) {
Omniscio.toast.show({ type: 'info', message: 'No AI engine is ready on this computer yet.' })
}estimateImage(request): Promise<BridgeImageEstimate | BridgeImageRefusal> (panel only)
Omniscio's own price for one Image Studio picture, its service fee included. Free. Needs the ai.images permission.
generateImage(request): Promise<BridgeImageResult | BridgeImageRefusal> (panel only)
Make one picture with Image Studio, paid from the user's Omniscio credit. Needs the ai.images permission. Omniscio prices it, checks the user's balance and this plugin's daily picture limit, then shows the user its own confirmation; only their Generate spends.
request:
| Field | Type | Description |
|---|---|---|
subject | string | What to draw, 1 to 4,000 characters |
model | string | An Image Studio model id |
aspectRatio | '1:1' | '4:3' | '3:4' | '16:9' | '9:16' | The picture's shape |
style | string? | Optional style notes |
imageSize | '0.5K' | '1K' | '2K' | '4K'? | Optional size |
transparentBackground | boolean? | Ask for a transparent background |
referenceImages | string[]? | This picture's OWN reference pictures, up to 2, as data:image/png;base64,... (or jpeg / webp) strings, each up to 1,500,000 characters. On a set, a picture also uses the set's shared list, up to 6 references in total |
Any other field (a picture count, a price) is refused.
Returns: { ok: true, imageId, base64, model, costUsd }, or a refusal { ok: false, code, message } — it does not reject for these. code is plugin-images-off, signed-out, plugin-image-daily-cap, insufficient-credit (Omniscio already offered the user Add credit), declined, busy, image-service-error or duplicate-request (the requestId was already used; claim its pictures instead).
The picture always arrives as base64 bytes, so a canvas that draws it is never tainted. When Image Studio stores the picture instead of returning it, Omniscio downloads it for you; if that download fails you get image-service-error.
Example:
const caps = await AgentMC.host.getCapabilities()
if (caps.includes('ai-images')) {
const result = await AgentMC.ai.generateImage({
subject: 'A watercolor fox reading a map in the snow',
model: 'gemini-3.1-flash-lite-image',
aspectRatio: '1:1'
})
if (result.ok) showPicture(result.base64 ?? result.url)
else if (result.code !== 'declined') showMessage(result.message)
}estimateImageSet(requests, opts?): Promise<BridgeImageSetEstimate | BridgeImageRefusal> (panel only)
Omniscio's own price for a set of pictures, Omniscio's fee included. Free. Needs the ai.images permission.
generateImageSet(requests, opts?): Promise<BridgeImageSetResult | BridgeImageRefusal> (panel only)
Make a set of pictures with Image Studio, paid from the user's Omniscio credit, behind one confirmation for the whole set. Needs the ai.images permission.
requests: an array of 1 to 8 request objects, each shaped as above. The pictures' own referenceImages across the whole set may add up to at most 6,000,000 characters; a set over that, or over 8 pictures, is refused.
opts.referenceImages: the photos every picture in the set uses, up to 6, as the same data URIs, each up to 1,500,000 characters. You send them ONCE for the whole set, instead of repeating them on every picture. A picture carries these plus its own references, at most 6 in total, and one picture's whole list may add up to at most 6,000,000 characters. Anything over that is refused before anything is priced.
Returns: { ok: true, items, costUsd }, where items holds one picture result or refusal per request, in order. estimateImageSet returns { ok: true, items: [{ model, priceUsd }], priceUsd } instead. A refusal for the whole set is { ok: false, code, message } with the same codes as generateImage.
Example:
const result = await AgentMC.ai.generateImageSet([
{ subject: 'A watercolor fox, front view', model: 'gemini-3.1-flash-lite-image', aspectRatio: '1:1' },
{ subject: 'The same fox, side view', model: 'gemini-3.1-flash-lite-image', aspectRatio: '1:1' }
])
if (result.ok) {
result.items.forEach((item) => {
if (item.ok) showPicture(item.base64 ?? item.url)
})
} else if (result.code !== 'declined') showMessage(result.message)getImageSpend(): Promise<BridgeImageSpend | BridgeImageRefusal> (panel and worker)
What this plugin has spent on pictures today and this calendar month, and its daily picture limit, all in US dollars. Free. Needs the ai.images permission and takes no arguments (any argument is refused).
Returns: { ok: true, todayUsd, monthUsd, dailyLimitUsd }. todayUsd is the exact figure the daily limit is judged against, so dailyLimitUsd - todayUsd is what the plugin can still spend today; dailyLimitUsd is 0 when the person turned plugin pictures off. Only this plugin's own pictures count: never another plugin, its text-AI spend, or the credit balance. A plugin that also holds ai.clips gets three more fields beside them — clipTodayUsd, clipMonthUsd and clipDailyLimitUsd — summed the same way from its own clip spend; one without ai.clips gets the picture figures alone. At most 60 reads a minute; a faster call answers { ok: false, code: 'busy', message }.
Example:
const spend = await AgentMC.ai.getImageSpend()
if (spend.ok) showGuard(spend.todayUsd, spend.dailyLimitUsd, spend.monthUsd)opts.requestId — name a request
generateImage(request, opts?) takes an optional { requestId }, and generateImageSet(requests, opts?) an optional { requestId, referenceImages }: your own handle for that request, 1 to 64 letters, digits, - or _, plus, on a set, the photos every picture in it uses. Any other value, or any other field in opts, is refused before anything is priced or asked. The person never sees the id. On a set it comes back on every onImageSetItem event.
Every picture made under a requestId is kept by Omniscio on this computer for 24 hours, so a panel that closed or lost its answer can get it back with claimImages. An id can be used once: a request whose id was already used in the last 24 hours is refused duplicate-request before anything is priced or asked, so a resent request never pays twice. A request that was declined or refused before it was paid leaves its id free. Use a new id for every new paid try.
onImageSetItem(callback): () => void (panel only)
See each picture of a set the moment it is made, instead of waiting for the whole set. Subscribe before calling generateImageSet; the return value unsubscribes. Needs the ai.images permission.
The callback gets one event per picture, in the order asked: { requestId, index, count, item, costUsd }. requestId is the set's own id or null, item is exactly what the final items[index] will hold (a picture or a refusal), and costUsd is that picture's own charge (0 for one that was not made). Only the panel that asked receives them. A set refused as a whole sends no event. The final answer of generateImageSet is unchanged, so a plugin that never subscribes works exactly as before. The last event and the final answer travel separately, so treat the final answer as the record and the events as progress.
const off = AgentMC.ai.onImageSetItem(({ requestId, index, count, item }) => {
if (requestId !== 'batch-7') return
showProgress(index + 1, count)
if (item.ok) showPicture(item.base64 ?? item.url)
})
const result = await AgentMC.ai.generateImageSet(requests, { requestId: 'batch-7' })
off()claimImages(requestId): Promise<BridgeImageClaim | BridgeImageRefusal> (panel only)
Get back the pictures already made and paid for under a requestId, for 24 hours after each was made. Free: it never prices, asks, charges or calls Image Studio. Needs the ai.images permission.
Returns: { ok: true, items }, where each item is { index, item }: the picture's position in its request and the same picture result generateImage returned, costUsd included, in order. A picture that was not made is not listed. An unknown id, an expired id and another plugin's id all answer { ok: false, code: 'not-found', message }. At most 60 claims a minute; a faster call answers busy.
const kept = await AgentMC.ai.claimImages('batch-7')
if (kept.ok) kept.items.forEach(({ index, item }) => placePicture(index, item.base64 ?? item.url))estimateImagePolish(polish): Promise<BridgeImagePolishEstimate | BridgeImageRefusal> (panel only)
Omniscio's own price for enlarging one of this plugin's pictures, or removing its background. Free. Needs the ai.images permission.
Parameters: one object — { op: 'upscale', imageId, scaleFactor? } with scaleFactor 2 or 4, or { op: 'remove-background', imageId, provider? } with provider 'bria' or '851-labs'. Omit the option and the picture service applies its own default. Any other field, or the other op's option, is refused before anything is priced.
Returns: { ok: true, op, priceUsd }, the most the person's credit can be charged, Omniscio's fee included. A refusal is { ok: false, code, message } with the same codes as generateImage.
const quote = await AgentMC.ai.estimateImagePolish({ op: 'upscale', imageId, scaleFactor: 4 })
if (quote.ok) showPrice(quote.priceUsd)polishImage(polish): Promise<BridgeImageResult | BridgeImageRefusal> (panel only)
Enlarge one of this plugin's pictures, or remove its background, through Image Studio. The picture's own pixels are kept — it is transformed, never redrawn, and the original is untouched. Paid from the person's Omniscio credit: Omniscio prices it, shows the person its own confirmation and spends only on their yes, inside this plugin's daily picture limit. Needs the ai.images permission.
Only a picture THIS plugin made can be polished. Omniscio records every picture your plugin makes; any other id — another plugin's, or one nobody made — answers { ok: false, code: 'not-found', message } before anything is priced or asked.
Returns: the same picture result generateImage returns — { ok: true, imageId, base64, model, costUsd } — where imageId is the NEW picture. Polish it again and the result is itself polishable.
Retries: Omniscio never retries a paid polish by itself, because a re-run of a billable change re-bills. The picture service's own key means a retry of the identical request is one charge, and asking again after a picture was delivered is a new paid call. A polish that fails charges nothing.
const polished = await AgentMC.ai.polishImage({ op: 'remove-background', imageId })
if (polished.ok) drawOnTransparency(polished.base64)Clips — estimateClip, generateClip, onClipProgress, claimClip (panel only)
One short silent clip at a time, paid from the user's Omniscio credit, behind the separate elevated ai.clips permission. Holding ai or ai.images grants nothing here, and ai.clips grants no pictures. Check host.getCapabilities() for ai-clips before you offer a clip button.
estimateClip(request) is free and answers { ok: true, model, priceUsd, spentTodayUsd?, capUsd? } — Omniscio's own price, its service fee included.
generateClip(request, opts?) prices the clip, checks the user's balance and this plugin's own daily clip limit, and — for any plugin Omniscio does not ship — shows the user its own confirmation; only their Generate spends. A built-in plugin's panel shows the price itself and no host dialog opens.
request:
| Field | Type | Description |
|---|---|---|
prompt | string | What the clip shows, 1 to 2,000 characters |
durationSec | number | A whole number of seconds from 4 to 8 |
aspectRatio | '1:1' | '16:9' | '4:5' | The clip's shape |
referenceImage | string? | At most ONE first-frame picture, a small data:image/png;base64,... (or jpeg / webp) string |
Any other field is refused before anything is priced or asked. opts accepts only { requestId }, with the same rules as a picture's.
Returns: { ok: true, clipId, base64, model, costUsd } — a silent H.264 MP4 at most 720p and 12 MB, always as base64 bytes — or a refusal { ok: false, code, message }. code is plugin-images-off, signed-out, plugin-clip-daily-cap, insufficient-credit, declined, busy, clip-service-error, duplicate-request or not-found. The clip shares the plugin's one waiting-request slot and its five confirmations a minute with its pictures, so a picture already waiting makes a clip busy and the other way round. A charge is recorded before the bytes are checked; a download or check that fails answers clip-service-error and refunds it. An outcome the clip service cannot confirm is never retried on its own.
onClipProgress(callback) reports { requestId, state, elapsedSec } at least every 15 seconds while the clip is being made, where state is queued, making, made or failed. Only the panel that asked receives them. Closing the panel never stops a confirmed clip: the app finishes it, checks it, records or refunds the charge, and keeps it for 24 hours.
claimClip(requestId) gets a kept clip back for 24 hours after it was made, free. An unknown id, an expired id and another plugin's id all answer not-found.
const off = AgentMC.ai.onClipProgress(({ state, elapsedSec }) => showClipProgress(state, elapsedSec))
const result = await AgentMC.ai.generateClip(
{ prompt: 'A paper fox running through snow, stop-motion', durationSec: 6, aspectRatio: '16:9' },
{ requestId: 'clip-7' }
)
off()
if (result.ok) playClip(result.base64)deleteImage(imageId): Promise<BridgeImageCleanup | BridgeImageRefusal> (panel only)
Delete one picture THIS plugin made: Image Studio's stored copy of it and the 24-hour copy Omniscio kept of it. Free: it never prices, asks or charges. Needs its own ai.imageDelete permission — ai.images, which lets a plugin make pictures, does not grant it.
Only a picture THIS plugin made can be deleted. Omniscio records every picture your plugin makes; any other id — another plugin's, or one nobody made — answers { ok: false, code: 'not-found', message }, and nothing is deleted. A picture already gone from Image Studio counts as done.
Returns: { ok: true }.
const gone = await AgentMC.ai.deleteImage(imageId)
if (gone.ok) forgetInLibrary(imageId)clearTemporaryCopies(): Promise<BridgeImageCleanup | BridgeImageRefusal> (panel only)
Delete every 24-hour kept picture copy of this plugin. The pictures in Image Studio's stored library, your paid-once request markers and any clips you kept are left alone — delete stored pictures one at a time with deleteImage. Free. Needs its own ai.imageDelete permission — ai.images alone is refused.
Returns: { ok: true }.
await AgentMC.ai.clearTemporaryCopies()Notes
estimateImage/generateImage/estimateImageSet/generateImageSet/onImageSetItem/claimImages/estimateImagePolish/polishImage/deleteImage/clearTemporaryCopieswork only from the plugin's panel, and their spend has its own per-plugin daily limit (Cost Control → Plugin pictures, $2 unless changed), separate from the text-AI limit. A polish counts toward the same limit as the pictures it edits. Deleting is free and does not count toward that limit.generateTextViaSubscriptionruns on the person's Claude plan; every other method here goes through Omniscio's AI service on a stored key.- These key calls go through Omniscio's AI service, which requires an API key account. OAuth/login accounts cannot make direct AI calls. If no API key account is available, the call will fail with a descriptive error.
- Call
isConfiguredfirst when you are about to show a Generate control — it is the difference between a disabled button and a failed click. generateMessageis best for short, targeted tasks. For complex multi-turn interactions, use the Sessions API instead.generateTitleis optimized for producing concise titles (typically under 10 words).