Call agents from your app
Your server calls the platform with an API key that has the runs scope,
and passes your own ID for the customer as user. Your website, mobile app or
WhatsApp bot talks to your server, never to Ngamia with a key.
customer ──► your app ──► your server ──(ngk_ key, user=customer-42)──► api.ngamia.comNever put an API key in browser JavaScript, a mobile app, a prompt or a chat message. Anyone who has it can run your agents and spend your model budget.
One message
curl
curl -s https://api.ngamia.com/v1/agents/duka-helper/runs \
-H "Authorization: Bearer $NGAMIA_KEY" -H 'content-type: application/json' \
-H 'Idempotency-Key: msg-8812' \
-d '{"input":"Do you deliver to Mbezi?","user":"customer-42"}'A conversation
Store the last run_id per customer conversation and send it as
previous_run_id with the next message, with the same user. Start a fresh
conversation by leaving it out.
Handling outcomes
status | Do |
|---|---|
completed | Show output. It may end with a Sources: list; show it or strip it. |
failed | Show a polite fallback (“I could not answer that, a person will reply”) and log error. |
running | Only with wait: false: stream or poll. |
| HTTP | Do |
|---|---|
429 | Back off and retry later. |
503 | Retry with exponential backoff and the same Idempotency-Key. |
401 / 403 | The key was revoked or lacks the runs scope. Alert your team. |
WhatsApp and chat apps
- Use the sender’s stable ID (for example the phone number hashed by your
server) as
user. - Use the provider’s message ID as
Idempotency-Key, so a redelivered webhook does not run twice. - Reply asynchronously: acknowledge the webhook, run the agent, then send the answer through your messaging provider.