extract.shbash
curl -X POST https://eu-api.tryparsr.dev/v1/extract \
-H "Authorization: Bearer $PARSR_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"document_url": "https://example.com/etrade-q1.pdf",
"schema": {
"type": "object",
"required": ["account_number", "period_end", "positions"],
"properties": {
"account_number": { "type": "string" },
"period_end": { "type": "string", "format": "date" },
"total_value": { "type": "string" },
"positions": {
"type": "array",
"items": {
"type": "object",
"required": ["symbol", "quantity", "market_value"],
"properties": {
"symbol": { "type": "string" },
"quantity": { "type": "string" },
"cost_basis": { "type": "string" },
"market_value": { "type": "string" }
}
}
}
}
},
"wait": 60
}'
extract_brokerage.pypython
import os, httpx
schema = {
"type": "object",
"required": ["account_number", "period_end", "positions"],
"properties": {
"account_number": {"type": "string"},
"period_end": {"type": "string", "format": "date"},
"total_value": {"type": "string"},
"positions": {
"type": "array",
"items": {
"type": "object",
"required": ["symbol", "quantity", "market_value"],
"properties": {
"symbol": {"type": "string"},
"quantity": {"type": "string"},
"cost_basis": {"type": "string"},
"market_value": {"type": "string"},
},
},
},
},
}
resp = httpx.post(
"https://eu-api.tryparsr.dev/v1/extract",
headers={"Authorization": f"Bearer {os.environ['PARSR_API_KEY']}"},
json={
"document_url": "https://example.com/etrade-q1.pdf",
"schema": schema,
"wait": 60,
},
timeout=70,
)
body = resp.json()
conformance = body["validation"]["schema_conformance"]
if not conformance["valid"]:
raise ValueError(f"Missing fields: {conformance['missing_fields']}")
for pos in body["result"]["positions"]:
print(pos["symbol"], pos["quantity"], pos["market_value"])
extractBrokerage.tstypescript
const schema = {
type: "object",
required: ["account_number", "period_end", "positions"],
properties: {
account_number: { type: "string" },
period_end: { type: "string", format: "date" },
total_value: { type: "string" },
positions: {
type: "array",
items: {
type: "object",
required: ["symbol", "quantity", "market_value"],
properties: {
symbol: { type: "string" },
quantity: { type: "string" },
cost_basis: { type: "string" },
market_value: { type: "string" },
},
},
},
},
} as const;
const resp = await fetch("https://eu-api.tryparsr.dev/v1/extract", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PARSR_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
document_url: "https://example.com/etrade-q1.pdf",
schema,
wait: 60,
}),
});
const body = await resp.json();
const { schema_conformance } = body.validation;
if (!schema_conformance.valid) {
throw new Error(`missing fields: ${schema_conformance.missing_fields.join(", ")}`);
}
for (const pos of body.result.positions) {
console.log(pos.symbol, pos.quantity, pos.market_value);
}
agent.pypython
from langchain_parsr import ParsrToolkit
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
# ParsrToolkit exposes 'parsr_extract' — the agent supplies the schema at call time.
tools = ParsrToolkit.from_env().get_tools()
agent = create_react_agent(ChatOpenAI(model="gpt-4o"), tools)
result = await agent.ainvoke({
"messages": [(
"user",
"Extract account_number, period_end, and a positions[] list "
"(symbol, quantity, market_value) from this E*TRADE statement: "
"https://example.com/etrade-q1.pdf"
)]
})
print(result["messages"][-1].content)