Skip to content

Complete

Completes an independent request and returns JSON, plain text or binary content.

1
$AI.Complete(request: AICompletionRequest):AICompletionResult

Parameters

AICompletionRequest request

Remarks

Selects an effective configured provider by name, or uses the first enabled provider. Messages and binary attachments are passed directly to the configured model. Attachments have no MIME, extension or model capability filtering; FileName is metadata. Invalid requests, provider failures and incomplete or unsupported responses throw coded errors. No response format is forced, and there is no repair or automatic second model call. Cancellation and script timeout cancel the request; the standard 100-second HTTP timeout also bounds the call.

Example

1
2
3
4
var result = $AI.Complete({
    Messages: [{ Role: 'user', Content: 'Return JSON with a summary of this request: ' + requestText }]
});
var summary = result.ToJson().summary;

Example

1
2
3
var result = $AI.Complete({ Messages: [{ Role: 'user', Content: 'Generate the requested file.' }] });
var file = result.Files[0];
var fileRecord = $Files.AddBase64(file.ToBase64(), file.FileName || 'output', file.MimeType);

Example

1
2
3
4
5
6
7
8
var result = $AI.Complete({
    Messages: [{
        Role: 'user',
        Content: 'Extract invoice text and number. Return JSON with text and invoiceNumber.',
        Attachments: [{ MimeType: 'application/pdf', DataBase64: documentBase64, FileName: 'invoice.pdf' }]
    }]
});
var text = result.ToJson().text;

See Also