HTTP API
Anything that can send an HTTP POST can log a run. Full reference: app.modgrad.com/api/v1; one screen for agents: app.modgrad.com/llms.txt.
$MODGRAD_TOKEN below is a project token from the quickstart.
Bodies are read as JSON whatever the Content-Type, so plain curl -d works.
Log metrics
curl -X POST https://app.modgrad.com/api/v1/runs/my-run/log \
-H "Authorization: Bearer $MODGRAD_TOKEN" -d '{"step": 10, "loss": 0.52}'
The first write creates the run. An id without / goes in the token’s project:
my-run becomes <project>/my-run.
A body is one of:
- one row:
{"step": 10, "loss": 0.52, "acc": "71.5%"} - many rows: a JSON array, or NDJSON (one object per line)
- an envelope:
{"rows": [...], "events": ["checkpoint saved"], "config": {"lr": 3e-4}, "summary": {"best_loss": 0.4}, "finish": true}
Row rules:
stepis optional (default: one past the last step)._stepworks too.- Values are numbers or numeric strings (
"3.4","7.5%","1e-3").null,"nan"and"inf"are stored as gaps;true/falseas 1/0. Units are dropped:"7.5%"is stored as 7.5. - Nested objects are flattened with
/:{"train": {"loss": 1}}istrain/loss. {"histogram": {"edges": [...], "counts": [...]}}and{"tensor": {"shape": [...], "data": [...]}}are stored as arrays.- Other text values are skipped and listed under
ignored.
Re-sending a row is harmless: reads merge by step, last write wins per (step, key).
Finish a run
curl -X POST https://app.modgrad.com/api/v1/runs/my-run/finish \
-H "Authorization: Bearer $MODGRAD_TOKEN"
Until then it shows as running. "finish": true in a log envelope or ?finish=1
on /text also finish it. An optional body is merged into the summary, e.g.
{"exit_code": 0}.
Log raw text
POST /api/v1/runs/<id>/text takes a script’s stdout as is. Each line is parsed
for metrics: step 1250: loss 3.48 acc 7.5%,
iter 100 | loss=2.31 | lr 3e-4, [epoch 2/10] train_loss: 0.45, tqdm postfixes,
{'loss': 0.4} dicts. Printed names become lower-case keys (Train Loss becomes
train_loss). ?events=unparsed also keeps the lines without metrics as events.
Print the step on every metric line. To stream, post new whole lines every few seconds; pipe.py, a stdlib Python script, does it for you:
curl -s https://app.modgrad.com/pipe.py -o modgrad_pipe.py
export MODGRAD_TOKEN=<token>
python3 modgrad_pipe.py my-run -- python -u train.py
It echoes every line, records the exit code in the summary and finishes the run. A failed send is retried and never stops training. The SSH pipe does the same with nothing to download.
Text samples
POST /api/v1/runs/<id>/samples stores generations for SFT, RL or evals:
{"step": 1200, "key": "eval/gsm8k", "prompt": "...", "completion": "...", "reward": 0.73}
Log the same prompts at every eval step to see each prompt’s completions change over training.
Files
PUT /api/v1/runs/<id>/files/<path> stores a file with an existing run; GET
downloads it. Plain relative names only.
Read
Public projects need no token. Private ones need the owner’s session or a project token.
| request | returns |
|---|---|
GET /api/index?project=<p> |
the run list |
GET /api/v1/runs/<id>/history?keys=a,b |
{"steps", "t", "columns": {key: [...]}} |
GET /api/v1/runs/<id>/config, /summary, /events |
those parts of the run |
GET /api/v1/runs/<id>/samples |
stored samples |
GET /api/v1/stream?project=<p> |
live updates (Server-Sent Events) for a project |
GET /api/v1/runs/<id>/stream |
live updates for one run |
Names the dashboard understands
layers/<i>/<stat>(e.g.layers/0/grad_norm) is drawn as a layer × step heatmap.eval/<benchmark>/<metric>(e.g.eval/gsm8k/acc) goes in the evals table.loss,grad_norm,lr,tokens_seen,reward,kl,entropyandresponse_lengthmake up the default board.
Errors
Errors are JSON {"error", "example", "help", "message"}: what was wrong, a
corrected request, and both as one paragraph.
| status | meaning |
|---|---|
| 400 | bad body |
| 401 | missing, unknown or expired token |
| 403 | token does not cover this run |
| 409 | the run has its own run token |
| 413 | body or storage limit |
| 429 | too many MCP calls at once |
| 503, 504 | overloaded: retry |
| 507 | server short of disk: retry after Retry-After |