Skip to main content
POST
/
{path}
POST /{path}
curl --request POST \
  --url https://api.example.com/{path} \
  --header 'Authorization: Bearer <token>'

POST /

Send a message to an agent deployed via launch().

Endpoint

POST /{path}
Where {path} is the path specified when calling agent.launch(path="/your-path").

Description

This endpoint accepts a message and returns the agent’s response. The path is configurable when launching the agent.

Request

Headers

HeaderValueRequired
Content-Typeapplication/jsonYes
X-API-Keyyour-api-keyIf configured

Body

{
  "message": "What is artificial intelligence?"
}

Request Fields

FieldTypeRequiredDescription
messagestringYesThe message to send to the agent

Response

Success Response (200 OK)

{
  "response": "Artificial intelligence (AI) is a branch of computer science that focuses on creating intelligent machines that can perform tasks that typically require human intelligence..."
}

Response Fields

FieldTypeDescription
responsestringThe agent’s response

Example

Starting the Server

from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are a helpful AI assistant."
)

agent.launch(path="/ask", port=8000)

cURL

curl -X POST http://localhost:8000/ask \
  -H "Content-Type: application/json" \
  -d '{"message": "What is AI?"}'

Python

import requests

response = requests.post(
    "http://localhost:8000/ask",
    json={"message": "What is AI?"}
)

print(response.json()["response"])

JavaScript

const response = await fetch("http://localhost:8000/ask", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ message: "What is AI?" }),
});

const data = await response.json();
console.log(data.response);

Multiple Agents

Deploy multiple agents on the same server:
weather_agent.launch(path="/weather", port=8000)
stock_agent.launch(path="/stock", port=8000)
Then access each at their respective paths:
curl -X POST http://localhost:8000/weather -d '{"message": "Weather in NYC?"}'
curl -X POST http://localhost:8000/stock -d '{"message": "AAPL price?"}'

Error Responses

StatusDescription
400Bad request - missing or invalid message
401Unauthorized - invalid API key
500Internal server error

Error Response Format

{
  "detail": "Error message describing the issue"
}

See Also