Skip to main content

Overview

This guide walks you through parsing one or more files with the Sciforium API, extracting plain text from the results, and sending that text to an LLM with a question.

Prerequisites

  • A Sciforium API key — get one at console.sciforium.com
  • Python 3.8+
  • The file(s) you want to parse accessible on disk (or uploaded to Colab — see the note below)
If you’re running in Google Colab, click the folder icon in the left sidebar, upload your file, then right-click it and select Copy path to use in your code. Uploaded files are deleted when the runtime disconnects.

Step 1 — Configuration

Set the four variables below before running anything else.
  • FILE_PATH — absolute path to the file you want to parse. Supported formats: PDF, DOCX, DOC, TXT, MD, CSV, HTML, JSON - any utf-8 encoded file.
  • QUESTION — the question you want to ask the LLM about the document.
  • MODEL — the LLM model identifier (e.g. openai/gpt-oss-120b, anthropic/claude-sonnet-4-6).
  • SCIFORIUM_API_KEY — your Sciforium API key.
Never commit your API key to version control. Use environment variables or a secrets manager in production.

Step 2 — Install dependencies

Run this once if openai or requests aren’t already installed.

Step 3 — Initialize the client

This constructs the Sciforium endpoint URLs and resolves the API key, falling back to the SCIFORIUM_API_KEY environment variable if set.

Step 4a — Parse a single file

Reads the file from FILE_PATH, base64-encodes it, and POSTs it to the Sciforium parse endpoint. The response contains structured content (pages, text, metadata) for the file.

Step 4b — Batch parse (optional)

Use this instead of Step 4a to parse multiple files in parallel with a thread pool. Add all your file paths to FILE_PATHS.
Run either Step 4a or Step 4b — not both. If you use this batch step, update Step 6 to iterate over parse_responses (plural) instead of parse_response.

Step 5 — Inspect the raw response (optional)

Print the full JSON to explore the response schema or debug issues. You can skip this step — it has no side effects.

Step 6 — Extract text from parse results

This walks the parse response and stitches all page text into a single document_text string. Pages are labeled [Page N] so the LLM can reference them. Files that failed to parse are skipped with a warning.
You are responsible for context management beyond this point. If document_text is larger than your model’s context window, you must truncate, chunk, or summarize it before sending. For large documents, consider splitting by page and processing in batches, or using a retrieval step (e.g. embeddings + vector search) to select only the relevant sections.

Step 7 — Ask the LLM

Send document_text plus your QUESTION to the configured model via the Sciforium OpenAI-compatible gateway.
To ask multiple questions without re-parsing, just change QUESTION and re-run this cell.