Skip to content

Python SDK

The nuacemone package wraps the Conversations API and the Workflows API for servers. It needs Python 3.9 or later and uses only the standard library.

The package is not published on PyPI. Ask your NuacemOne contact for the nuacemone package, then install it with pip install and the path of the file you receive.

Use a secret key (vcx_sk_). The Python SDK is for servers; never ship a secret key to a browser or a mobile app.

import os
from nuacemone import NuacemOne, NuacemOneError
client = NuacemOne(
key=os.environ["NUACEMONE_SECRET_KEY"],
gateway="https://api.nuacem.dev/voice-gw", # chats
workflows="https://api.nuacem.dev/workflow-api", # workflows
)

timeout (seconds, default 60) sets the timeout for each request.

The client has client.agents, client.use_cases and client.workflows.

with client.agents.chat("agt_xxxx", user_id="cust-42") as chat: # or client.use_cases.chat("uc_xxxx")
print(chat.greeting)
reply = chat.send("When is my EMI due?", on_delta=lambda so_far, piece: print(piece, end="", flush=True))
print(reply.text)
chat.feedback(5)

The with block starts the chat and ends it when the block exits. Without with, call chat.start() (or just send()) and chat.end() yourself.

Options for chat(id, ...): language, user_id, user_hash, visitor_id and profile. With a secret key, user_id alone names the user.

Method What it does
start() Starts the chat, or returns the open Session.
send(text, on_delta=None, file_ids=None, reply_to=None) Sends a message and returns a Reply (text, block, block_text). on_delta(text_so_far, piece) is called as the reply streams.
upload_file(data, name=None) Uploads a file. See Files.
tap(block_id, value, label="") Sends a tap on a rich block’s option.
feedback(rating, comment=None) Rates the chat 1 to 5.
end() Ends the chat. Safe to call twice.

A Chat is not thread-safe: send one message at a time. After session_not_found (the chat ended or expired), the next send() starts a new chat.

uploaded = chat.upload_file("statement.pdf") # a path, or bytes: chat.upload_file(data, "statement.pdf")
if uploaded.status == "blocked":
print(uploaded.message) # safe to show; do not send this file
else:
reply = chat.send("Summarise this statement", file_ids=[uploaded.file_id])

upload_file returns an UploadedFile with file_id, name, kind, size_bytes, status, code, message, pages, truncated, files_left and accepted. A blocked file is not an error. See Files for types and limits.

A reply may carry reply.block (a dict with type and id) and reply.block_text. reply.text is always the full reply. Send a tap with chat.tap(block_id, value, label).

The Workflows API is in beta and must be switched on for your organisation. Use a secret key with no agent limit.

wf = client.workflows
run = wf.start("flw_xxxx", input={"appointmentId": "A-1042"}, correlation={"patientRef": "P-77"})
print(wf.get_run(run.id).status_label)
result = wf.send_event("doctor.cancelled", event_id="hosp-evt-981",
correlation={"doctorId": "D-12"}, data={"doctorId": "D-12", "date": "2026-11-20"})
print(result.started, result.woken)
for task in wf.tasks(status="OPEN"):
wf.decide_task(task["id"], "approved", note="Checked in the hospital system")
wf.cancel_run(run.id)
Method API call
start(workflow_id, input=, correlation=, trigger_id=) POST /public/v1/workflows/{workflowId}/runs
get_run(run_id) GET /public/v1/runs/{runId}
cancel_run(run_id) POST /public/v1/runs/{runId}/cancel
send_event(event_name, event_id=, correlation=, data=) POST /public/v1/events
tasks(run_id=, status=) GET /public/v1/tasks
decide_task(task_id, outcome, note=, data=) POST /public/v1/tasks/{taskId}/decide

start, get_run and cancel_run return a WorkflowRun (id, workflow_id, status, status_label, outcome, and so on; output and deduplicated after start). send_event returns an EventResult. Tasks are plain dicts with the API’s field names.

You can also use the workflows client on its own: Workflows(key=..., base_url="https://api.nuacem.dev/workflow-api").

import json
import os
import httpx
from nuacemone import signed_headers, verify_webhook
# Check a webhook NuacemOne sent you: the RAW body and two headers.
ok = verify_webhook(os.environ["NUACEMONE_WEBHOOK_SECRET"], raw_body,
headers["X-VoiceCX-Timestamp"], headers["X-VoiceCX-Signature"])
# Sign a call to a signed workflow hook with the workspace's inbound secret.
body = json.dumps({"input": {"appointmentId": "A-1042"}}).encode()
httpx.post(hook_url, content=body, headers=signed_headers(os.environ["NUACEMONE_INBOUND_SECRET"], body))

verify_webhook rejects timestamps more than 300 seconds away; pass tolerance_seconds= to change that. See Verifying signatures.

Every failure raises NuacemOneError with code, status (the HTTP status, or 0 for network errors) and message (safe to show):

try:
reply = chat.send("Hello")
except NuacemOneError as e:
if e.code == "rate_limited":
...
print(e.code, e.status, e.message)

See Errors for every code. Code written for the older voicecx package keeps working; see Older names.