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

  1. 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?" }'
  2. Read the reply

    responseText is the answer. verdict scores it. Keep sessionId to continue.

Request fields

Request fields
FieldRequiredNotes
messageYes10 to 100,000 characters, the same limits as score and evaluate
sessionIdNoFrom an earlier reply, to continue
contextNoEarlier turns as [{ "role": "user", "content": "What does ClearRun score?" }]
workspaceIdNoWhich 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, with maxLength and actualLength) 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: the sessionId is not yours
  • 402, 403, 429 as on every scored route