Skip to main content
All symbols live in the managed-package namespace lai. These are global symbols: signatures are permanent and only ever added to, never changed — so code you write against them keeps working across package upgrades.

LogicAI methods

register

Id register(String source, String model)
Registers a source (a caller) and returns its registration id. Call this once at setup, store the id, and reuse it — not before every invoke. Idempotent: calling again with the same source returns the same id.
Id regId = lai.LogicAI.register('NightlySync', 'claude-sonnet-4-6');
  • source — a stable, short identifier for the caller, e.g. 'NightlySync'. Required.
  • model — the AI model this source runs on. Must be a catalogued gateway model; leave blank to use the org default model.
  • Throws LogicAI.LogicAIException if the source is blank or the model isn’t recognised.
There’s also a convenience overload register(String source) that registers on the org default model. See Source Registration for the full picture.

invoke

LogicAISchema.Response invoke(LogicAISchema.Request request)
Synchronous single round-trip. Does the gateway callout inline and returns the response.
lai.LogicAISchema.Request req = new lai.LogicAISchema.Request('Draft a follow-up email.');
req.registrationId = regId;
lai.LogicAISchema.Response res = lai.LogicAI.invoke(req);
Does not throw for gateway, credit, or validation failures — inspect res.success / res.statusCode / res.error instead. Must be called from a context that permits synchronous callouts (Queueable, @future, controller action, anonymous Apex).

invokeJson

String invokeJson(LogicAISchema.Request request)
Same as invoke, but returns the Response serialised to JSON. Handy for handing a single string to a Flow text variable.
String json = lai.LogicAI.invokeJson(req);

invokeAsync

Id invokeAsync(LogicAISchema.Request request)
Asynchronous variant for contexts where a synchronous callout isn’t allowed — Flows, triggers, after-DML. Enqueues a Queueable that performs the gateway call off-transaction, and returns immediately.
Id sessionId = lai.LogicAI.invokeAsync(req);
  • A session is never created here. Pass a sessionId on the request to have the reply persisted onto that Bot_Session__c (poll its Bot_Message__c rows for the result); the returned Id is that same session id.
  • With no sessionId, the call is fire-and-forget — it runs but the reply isn’t persisted, and the method returns null.
  • Unlike invoke, invokeAsync validates up front and will throw LogicAI.LogicAIException for a bad request or an unregistered/disabled source, so the caller fails fast on their own transaction rather than silently in the async job.

LogicAISchema.Request fields

Construct with new lai.LogicAISchema.Request() or new lai.LogicAISchema.Request(prompt).
FieldTypeRequiredNotes
registrationIdIdYesThe id returned by LogicAI.register(...). Identifies the source that supplies the model and attribution. The API will not run without it.
promptStringYes*The user’s prompt / instruction. *Required unless you supply contentBlocks.
sessionIdIdNoContinue an existing Bot_Session__c conversation. When null, the call is a stateless one-shot.
systemPromptStringNoSystem-prompt override. When blank, a minimal default is used — the full chat system prompt is intentionally not applied here.
contentBlocksList<Object>NoStructured content blocks for the user message — required for anything other than plain text (PDFs, images). See below.
Deprecated fields: model and agent are no longer honoured — the model and attribution now come from the registered source. They remain on the class only for binary compatibility; any value you set is ignored. Pass the model to register(...) instead.

Content blocks (files)

To send a PDF or image, populate contentBlocks with Anthropic content-block maps. When set, prompt is appended as a trailing text block unless one is already at the end of the list.
lai.LogicAISchema.Request req = new lai.LogicAISchema.Request();
req.registrationId = regId;
req.prompt = 'Summarise this document.';
req.contentBlocks = new List<Object>{
    new Map<String, Object>{
        'type' => 'document',
        'source' => new Map<String, Object>{
            'type' => 'base64',
            'media_type' => 'application/pdf',
            'data' => EncodingUtil.base64Encode(pdfBlob)
        }
    }
};
lai.LogicAISchema.Response res = lai.LogicAI.invoke(req);
Images use 'type' => 'image' with a media_type like image/jpeg.

LogicAISchema.Response fields

FieldTypeNotes
successBooleantrue when the call succeeded; false when error is populated.
statusCodeIntegerHTTP-style code — see Errors & Status Codes.
textStringThe assistant’s text reply.
sessionIdIdThe session used. Null for a stateless one-shot.
inputTokensIntegerInput tokens consumed.
outputTokensIntegerOutput tokens produced.
creditsDecimalCredits consumed by this call (gateway-reported).
errorStringHuman-readable message when success == false.
Response also exposes toJson(), which serialises it to pretty-printed JSON (this is what invokeJson returns).

Governor-limit notes

  • Each invoke performs one HTTP callout. It counts against the standard 100-callouts-per-transaction limit.
  • invoke must run where callouts are allowed. In synchronous trigger/Flow contexts, use invokeAsync.
  • Callout timeouts are set generously (120s) because model responses can take time — size your transactions accordingly.