AIP
API quickstart
Create an AIP key, call a saved Agent, read replies, and access authorized business resources.
Call a saved AIP Agent from your server and read its conversation results. Manage API keys in the AIP workbench; REST and MCP share the same keys and permissions. See the API reference for endpoint details.
Prepare the URL and key
- Select the target Profile (business identity) in AIP. Create and test an Agent, save its configuration, and enable it.
- Open Manage API keys, create a key, choose the single-Agent conversation access range, and select the Agent to call.
- Enable send messages (
agent:invoke). This includes read conversations (agent:conversations:read), which grants access to all of that Agent's historical conversations, including those created by other integrations. - Copy the full key immediately after creation. It will not be shown again.
Set these variables in your server terminal. This is the production URL; use the corresponding backend URL for development or self-hosted deployments:
export HAST_API_BASE='https://backend.hast.so/api/public/v1'
export HAST_API_KEY='<YOUR_SINGLE_AGENT_KEY>'Submit your first task
curl --fail-with-body --request POST \
--url "$HAST_API_BASE/agent/prompts" \
--header "Authorization: Bearer $HAST_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"request_id":"message-001","prompt":"Describe your role and the work you can help me complete."}'The request uses the Agent bound to the key and its saved configuration. Omit session_id to create a conversation; include the returned session_id to continue it. Use a new request_id for each new message, and keep the identifier and request content unchanged when retrying that message.
HTTP 202 means the request was accepted. Save the returned session_id and request_id, then read events to determine the outcome of this run.
Read execution progress
export SESSION_ID='<SESSION_ID_FROM_RESPONSE>'
curl --fail-with-body \
"$HAST_API_BASE/agent/sessions/$SESSION_ID/events?after=0&limit=100" \
--header "Authorization: Bearer $HAST_API_KEY"The response contains events, next_after, and has_more. Pass next_after as after on the next request. Keep paging while has_more is true, even if a page contains no visible events. When no new events are available, wait before polling again.
This endpoint returns user messages, Agent replies, and run status. Wait for run.completed, run.failed, or run.interrupted whose run_id matches the receipt's request_id. A message.completed event only completes one message. See conversation events and SSE for details.
Single-Agent conversations use JSON polling and have no SSE route. Use GET /agent/sessions to find the Agent's historical conversations and read their events.
Use a Profile API key
To access resources belonging to the current business identity, create a Profile API key in Manage API keys and grant the required permissions:
| Purpose | Permission and endpoint |
|---|---|
| Read saved Agent configurations | webhooks:read, GET /webhooks |
| Invoke a specific Agent | webhooks:write, POST /webhooks/{hook_id}/invoke |
| Manage knowledge bases, channels, CRM, or schedules | Corresponding resource permissions; see the API reference |
| Submit an ordinary task and read events | prompts:write and sessions:read, POST /prompts and /sessions/{id}/events |
Write permissions include the corresponding read permission. A Profile key's /prompts endpoint creates ordinary task sessions without automatically applying a saved AIP Agent configuration. To call a configured Agent, use /webhooks/{hook_id}/invoke or the single-Agent flow above.
Ordinary tasks support SSE at /sessions/{id}/events/stream; see SSE integration. Profile keys and single-Agent keys have different endpoint access: /agent/* and ordinary task paths are not interchangeable.
Continue integration
See the API reference for parameters, responses, and OpenAPI JSON. For external Agent clients, use MCP integration. To call the full Hook URL from an Agent's details page, use Webhook HTTP integration.