langchain_unstructured with an Uncensored LLM API
The LangChain Unstructured loader parses and splits documents; it does not call a model. Pair it with ChatOpenAI pointed at an OpenAI-compatible endpoint and you have a document pipeline in about thirty lines.
Updated
Key points
- The Unstructured integration is the LangChain package for the Unstructured document loader, so it handles parsing, not generation.
- ChatOpenAI with a custom base_url and model uncensored handles the generation half.
- There is no embeddings route here, so retrieval needs a local or separate embedding model.
- A 100,000-token window often lets you skip retrieval for single documents.
The loader package and the model are separate
If you landed here after typing langchain_unstructured into a search box, here is the useful fact first: it is the name of a Python package, installed with pip as langchain-unstructured, that wraps the Unstructured document-parsing library for LangChain. Its main class, UnstructuredLoader, reads PDFs, Word files, HTML and similar formats and returns LangChain Document objects. It does not talk to a language model at all.
That means two separate jobs. Parsing turns messy files into clean text elements. Generation takes that text and writes something. For generation you pick a chat model class, and because this service follows the OpenAI format, the standard ChatOpenAI class from langchain-openai works with a changed base URL. Everything below shows the two halves joined.
One reminder about scope: the API is text only. Nothing on this page involves video or images, even though the site name suggests otherwise. The related text layer article explains where a text model sits in a video workflow.
Install and configure
Install the loader, the OpenAI integration, and the parser extras for the file types you use:
pip install langchain-unstructured langchain-openai langchain-core
pip install "unstructured[pdf]"Unstructured can also run as a hosted service, in which case you pass its own key to the loader and skip the local install. That key belongs to Unstructured and is unrelated to ours. Local parsing needs more system packages for some formats, so read the loader's documentation if a PDF fails to open.
Now the model side. Set the key in an environment variable and build the chat model:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.unrestrictedvideo.com/v1",
api_key=os.environ["API_KEY"],
temperature=0.3,
)
print(llm.invoke("Reply with one word: ready").content)If that prints a word, the generation half is done. If you still need a key, the key page has a one-click trial of $0.50 credit for new accounts, no payment required.
Load a document and summarize it
This script parses a file, joins the extracted text and asks the model for a summary. For a single report or contract, a 100,000-token window (prompt plus completion) is large enough to pass the whole text without any retrieval step.
import os
from langchain_unstructured import UnstructuredLoader
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
loader = UnstructuredLoader("report.pdf")
docs = loader.load()
text = "\n\n".join(d.page_content for d in docs)
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.unrestrictedvideo.com/v1",
api_key=os.environ["API_KEY"],
)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a careful analyst. Use only the supplied text."),
("human", "Summarize the key points of this document:\n\n{text}"),
])
chain = prompt | llm | StrOutputParser()
print(chain.invoke({"text": text}))Each Document carries metadata such as the page number and the element category (title, narrative text, table). Keep that metadata if you want citations, for example by prefixing each chunk with its page before joining.
Check the size before you send
Count roughly before every call. A rule of thumb for English is four characters per token, so len(text) / 4 gives an estimate. If it lands near 100,000, split the document by section and summarize in two passes, or trim boilerplate such as headers and footers that the loader returned as separate elements.
Choosing how to split the text
The loader returns elements, not paragraphs of a convenient size. A title becomes one element, a table another, a list item yet another. Joining them all with blank lines works for summaries. For question answering over several files, grouping by title keeps related content together. The loader accepts a chunking_strategy option such as by_title, plus size limits, so check the current loader reference for the exact argument names in your installed version.
Tables deserve a look. A table that arrives as flattened cell text can confuse a model, so inspect a few outputs by eye. If a table matters, ask the parser for the HTML form of it where your version supports that, since a model reads rows and columns more reliably from markup than from a stream of cell values.
Last, strip what you do not need. Page headers, footers and repeated disclaimers cost input tokens on every call. Filtering elements by category before joining them is a cheap change that lowers cost and removes noise, and it needs only a list comprehension over docs using the category stored in each document's metadata.
Structured extraction with JSON mode
Parsing pipelines often feed a database, which means you want fields, not prose. The API supports JSON mode, and LangChain exposes it through with_structured_output:
from pydantic import BaseModel
from typing import List
class Contract(BaseModel):
parties: List[str]
start_date: str
obligations: List[str]
structured = llm.with_structured_output(Contract, method="json_mode")
result = structured.invoke(
"Extract parties, start_date and obligations as JSON with exactly those keys.\n\n" + text
)
print(result)With json_mode, the class you pass is used to parse and validate the answer, but the model only learns the shape from your prompt, so list the key names in the instruction as above. Expect to handle an occasional validation error and retry once. Failed or refused requests are not charged, though a request that returns valid JSON with wrong content is billed as normal.
Tool calling and streaming
Agent workflows use bind_tools. The endpoint accepts tools and tool_choice and streams tool_calls, so the usual LangChain agent loop works:
from langchain_core.tools import tool
@tool
def lookup_clause(topic: str) -> str:
"""Find the clause in the loaded document that covers a topic."""
hits = [d.page_content for d in docs if topic.lower() in d.page_content.lower()]
return hits[0] if hits else "not found"
llm_tools = llm.bind_tools([lookup_clause])
msg = llm_tools.invoke("Which clause covers termination?")
print(msg.tool_calls)The returned tool_calls list names the function and arguments. Run the function and send the result back as a tool message, which LangChain does for you inside an agent executor. For streaming, call llm.stream(...) and iterate; chunks arrive as server-sent events. Remember that a streamed request holds one of your concurrency slots until the end, 8 on a full key and 2 on a trial key.
Retrieval without embeddings from this API
The service does not provide embeddings, so OpenAIEmbeddings pointed at this base URL will fail. For a large corpus that does not fit in one window, split the loader output into chunks, embed them with a local sentence-embedding model or another provider, store them in a vector store, and send only the top results to uncensored. The chat model never sees the embeddings; it only reads the final text.
For anything under roughly 100,000 tokens, ask whether retrieval is worth the complexity. Passing the full text keeps answers consistent and removes retrieval errors. For multiple documents, a loop with one call per document and a final merge call is often simpler than a vector store.
Cost, limits and retries
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. Suppose a 60-page PDF at about 700 tokens per page, so 42,000 input tokens, and a 1,000-token summary:
- Input: 42,000 / 1,000,000 x $0.15 = $0.0063
- Output: 1,000 / 1,000,000 x $0.50 = $0.0005
- Total: $0.0068
That is under a cent per document, so a batch of 100 such files costs $0.68. See the pricing page for top-ups; this site accepts crypto only (USDT on TRC20 or USDC on Base).
When you run batches, LangChain's max_retries on ChatOpenAI handles transient failures. Over a limit the API returns HTTP 429, with code rate_limited for requests per minute or concurrency for too many at once, and Retry-After: 5 during temporary overload. Cap parallelism at 8 for a full key, for example with chain.batch(inputs, config={"max_concurrency": 6}), and you will rarely see either. The documentation lists the response headers worth logging.
One more habit for batch jobs: write each result to disk as soon as it returns, keyed by the source file name. If a run stops at file 63 of 100, you restart from 64 instead of paying again for the first 63. Failed requests are not charged, but successful ones before the failure are, so saving them is worth a few lines of code.
More guides

Questions and answers
Is the Unstructured integration a model provider?
No. It is a document loader integration. You still need a chat model class such as ChatOpenAI to generate text from what it loads.
Do I need an Unstructured API key?
Not for local parsing, which needs the unstructured library installed. The hosted Unstructured API is optional and has its own key, separate from ours.
Can I use OpenAIEmbeddings with this endpoint?
No, the service has no embeddings. Use a local embedding model for vector search, then send the retrieved chunks to <code>uncensored</code> for the answer.
Does with_structured_output work?
Use method="json_mode", which maps to the JSON mode parameter the API supports, and describe the fields in your prompt. Validate the result on your side.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.