Wait for the rewrite.
Poll the run if you only need the finished text. Open the event stream if you want the charge while the run is still going.
Polling
GET /v1/runs/{id} is the reliable way for a script. Stop when status is succeeded, rejected, failed, or canceled. A couple of seconds between requests is enough.
/v1/runs/{id}/events
A server-sent event stream. The URL is the events_url from the create response, on https://humanizeword.com. The stream replays events you missed, then stays open until the run finishes. Comment lines that say ping keep the connection alive.
curl -N https://humanizeword.com/api/v1/runs/run_01J9ABCDEF/events \
-H "Authorization: Bearer $HUMANIZEWORD_API_KEY"
event: cost
data: {"type":"cost","projected_charge_usd":"0.050000"}
event: done
data: {"type":"done","status":"succeeded","charged_usd":"0.050000","reasons":[]}
Frames to handle
| Event | Use it for |
|---|---|
cost | projected_charge_usd is the charge so far, in USD. It can move during the run. It is still an estimate until done. |
done | The stream ends. status matches the run. charged_usd is the settled charge. reasons lists why a run was rejected or stopped. |
Other event types can appear while the run is working. Ignore any type you do not recognize. After done, read GET /v1/runs/{id} for output_text. The stream does not include the rewrite.
EventSource cannot set Authorization.
Use it from the signed-in app, which already has a session cookie. From a script, use an HTTP client that can send the bearer token, or poll the run.