Documentation

Classify

  • POSTClassify pages
Classify
View .mdOpenAPI

Classify pages

POSThttps://weights.fyi/run/v1/classifyscope: submit
text
POST https://weights.fyi/run/v1/classify[?model=<model>]
Authorization: Bearer <token>                    scope: submit
Content-Type: application/json
[Idempotency-Key: <your key>]
[Prefer: respond-async]
[traceparent: <W3C trace context>]
{"model": "<model>", "pages": ["<text>" | {"text": "<text>", "id": "<your id>"} | {<fetched page>}, ...],
 ["options": {"rejectIfBusy": false, "waitCold": false}], ["jurisdictions": ["EU"]], ["retain": "none"],
 ["version_id": "<version>"], ["calibration_sha256": "<64 hex>"]}
Available since
2026-10-08, when the service went live on weights.fyi/run. Running your own fine-tuned ft_… model through it is not available yet (Bring your own model).
Answer time
Results within 300 s when ready (200); otherwise an immediate queued job (202) with Retry-After.

Classifies up to 256 pages. A ready model answers 200 with every result, the job id and cost. If it is stopped, starting, stopping, moving, becomes unready during the wait, or exceeds 300 s, you receive 202 with the job, model state and Retry-After. Work continues; a stopped model starts automatically. Poll GET /v1/jobs/{job_id} for results. Prefer: respond-async answers 202 after admission even when ready.

Two kinds of model answer this call. laya-page-role, the default, is the five-label page classifier and takes page text, as above. A specialist your catalog lists with classify among its operations takes fetched pages, is answered in the call by its own pool with no job queued, and returns its own result; fetched pages sent to laya-page-role reach a specialist of that id where your workspace has one. Retry-After is the time until the model is expected ready, else the job's expected finish, else 144 s; in the readiness run of 2026-10-09 a call to the sleeping model had its result 160.4 s later. Admission is that of POST /v1/jobs; a move is told in Jobs, progress and results.

Request

NameWhereRequiredMeaning
AuthorizationheaderyesBearer and your token. The token needs the submit scope, and the call counts against the token's request rate.
Content-Typeheaderyesapplication/json. The body is read whole and may be at most 16 MiB.
Idempotency-KeyheadernoAny string you choose, one per piece of work. A retry with the same key returns the first answer, marked Idempotent-Replayed: true, and makes no second job.
Preferheadernorespond-async returns the admitted job immediately instead of waiting for results.
traceparent, tracestateheadernoA W3C trace context. When it is valid, the job and its work join your trace; when it is not, it is ignored and Weights-Notice says so.
pagesbodyyes1 to 256 pages, all of one kind. Text: a string, or an object with text and an optional id (a string or a whole number); each non-empty once trimmed and fitting one call to the model, 16 MiB with its envelope. Fetched: an object with url and final_url (http or https), http_status, content_type, sha256 (of the fetched bytes, 64 lowercase hex, checked) and body_b64 (those bytes, base64), plus an optional id: for a specialist that reads the page as it was fetched.
modelbody or querynoThe model to run: laya-page-role by default, or any model your catalog lists with classify among its operations (GET /v1/models). If you name it in both places, they must agree.
options.rejectIfBusybodynotrue to be refused with 429 overloaded when the model is not ready or every call slot is taken, instead of the 202 and a queued job; false, the default, keeps today's behaviour. The name and the behaviour follow Cloudflare's Workers AI.
options.waitColdbodynotrue keeps waiting for the results while the model starts, within the same 300 s, instead of answering 202 at once. Also ?wait_cold=true or the header X-Weights-Wait-Cold: true.
jurisdictionsbody, or header X-Weights-JurisdictionsnoCountry codes, EU or EEA, as a list or comma-separated: the call runs only where the model's known location is inside them. The body can narrow the header, never widen it.
retainbody, ?retain=none, or header X-Weights-Retainnonone, the only value: zero retention, no copy of the answer is kept. The call must then be answered in the call, so not with Prefer: respond-async or a schedule, and only by a specialist pool that answers at once. A retry with the same Idempotency-Key answers 409 replay_not_retained with the first answer's SHA-256, never the answer itself.
version_id, calibration_sha256bodynoPin a registered version of the model, and its calibration's digest (64 lowercase hex). The version must have a bundle the service executes; its results carry both values.
encrypted_envelopebodyin a confidential workspaceThe sealed request (POST /v1/workspaces); a plain call there answers 400 encrypted_envelope_required.

