---
title: Documents and images
description: Ask SubQ Snap about a document's text, or about up to 4 images alongside it.
---

SubQ Snap takes text and images, not files. Send a document's text as
`state`, and add images to judge what they show. Both go in the same
[Decisions API](/endpoints/decisions-api/) request as your questions.

## Documents

Use a document to fact-check a claim against its source, find the passage that
backs an answer, or tag a record from its text.

The Decisions API takes no files. To ask about a PDF, Word file, or other
document, extract its text and send it as `state`, on its own or as a field
next to other data. Run OCR on scanned PDFs first.

- **Label the parts.** Mark pages, sections, or passages in the text, like
  `[P2]` or `--- page 24 ---`, so options can name them.
- **Ask where.** A choice whose options are those labels returns a probability
  for each location. Add an option like `not_found` for when the document
  doesn't say.

Send the text as a `state` field, and use the labels as `choice` options:

```bash title="cURL"
curl --request POST \
  --url https://api.subq.ai/v1/systemone \
  --header "Authorization: Bearer $SUBQ_API_KEY" \
  --header 'Content-Type: application/json' \
  --data @- <<'EOF'
{
  "model": "subq-snap-1.2",
  "state": {
    "claim": "Under Harlow v. Pemberton (2019), a landlord must return a tenant's security deposit within 14 days of move-out, no exceptions.",
    "source": "Harlow v. Pemberton, State Court of Appeals (2019)\n\n[P1] Tenant Dana Harlow moved out of a two-bedroom apartment on June 1. Landlord Owen Pemberton kept her $1,800 deposit for 30 days, then returned $600 with a note that the rest covered carpet damage.\n\n[P2] We hold that Section 12 of the Residential Tenancy Act requires a landlord to return the deposit within 14 days of move-out, unless within those same 14 days the landlord sends the tenant a written, itemized list of the damage it intends to deduct. A landlord who sends the list in time may keep the listed amounts while the dispute is resolved.\n\n[P3] Pemberton sent no itemized list within 14 days. He therefore owes Harlow the full deposit and, under Section 15, a penalty equal to the amount wrongly withheld.\n\n[P4] Harlow argues that Section 12 sets a 14-day deadline \"with no exceptions,\" and that any deduction needs a court order. We disagree. The Act plainly allows deductions that are itemized in time.\n\n[P5] Judge Alvarez, dissenting: I would allow the itemized-list route only for landlords who also photographed the unit at move-in. Without that record, the 14-day deadline should apply to the whole deposit.\n\n[P6] Headnote (written by the publisher, not part of the opinion): Landlords must return deposits within 14 days."
  },
  "questions": {
    "support": {
      "type": "score",
      "instructions": "How well does the source support the claim as written?",
      "criteria": [
        "Not supported",
        "Partly supported",
        "Fully supported"
      ]
    },
    "best_passage": {
      "type": "choice",
      "instructions": "Which source passage states the court's rule on the claim's subject?",
      "criteria": {
        "P1": null,
        "P2": null,
        "P3": null,
        "P4": null,
        "P5": null,
        "P6": null,
        "not_found": "No passage states it"
      }
    },
    "omits_condition": {
      "type": "noul",
      "instructions": "Does the claim leave out a condition or exception that the court's holding sets?"
    },
    "no_exceptions_source": {
      "type": "choice",
      "instructions": "Where in the source does the claim's \"no exceptions\" come from?",
      "criteria": {
        "majority": "The court's own holding or reasoning",
        "party_argument": "An argument the court describes and rejects",
        "dissent": "The dissenting judge",
        "headnote": "The publisher's headnote, which is not law",
        "not_found": "The source never says it"
      }
    }
  }
}
EOF
```

`best_passage` returns `"choice": "P2"` with a probability for every label,
including `not_found`.

## Images

Judge photos or screenshots alongside the text, such as checking that a
listing's photos match its description, or that a screenshot shows a step is
done. Send each image as base64, with no URL or `data:` prefix:

```ts title="TypeScript"
import { readFileSync } from "node:fs";

const baseURL = "https://api.subq.ai/v1";

// The ticket note. The photo carries the rest: which device, and what shape it is.
const state = "The number row stopped working.";

// Plain base64 of the file bytes. No data: URL prefix.
// PNG, JPEG, or WebP, at most 4 MiB decoded per image.
const photo = readFileSync("./keyboard.jpg").toString("base64");

// One question per judgment. Every question sees the note and every image.
const questions = {
  shows_keyboard: {
    type: "noul",
    instructions: "Does the photo show a keyboard?",
    criteria: {
      true: "A keyboard is the main object",
      false: "No keyboard is visible",
    },
  },
  layout: {
    type: "choice",
    instructions: "Which keyboard layout is in the photo?",
    criteria: {
      full_size: "Desktop keyboard with a numeric keypad",
      tenkeyless: "Desktop keyboard with no numeric keypad",
      laptop: "Built into a laptop",
      not_a_keyboard: null,
    },
  },
  wear: {
    type: "score",
    instructions: "How worn does the keyboard look?",
    criteria: ["Looks new", "Everyday wear", "Replace it"],
  },
};

const response = await fetch(`${baseURL}/systemone`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SUBQ_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "subq-snap-1.2",
    state,
    images: [{ mediaType: "image/jpeg", base64: photo }],
    questions,
  }),
});

if (!response.ok) {
  const error = await response.json();
  throw new Error(
    `${response.status} ${error.detail.error_type}: ${error.detail.message}`,
  );
}

const result = await response.json();
const { shows_keyboard, layout, wear } = result.answers;

// A photo that is not a keyboard, or an unsure layout, goes back to the employee.
if (
  shows_keyboard.noul < 0.5 ||
  layout.confidence < 0.6 ||
  layout.choice === "not_a_keyboard"
) {
  console.log("Ask for a clearer photo of the keyboard.");
} else {
  const condition = wear.legend[String(Math.round(wear.score))];
  console.log(`Keyboard: ${layout.choice} (${condition})`);
}
```

