Astra API Quickstart
Find a published Astra agent, send your first message, and read the reply as it streams.
You’ll need an Astra API key and a published chat agent in the same Astra workspace. Run the examples in a terminal with curl. Keep your key on the server.
Using an AI client such as Claude or ChatGPT? Follow the WATI MCP connection guide to access Astra tools from your client.
1. Connect to Astra
Follow Create and manage Astra API keys to get a key. Set ASTRA_API_KEY in your shell, then call List agents on the Astra gateway.
curl -sS 'https://astra-gateway.wati.io/v1/agents?status=live' \
-H "Authorization: Bearer $ASTRA_API_KEY"Choose a published chat agent from the response and copy its id (UUID). If the list is empty, follow Build a chat agent with a knowledge base to create and publish one in this workspace.
2. Send a message
Replace the placeholder UUID below. Use a stable user_id for each end user. Omit conversation_id on the first turn.
curl -i -N 'https://astra-gateway.wati.io/v1/chat' \
-H "Authorization: Bearer $ASTRA_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"agent_id":"REPLACE_WITH_AGENT_UUID","user_id":"quickstart-user","user_query":"Hello!"}'3. Read the reply and continue
A normal generated reply arrives as server-sent events (text/event-stream) on the same request. The -N option lets curl display events as they arrive.
- For
AGENT_MESSAGE, append eachcontent_deltato the reply. Skip filler events markedfiller: truewhen assembling the final text. - At
SESSION_END, usesession.final_contentwhen present. Savesession.conversation_id. - For a follow-up, send that conversation ID as
conversation_idalongside the sameagent_idanduser_idand your newuser_query.
Check the HTTP status and content type before parsing. Some chat outcomes return JSON, including HTTP 202 when a message is appended to a turn already in progress. See the Chat endpoint for request fields.
Troubleshooting
- Authentication failed. Check that you are using an Astra API key from the agent’s workspace and that the Authorization header starts with
Bearer. - No agent to select. Check the agent’s publication status in Astra and run List agents again.
- The first reply fails to parse as JSON. Inspect the Content-Type header. Use an SSE reader for
text/event-stream.
Updated about 1 hour ago