Return value

200 OK when the model was ready and every page finished within the wait.

FieldMeaning
job_idThe job's identifier, job_ followed by 24 hexadecimal characters.
statusThe job's final status: SUCCEEDED when every page has a result, FAILED when every page failed.
modelThe model that classified the pages.
traceparentThe job's trace context, also sent as a header.
resultsOne result per page, in the order you sent them, each as below.
costThe job's cost so far: usd_micros, the amount in micro-dollars; final, true once the job has ended (its pages are charged as their results land); basis, one sentence on how it is counted; pages_counted and prices; and runs, the runs of the model the job was served in, each with started_at, ended_at (null while the run goes on), usd_micros and final.

Each result:

FieldMeaning
seqThe page's number in the job, from 1, in the order you sent the pages.
idYour own id for the page, as text, or null if you sent none.
input_shaThe SHA-256 of the page's UTF-8 text, in hexadecimal.
input_shaFor a fetched page, the SHA-256 of the fetched bytes.
labelThe page's role: detail, listing, landing, not_vacancy or unresolved. A specialist or a registered version answers its own labels here, or null when it gives none.
probabilitiesThe model's calibrated probability for each of its labels, or null.
version_id, calibration_sha256From a registered version only: the version that classified the page, and its calibration's digest.
resultFrom a specialist or a registered version only: its own answer for the page, an object whose fields are that model's (labels for a classifier, extracted fields for an extractor). A page it could not read is failed, error unresolved, with {"unresolved": "<reason>"}.
statusdone for a page with a result; failed for a page the model could not classify.
errorThe reason a page failed, as a code, or null.

A specialist pool's 200 has no job: status, model, request_id, results, and the charged tokens as usage.

202 Accepted when the results are not in the answer.

FieldMeaning
job_idThe job's identifier; the Location header holds its path.
statusQUEUED or RUNNING.
modelThe model the job runs.
traceparentThe job's trace context.
model_stateThe model's state: state, one of the codes of GET /v1/endpoint, and expected_ready_seconds, the estimate until it is ready. it also carries since, message (the state in a sentence), queued_work_preserved and recovery_action, as GET /v1/endpoint does.
retry_after_secondsThe same figure as the Retry-After header: how long to wait before you read the job.

Errors