```py title="Python"
import base64
import os
from pathlib import Path

import httpx2  # pip install httpx2

base_url = "https://api.subq.ai/v1"

# The ticket note. The photo carries the rest: which device, and what shape it is.
state = "The number row stopped working."

# Plain base64 of the file bytes. No data: URL prefix.
# PNG, JPEG, or WebP, at most 4 MiB decoded per image.
photo = base64.b64encode(Path("./keyboard.jpg").read_bytes()).decode("ascii")

# One question per judgment. Every question sees the note and every image.
questions = {
    "shows_keyboard": {
        "type": "noul",
        "instructions": "Does the photo show a keyboard?",
        "criteria": {
            "true": "A keyboard is the main object",
            "false": "No keyboard is visible",
        },
    },
    "layout": {
        "type": "choice",
        "instructions": "Which keyboard layout is in the photo?",
        "criteria": {
            "full_size": "Desktop keyboard with a numeric keypad",
            "tenkeyless": "Desktop keyboard with no numeric keypad",
            "laptop": "Built into a laptop",
            "not_a_keyboard": None,
        },
    },
    "wear": {
        "type": "score",
        "instructions": "How worn does the keyboard look?",
        "criteria": ["Looks new", "Everyday wear", "Replace it"],
    },
}

response = httpx2.post(
    f"{base_url}/systemone",
    headers={"Authorization": f"Bearer {os.environ['SUBQ_API_KEY']}"},
    json={
        "model": "subq-snap-1.2",
        "state": state,
        "images": [{"mediaType": "image/jpeg", "base64": photo}],
        "questions": questions,
    },
    timeout=60,
)
result = response.json()
if response.is_error:
    detail = result["detail"]
    raise RuntimeError(
        f"{response.status_code} {detail['error_type']}: {detail['message']}"
    )

answers = result["answers"]
shows_keyboard = answers["shows_keyboard"]["noul"]
layout = answers["layout"]
wear = answers["wear"]

# A photo that is not a keyboard, or an unsure layout, goes back to the employee.
if (
    shows_keyboard < 0.5
    or layout["confidence"] < 0.6
    or layout["choice"] == "not_a_keyboard"
):
    print("Ask for a clearer photo of the keyboard.")
else:
    condition = wear["legend"][str(round(wear["score"]))]
    print(f"Keyboard: {layout['choice']} ({condition})")
```

### cURL with an image

`openssl base64 -A` writes the file as one line. The heredoc is unquoted so the
shell encodes the file before the request is sent. Shrink the photo first so
the decoded file stays under 4 MiB.

```bash
curl -sS -X POST https://api.subq.ai/v1/systemone \
  -H "Authorization: Bearer $SUBQ_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<EOF
{"model":"subq-snap-1.2","state":"The number row stopped working.","images":[{"mediaType":"image/jpeg","base64":"$(openssl base64 -A -in keyboard.jpg)"}],"questions":{"shows_keyboard":{"type":"noul","instructions":"Does the photo show a keyboard?","criteria":{"true":"A keyboard is the main object","false":"No keyboard is visible"}},"layout":{"type":"choice","instructions":"Which keyboard layout is in the photo?","criteria":{"full_size":"Desktop keyboard with a numeric keypad","tenkeyless":"Desktop keyboard with no numeric keypad","laptop":"Built into a laptop","not_a_keyboard":null}},"wear":{"type":"score","instructions":"How worn does the keyboard look?","criteria":["Looks new","Everyday wear","Replace it"]}}}
EOF
```

- **Cost:** each image costs 66 to about 1,600 input tokens, set by resolution
  rather than file size. Downscale anything above about 1.6 megapixels to cut
  the cost.
- **Video:** not supported. Sample up to 4 frames and send them as images.

Formats, size limits, and image errors are in
[Images](/endpoints/decisions-api/#images) on the API reference.

## Next steps

- [Make a decision](/using-the-api/make-a-decision/): question types and
  reliable decision workflows.
- [Decisions API](/endpoints/decisions-api/): every field, limit, and error.
