Skip to main content
POST
Rate limit tier: submission, 60 requests/min. See Rate limits. Starts an optimization: a run that rewrites a workflow’s field descriptions to extract more accurately. The call is async and fire-and-forget. It returns 202 at once with the new optimization. Poll it with GET …/optimizations/{optimization_id}/ until status is done or failed. The body is discriminated on kind: A one-shot run reports no accuracy: baseline_accuracy and best_accuracy stay null. Pick it when the dataset has no ground truth yet, or when you want a quick suggestion to review.

One optimization at a time

A workflow runs one optimization at a time, of either kind. A start while another runs returns 409 OPTIMIZATION_ALREADY_RUNNING. List the workflow’s optimizations to find the running one. A run whose worker stopped for more than 100 minutes is reported failed and no longer blocks.

Credits

A measured run is billed like evals, one extraction per dataset document for the baseline and for every round. A one-shot run is billed one flat charge when it finishes done, even when it changes nothing, and nothing when it fails. For either kind, an organization with no credit gets 402 INSUFFICIENT_CREDIT and nothing starts. While a measured run evaluates a round, that round’s candidate is the workflow’s latest version, so a document run on the workflow at that moment uses it. The run ends by saving the best descriptions as the latest version. See How credits work.

Idempotency

Without an Idempotency-Key, every call starts a new optimization. Supplying the header replays instead: a retry with the same key and body returns the original optimization, with the status it had at the first call, and starts no second run. Reusing the key with another body returns 422 IDEMPOTENCY_KEY_REUSED. See Idempotency.

Authorizations

Authorization
string
header
required

API key issued from app.anyformat.ai/api-key. Send as Authorization: Bearer <key>.

Headers

Idempotency-Key
string | null

Optional caller-supplied key (Stripe convention). Retrying with the same key returns the original optimization instead of starting (and billing) a second one.

Path Parameters

workflow_id
string
required

Body

application/json

Body for POST /v3/workflows/{workflow_id}/optimizations/, discriminated on kind.

kind
string
required

A measured run: every round is scored against the dataset's ground truth.

Allowed value: "extraction"
max_rounds
integer
default:3

Most rounds the run may try. It stops earlier when rounds stop improving accuracy.

Required range: 1 <= x <= 10

Response

Successful Response

One optimization run.

id
string
required

Unique identifier of the optimization (hyphenated UUID).

Example:

"069dcc2c-e14c-7606-8000-2ee4fb17b4f9"

workflow_id
string
required

The optimized workflow (hyphenated UUID).

kind
enum<string>
required
Available options:
extraction,
extraction_oneshot
status
enum<string>
required

Lifecycle of a run. Non-terminal: evaluating, proposing. Terminal: done, failed.

Available options:
evaluating,
proposing,
done,
failed
max_rounds
integer
required

Most rounds the run may try.

rounds
OptimizationRoundV3 · object[]
required
baseline_accuracy
number | null

Accuracy before any change; null until scored and on a one-shot run.

best_accuracy
number | null

Best accuracy any round reached; null until scored and on a one-shot run.

result_version_id
string | null

The workflow version that holds the optimized descriptions; null until a round is kept.

error
string | null

Why the run failed; null unless status is failed.

created_at
string<date-time> | null

When the run started (ISO 8601).

finished_at
string<date-time> | null

When the run reached done or failed (ISO 8601); null while it runs.