PRODUCTION USE CASE

LLM API for workflow automation

An accounts-payable workflow reads an invoice, matches it to a purchase order, asks the model to classify discrepancies, and either queues approval or opens an exception ticket. Workflow state lives in the application database, not in chat history.

Multi-step automation workflow with retries, checkpoints, and final state
LLM API for workflow automation

Production recipe

API, primary model, and failover configuration

Production choiceRecommendationWhy
APIPOST /v1/chat/completionsOpenAI-compatible server-side request
Primary modelgpt-5.6-terraTerra handles the bounded judgment step while preserving enough reasoning for policy and exception classification.
Fallback modelgpt-5.4-miniUse gpt-5.4-mini for narrow classifications that pass validation. Escalate novel exceptions to Sol or a person rather than widening the model's permissions.
Escalation modelgpt-5.6-solUse only when the primary route fails the defined quality or complexity boundary
Output contractValidated JSONA structured classification, policy rule ID, explanation, and review reason when applicable.
01
Scenario

Workflow automation in a production application

An accounts-payable workflow reads an invoice, matches it to a purchase order, asks the model to classify discrepancies, and either queues approval or opens an exception ticket. Workflow state lives in the application database, not in chat history.

The model decides only the ambiguous classification. Parsing, arithmetic, duplicate detection, writes, retries, and deadlines stay deterministic. Every external write carries an idempotency key.

02
Architecture

How the workflow automation workflow operates

  • Persist state and immutable input references.
  • Run deterministic parsing and matching.
  • Call the model only for the ambiguous decision.
  • Validate the decision against policy and confidence rules.
  • Write the next state idempotently or route to review.
03
API request

Call gpt-5.6-terra through LLMFly AI

Send the request from your server. Replace the example content and placeholder tool schema with data and tools from your application.

request.exampleCopy-ready
curl https://app.llmfly.ai/v1/chat/completions \
  -H "Authorization: Bearer $LLMFLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-terra",
    "messages": [
      {"role": "system", "content": "Classify the invoice discrepancy using the supplied policy. Return MATCH, REVIEW, or REJECT with the exact policy rule. Do not perform any external action."},
      {"role": "user", "content": "Classify this invoice and purchase-order discrepancy."}
    ],
    "response_format": {"type": "json_object"}
  }'
04
Model choice

Why gpt-5.6-terra is the primary model

Terra handles the bounded judgment step while preserving enough reasoning for policy and exception classification.

Use gpt-5.4-mini for narrow classifications that pass validation. Escalate novel exceptions to Sol or a person rather than widening the model's permissions.

05
Acceptance

Acceptance checks for workflow automation

MetricPass condition
End-to-end completion rateThe workflow reaches a recorded success state with every required step satisfied
Duplicate-write rateReplays and retries create no duplicate message, ticket, payment, or update
Manual-intervention rateOnly predefined exception paths require a person to resume the workflow
Cost and duration per workflowSuccessful runs stay inside the workflow's time and cost budget
06
Failure handling

Failures to handle before deployment

  • Using chat history as the state store
  • Retrying non-idempotent writes
  • Granting unnecessary permissions
  • Having no terminal failure path
07
Output

Returned output and run records

A structured classification, policy rule ID, explanation, and review reason when applicable.

Record the model ID, request ID, token usage, retries, validation result, and final disposition for every production run.

Frequently asked questions

Where should workflow state live?

Store it in an application database or workflow engine and pass only relevant state to the model.

What should be idempotent?

Every external write that may be retried, including messages, tickets, payments, and updates.

When should retries stop?

Use a bounded policy and move terminal failures to a review queue with recovery context.

Test this setup with your own inputs

Compare the primary and fallback models with the same requests, tools, and validation rules.

Compare models