StatusCodeWhen it happensWhat to do
400invalid_json, invalid_bodyThe body is not JSON, or not an object with a pages list.Send {"pages": [...]}.
400empty_page, invalid_text, invalid_idA page is empty or unreadable, or its id is neither a string nor a whole number; index says which, from 0.Fix the page.
400page_too_largeOne page does not fit a call to the model.Shorten it.
400no_pages, too_many_pagesNo page at all, or more than max.Send 1 to 256 pages; use POST /v1/jobs for more.
400model_not_available, model_conflictA model you cannot run (available lists those you can), or two different models named.Name one model your catalog lists, once.
400invalid_bodyText pages sent to a specialist that reads fetched pages only; expected shows the fetched shape.Send fetched pages.
400invalid_jurisdictionsjurisdictions is not a list of country codes, EU or EEA.Fix the list.
400invalid_retain, retain_none_requires_syncretain is not none, or it came with Prefer: respond-async or a schedule.Send none, and wait for the answer.
400encrypted_envelope_requiredA plain call from a confidential workspace.Send the sealed request.
409jurisdiction_refusedNo eligible capacity has a known location inside jurisdictions.Widen them, or wait.
409retain_none_unavailableZero retention was asked of the five-label classifier or of a registered version's bundle, which both keep results.Use a specialist pool that answers in the call, or drop retain.
409replay_not_retainedA retry of a zero-retention call; response_sha256 is the first answer's digest.Keep the first answer yourself.
409version_not_executable, bundle_not_executableThe pinned version has no bundle the service can execute.Pin another version, or none.
401unauthorized, invalid_token, token_revoked, token_expiredNo token, or one that does not work (any more).Use a valid token.
402no_creditYour available credit is zero or less.Add credit.
503price_unavailableA price cannot be set right now; nothing was admitted or charged.Send again after Retry-After.
402queue_exceeds_creditThe pages, with your pages already waiting, cost more than your available credit; pages_allowed says how many it pays for.Send fewer pages, or add credit.
402token_daily_capThe token's spend cap for the UTC day would be passed; resets_at says when it resets.Wait, or raise the cap on your panel.
403scope_required, account_suspendedThe token lacks submit, or the account is suspended.Use a token with submit.
409idempotency_key_in_progressA request with this key is still running.Wait for it, then send again with the same key.
413body_too_largeThe body is larger than limit_bytes.Send fewer or shorter pages.
422idempotency_key_reusedThe key was used for a different request.Use a new key.
429rate_limitedThe token sends work faster than its request rate.Wait Retry-After seconds and send again with the same key.
429overloadedThe service holds as much unfinished work as it takes (reason: queue_full, or concurrency_limit for single calls), or you sent rejectIfBusy and the model is not ready (capacity_unavailable, with the model's state in recovery) or busy (concurrency_limit). Nothing was accepted.Wait Retry-After seconds and send again.
400invalid_optionsoptions.rejectIfBusy or options.waitCold is not true or false.Send booleans.
500internal_errorA fault on our side.See Errors and limits.

Examples

Two pages while the model is ready:

sh
curl -s -i https://weights.fyi/run/v1/classify \
  -H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: first-call-2" \
  -d '{"model": "laya-page-role", "pages": [{"text": "Senior data engineer, Utrecht. Apply today.", "id": "p1"}, "All open positions: 24 results. Filter by city or team."]}'
text
HTTP/1.1 200 OK
Content-Type: application/json
traceparent: 00-bab95d936f1061465864482cc2494dce-1c86517d7012893b-01

{
  "job_id": "job_a9f211eac4050afa06474fa0",
  "status": "SUCCEEDED",
  "model": "laya-page-role",
  "traceparent": "00-bab95d936f1061465864482cc2494dce-1c86517d7012893b-01",
  "results": [
    {
      "seq": 1,
      "id": "p1",
      "input_sha": "0e9d03893cf9b487b46c69b99a496bc5859890f184509f4a97d5cc1f3bb3cb8f",
      "label": "detail",
      "probabilities": {"detail": 0.912, "listing": 0.041, "landing": 0.022, "not_vacancy": 0.019, "unresolved": 0.006},
      "status": "done",
      "error": null
    },
    {
      "seq": 2,
      "id": null,
      "input_sha": "831b6f101815b4590022ea3ffed074ed5af35cfca7ecf93dda70861e50e913e4",
      "label": "listing",
      "probabilities": {"detail": 0.027, "listing": 0.893, "landing": 0.061, "not_vacancy": 0.011, "unresolved": 0.008},
      "status": "done",
      "error": null
    }
  ],
  "cost": {
    "usd_micros": 7,
    "final": true,
    "basis": "the sum of the job's charges so far, each posted as its results landed, at the prices it was admitted at",
    "prices": {"usd_per_1m_pages": 2.288525},
    "pages_counted": 3,
    "runs": [
      {"started_at": "2026-10-09T08:28:09.790Z", "ended_at": null, "usd_micros": 7, "final": false}
    ]
  }
}

Patterns

Handling both answers

On 200, take the results; on 202, wait Retry-After, then poll the job no faster than every 5 s and read its results once final. For a burst, start the model with POST /v1/endpoint/warm and keep calling; each page renews its 144 s ready.

History

  • 2026-10-08: live: results in the answer while ready, 202 with Retry-After otherwise, Idempotency-Key, traceparent; runs in the cost.
  • 2026-10-08: Retry-After uses the median start of hardware that served the model before (the first live run said 440 s for a 132 s start).
  • 2026-10-10 implementation review: rejectIfBusy, 429 overloaded, model_state with since, message, queued_work_preserved and recovery_action, recovered retries.
  • 2026-11-16: fetched pages, waitCold, jurisdictions, retain and version pins documented.

See also

POST /v1/jobs, GET /v1/jobs/{job_id}/results, Classify pages, Errors and limits.