Docly Developers
Function API only Updated 22 Oct 2026

promptAI(model, messages)

Sends a conversation to one of Docly's AI models and returns the reply.

Requires AI to be enabled on the workspace's subscription (otherwise error 1, "AI features are not enabled on your subscription"). The call runs as the user who published the site, and the usage is logged on that user.

See also getAIModels

Parameters

modelstringrequired

Model id, from getAIModels. An id that does not exist falls back to the default model. A beta model is refused unless the publisher is an administrator.

messagesarrayrequired

The conversation: an array of { role, content }, where role is "user" or "assistant" and content is the text.

Returns

An object with the reply: Content is the reply text, and InputTokens, OutputTokens and Cost show what the call used.

The call waits for the reply. If no reply arrives within the script's execution timeout, promptAI throws (error 1).

Throws if model or messages is missing (error 0). An error from the AI provider is thrown by the promptAI call itself (error 1).

Example

Normal JavaScript, running in the browser or on the Docly™ server.
export default (text) => {
    let modelId = "...";   // an Id from docly.getAIModels()

    let result = docly.promptAI(modelId, [
        { role: "user", content: "Summarize in one sentence: " + text }
    ]);

    return { answer: result.Content };
}