Skip to main content
POST
Invoke Sofia AI
Sofia AI is built on the Agent Graph infrastructure. Invoking it uses the standard Agent Graph invoke endpoint — the only Sofia-specific value you supply is the agentId (your agent_descriptor_id) that Connectly provides during onboarding.
To set up Sofia AI for production, contact your Connectly Account Manager. They will configure your knowledge base and product catalog, then provide your agent_descriptor_id, business_id, and api_key.

Endpoint

Authentication

Use the Sofia-specific API key provided by Connectly — not your general Connectly API key. Pass it in the x-api-key header (lowercase).
Your Sofia api_key is scoped to inference only and is safe to use in client-side JavaScript — it cannot send WhatsApp messages or access campaign data.

Session lifecycle

Every Sofia AI conversation follows the standard Agent Graph three-step lifecycle:
1

Init

Call POST /agent_graph/init with your businessId and clientKey to receive a sessionId.
2

Invoke

Call this endpoint with the sessionId and your inputEvents to send a customer message and receive the agent’s reply.
3

Close

Call POST /agent_graph/close with the sessionId when the conversation ends.

Request body

string
required
The business_id provided by Connectly for your Sofia AI integration.
string
required
A unique identifier for the customer. Use a stable ID from your system so you can correlate sessions with users.
string
required
The session ID returned by the init endpoint.
string
Your agent_descriptor_id — provided by Connectly during onboarding. Identifies the Sofia agent configuration to use.
array
required
The events to send to the agent. For a standard text interaction, include a single messageEvent with the customer’s text.For the full list of supported event types — button responses, list replies, form submissions, store events — see Invoke (stream).

Response

The response is an NDJSON stream — one JSON object per line, each representing one agent response event.
Do not call response.json() on the raw response — it will throw a parse error. Parse each line individually. See NDJSON streaming for a complete guide.

Full example (Python)


NDJSON streaming

How to correctly parse the streaming response body.

Invoke (stream) reference

Full parameter docs including all input and response event types.