Optionaloptions: AIGenerateOptionsIf receive an error "Authorization Denied", check policy AI / Access for the Analysis in Access Management.
// Let another Analysis handle the result, with the job as its scope
await Resources.ai.generate({
messages: "Write the weekly report for these readings: ...",
wait: 0,
callback: { analysis: "report-handler-analysis-id" },
});
Generates a response and waits up to timeout seconds (default 25) for
the generation to finish. Requires an Analysis token.
Resolves with the job once its status is completed, incomplete or
failed. If it is still queued or in_progress at the timeout, resolves
with the job as it is: the generation keeps running on the API, and
AI.getGeneration reads it later by job.id.
Each request is limited to the time left, and requests that fail in
transit are retried only while time remains, always with the same
idempotency key. The call returns within a few seconds of the timeout, and
a retry never starts a second generation. API rejections are not retried;
see AI.generate. For generations that may take longer than the
Analysis can run, use AI.generate with callback.
Optionaloptions: AIGenerateAndWaitOptionsIf receive an error "Authorization Denied", check policy AI / Access for the Analysis in Access Management.
const job = await Resources.ai.generateAndWait({
system: "You summarize sensor readings in one sentence.",
messages: "Readings from the last hour: 21.5C, 22.1C, 23.8C",
});
if (job.status === "queued" || job.status === "in_progress") {
console.log(`Still running, check later: ${job.id}`);
} else {
console.log(job.status, job.output?.text);
}
const job = await Resources.ai.generateAndWait<{ severity: "low" | "high" }>({
messages: "Classify: pump vibration at 12 mm/s",
response_format: {
type: "json_schema",
name: "alert",
schema: {
type: "object",
properties: { severity: { type: "string", enum: ["low", "high"] } },
required: ["severity"],
},
},
});
// `json` is `null` when the model did not return JSON. The API does not
// check it against the schema, so validate it before use.
const severity = job.output?.json?.severity;
if (severity === "low" || severity === "high") {
console.log(severity);
}
Gets a generation job started by AI.generate, as it stands. The API answers right away; it does not wait for the job to finish. Jobs are kept for 1 hour; a missing, expired, or other profile's job is rejected (404). Requires an Analysis token.
Generates a response with the profile's AI. Pure completion: no chat history and no TagoIO tools. Requires an Analysis token.
The API waits up to
waitseconds (default 10, max 25). If the generation finishes in time, the returned job has a final status (completed,incompleteorfailed). Otherwise it is stillqueuedorin_progress. Use AI.generateAndWait to always get the finished job, or setcallbackto run an Analysis when it finishes.The request is rejected with the API's message when the profile already runs 3 generations or used up its free monthly AI requests (429), when the AI Wallet has no funds (402), or when the body is invalid (400).