How to call ClearRun chat with POST /api/chat
Send POST /api/chat with { "message": "Is it safe to leave cooked rice out overnight?" }. ClearRun writes an answer, scores it, and returns responseText, verdict, receipt and a sessionId. A chat turn costs at most 4 credits.
Last updated
Steps
Send a message
curl -s https://api.clearrun.net/api/chat \ -H "Authorization: Bearer $CLEARRUN_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "message": "Is it safe to store API keys in a .env file?" }'Read the reply
responseTextis the answer.verdictscores it. KeepsessionIdto continue.
Request fields
| Field | Required | Notes |
|---|---|---|
message | Yes | 10 to 100,000 characters, the same limits as score and evaluate |
sessionId | No | From an earlier reply, to continue |
context | No | Earlier turns as [{ "role": "user", "content": "What does ClearRun score?" }] |
workspaceId | No | Which workspace's receipt chain to use |
Response fields
sessionId, messageId, executionId, responseText (also as response), verdict, receipt and model.
Errors
- 400
Message required - 400
Message is too short to score(CONTENT_TOO_SHORT) under 10 characters - 400
Message too long(CONTENT_TOO_LONG, withmaxLengthandactualLength) over 100,000 - 400
Request blocked(ACTION_NOT_ALLOWED) - 400
Content blocked(CONTENT_BLOCKED), the same on score, evaluate and chat. See Why am I getting 400 'Request blocked'? - 404
Session not found: thesessionIdis not yours - 402, 403, 429 as on every scored route