Skip to Content
The Ngamia platform API is in preview. Endpoints may change before general availability.
GuidesCall agents from your app

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

Never 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 -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

statusDo
completedShow output. It may end with a Sources: list; show it or strip it.
failedShow a polite fallback (“I could not answer that, a person will reply”) and log error.
runningOnly with wait: false: stream or poll.
HTTPDo
429Back off and retry later.
503Retry with exponential backoff and the same Idempotency-Key.
401 / 403The 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.