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

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.
  • 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

Synchronous single round-trip. Does the gateway callout inline and returns the response.
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

Same as invoke, but returns the Response serialised to JSON. Handy for handing a single string to a Flow text variable.

invokeAsync

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.
  • 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).
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.
Images use 'type' => 'image' with a media_type like image/jpeg.

LogicAISchema.Response fields

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.