← All tutorialsAI

Structured extraction over invoices

Hand a raw invoice text blob to text_generation.extract_structured with a JSON schema; get back typed line items. No prompt-engineering ritual.

Cost~$0.003 per invoice
Operations
text_generation.extract_structured

Prerequisites

  • OCR/text-extraction already done (see document.parse below).

Walkthrough

1. Define the schema

JSON Schema with `vendor`, `total_cents`, `line_items[]`. The platform enforces it server-side.

bash# Schema-validated JSON output, no parseInt() gymnastics.
curl -X POST https://www.upivia.com/v1/service-requests \
  -H "Authorization: Bearer $AGENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "service":"text_generation",
    "operation":"extract_structured",
    "payload":{
      "model":"openai/gpt-4o-mini",
      "input":"<raw invoice text>",
      "schema":{
        "type":"object",
        "properties":{
          "vendor":{"type":"string"},
          "total_cents":{"type":"integer"},
          "line_items":{"type":"array","items":{"type":"object"}}
        },
        "required":["vendor","total_cents"]
      }
    }
  }'

Next steps

Audit every call at /audit-logs, watch spend at /usage, and tune budgets per service on the agent's page.

Create an account →