{
  "info": {
    "name": "Refractr API",
    "description": "Refractr turns documents into structured JSON. You write a template shaped like the answer you want, with typed placeholders on the leaves, and get back clean typed values.\n\n## Setup\n\n1. Open the collection **Variables** tab.\n2. Paste your API key into the current value of `api_key`. Keys start with `re_` and are created in your dashboard at https://www.refractr.io/account/.\n3. Send **Extract (sync)** to check it works.\n\nThe key is sent as `Authorization: Bearer {{api_key}}` on every request via collection-level auth.\n\n## Typed placeholders\n\nLeaf values in a template declare the type you want back:\n\n| Placeholder | Output is always |\n| --- | --- |\n| `\"__str__\"` | string or null |\n| `\"__int__\"` | integer or null |\n| `\"__float__\"` | number or null |\n| `\"__bool__\"` | true/false or null |\n| `\"__date__\"` | \"YYYY-MM-DD\" or null |\n\nUse `null` for an untyped field and `[]` for a list. The type is enforced during generation, so the response shape is guaranteed. Accuracy is not: extraction is model-based, so validate values against your own rules.\n\nDocs: https://www.refractr.io/docs/",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{api_key}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://www.refractr.io",
      "type": "string",
      "description": "API base URL. No trailing slash."
    },
    {
      "key": "api_key",
      "value": "",
      "type": "string",
      "description": "Your Refractr API key, starting with re_. Create one at /account/."
    },
    {
      "key": "job_id",
      "value": "",
      "type": "string",
      "description": "Set automatically by the async example; used by Poll job result."
    }
  ],
  "item": [
    {
      "name": "Extract (sync)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/api/v1/extract/",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "extract",
            ""
          ]
        },
        "description": "Submit a document and wait for the result. Costs one credit on success; failed extractions are not charged.\n\nSend either `document_text` (plain text, max 50k chars) or `document` (an envelope, e.g. base64 PDF), but not both.\n\n`wait: true` blocks until the result is ready, up to 30 seconds. If the GPU worker is cold, prefer `wait: false` and poll.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"document_text\": \"INVOICE 2024-0912\\nAcme Industrial BV\\nDate: 12 September 2024\\nDue: 12 October 2024\\n\\n3x Widget assembly @ EUR 249.50\\n1x Installation service @ EUR 500.00\\n\\nSubtotal: EUR 1,248.50\\nVAT 21%: EUR 262.19\\nTotal: EUR 1,510.69\",\n  \"template\": {\n    \"invoice_number\": \"__str__\",\n    \"supplier\": \"__str__\",\n    \"invoice_date\": \"__date__\",\n    \"due_date\": \"__date__\",\n    \"subtotal_eur\": \"__float__\",\n    \"vat_pct\": \"__int__\",\n    \"total_eur\": \"__float__\"\n  },\n  \"schema_type\": \"invoice\",\n  \"wait\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "response": []
    },
    {
      "name": "Extract (async)",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Save the job_id so 'Poll job result' can be sent straight after.",
              "if (pm.response.code === 202 || pm.response.code === 200) {",
              "    const body = pm.response.json();",
              "    if (body.job_id) {",
              "        pm.collectionVariables.set('job_id', body.job_id);",
              "    }",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/api/v1/extract/",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "extract",
            ""
          ]
        },
        "description": "Submit a document and return immediately with a job_id. Use this when the worker may be cold, or for larger batches.\n\nThis request saves the returned job_id into the collection variable `job_id`, so you can send 'Poll job result' next without copying anything.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"document_text\": \"BREAKING: Nvidia soars 12% to ~$187 after crushing Q4 earnings. Revenue hit $22.1B vs $20.4B expected.\",\n  \"template\": {\n    \"company\": \"__str__\",\n    \"ticker\": \"__str__\",\n    \"stock_move_pct\": \"__float__\",\n    \"revenue_billions\": \"__float__\"\n  },\n  \"wait\": false\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "response": []
    },
    {
      "name": "Poll job result",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{base_url}}/api/v1/extract/{{job_id}}/",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "extract",
            "{{job_id}}",
            ""
          ]
        },
        "description": "Fetch the status and result of a job submitted with `wait: false`.\n\nStatus is one of queued, processing, success, error or timeout. Poll every second or so; a warm worker typically finishes in well under a second."
      },
      "response": []
    },
    {
      "name": "Health",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{base_url}}/api/v1/extract/health/",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "extract",
            "health",
            ""
          ]
        },
        "description": "Service health. Returns 200 when extractions are being served and 503 when they are not. No authentication required."
      },
      "response": []
    },
    {
      "name": "Account info",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{base_url}}/api/v1/account/",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "account",
            ""
          ]
        },
        "description": "Your account and current credit balance."
      },
      "response": []
    },
    {
      "name": "Usage summary",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{base_url}}/api/v1/account/usage/?days=30",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "account",
            "usage",
            ""
          ],
          "query": [
            {
              "key": "days",
              "value": "30",
              "description": "Window in days, max 90."
            }
          ]
        },
        "description": "Daily request, token and credit totals across all of your API keys."
      },
      "response": []
    },
    {
      "name": "Credit balance",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{base_url}}/api/v1/billing/credits/",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "billing",
            "credits",
            ""
          ]
        },
        "description": "Current credit balance plus lifetime purchased and used totals."
      },
      "response": []
    }
  ]
}
