For the agent to talk to the visitors on your website, the path is always the same: the browser talks to your server, and your server talks to the API. The browser never calls the API directly. Your website's pages could not do it anyway: browsers can only call the API from our documentation.
The path of a message
| 1 |
The visitor types in the chat, and the browser sends the message to your server.
|
|
| 2 |
Your server adds the earlier messages of the conversation and calls POST /v1/chat/completions, with the key and agent/... in model.
|
|
| 3 |
The agent adds its instructions and knowledge, uses its tools if it needs them, and answers.
|
|
| 4 |
Your server sends only the text of the answer back to the browser.
|
|
What your server sends, and what it does not
| Sends |
Does not send |
| model, with agent/ and the agent id |
The instructions: the agent adds them itself |
| The conversation messages, with role user and assistant |
The knowledge: it also goes on its own |
| max_tokens, if you want shorter answers than the agent's |
The key to the browser: it stays on the server only |
| The key, in the Authorization: Bearer header |
Data the agent does not need, such as passwords or card numbers |
The request body looks like this:
{
"model": "agent/7c1e9a42-b35d8f06-a2c4e719-5d0b3f8e",
"messages": [
{ "role": "user", "content": "Do you deliver on Saturdays?" },
{ "role": "assistant", "content": "Yes, from 9 am to 1 pm." },
{ "role": "user", "content": "And how much does it cost?" }
],
"max_tokens": 400
}
Each chat request stands on its own. For the agent to know what was already said, your server sends the earlier messages with each request. More messages mean more input tokens, so send only the latest ones: the Interweb WordPress plugin, for example, sends the last 10.
Keeping the spending under control
| 1 |
Set a limit of messages per visitor and per day on your server. Each message spends credits.
|
|
| 2 |
Set max_tokens: it caps the answer and the credit reservation.
|
|
| 3 |
Use a key just for the chat, with ai:read and ai:write, and the server IP on its IP list.
|
|
| 4 |
If something goes wrong, pause the agent in All in One AI: requests then get 409 agent_paused and the agent stops answering.
|
|
With WordPress
The Interweb WordPress plugin already follows this path for you. In the Model or agent field, type agent/ and the id. The plugin's instructions are set aside, because the agent brings its own. See the AI assistant in the WordPress plugin.
|
Never put the key in your website's JavaScript or in a mobile app. Whoever finds it spends your credits. If that happens, see what to do, in the right order.
|
|
Write your program with a sandbox_ key: the agent answers "Resposta de teste (sandbox)." and spends nothing. Switch to the prod_ key when the chat is ready.
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon) See plans |