How to call the ClearRun API from Python
Use requests (or any HTTP client) to POST to https://api.clearrun.net/api/score or /api/evaluate with your key in the Authorization header. There is no Python package to install.
Last updated
Steps
Install requests
pip install requestsScore an answer
import os, requests API = "https://api.clearrun.net" headers = {"Authorization": f"Bearer {os.environ['CLEARRUN_API_KEY']}"} res = requests.post( f"{API}/api/evaluate", headers=headers, json={ "prompt": "When was the Eiffel Tower finished?", "responseText": "It was definitely finished in 1925, everyone agrees.", }, timeout=30, ) if res.status_code == 429: print("wait", res.headers.get("Retry-After"), "seconds") res.raise_for_status() body = res.json() print(body["verdict"]["score"], body["verdict"]["verdictId"])Look up a verdict later
r = requests.get(f"{API}/api/verify/{verdict_id}", timeout=30) print(r.json()["verified"])No key needed.