Browse the docsPDF
Each page of each PDF becomes its own model call, dispatched concurrently, and the per-page results are concatenated in order. A large batch costs roughly the wall-clock of a single page, and one unreadable page never poisons the rest of the document.
Fan-out limit
| Limit | Value | On breach |
|---|---|---|
| Pages + images per request | 25 | 413 page_limit_exceeded |
import base64
from openai import OpenAI
API_KEY = "Your API Key"
BASE_URL = "https://labs-api.petpooja.com/v1/extract"
MODEL = "chitragupta"
client = OpenAI(api_key=API_KEY, base_url=BASE_URL)
PDF_PATH = "<PDF_PATH>"
pdf_b64 = base64.b64encode(open(PDF_PATH, "rb").read()).decode()
pdf_data_uri = f"data:application/pdf;base64,{pdf_b64}"
response = client.chat.completions.create(
model=MODEL,
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Extract the invoice information from this document as JSON."},
{"type": "file", "file": {"filename": "invoice.pdf", "file_data": pdf_data_uri}},
],
}],
)
print(response)import fs from "node:fs";
const apiKey = "Your API Key";
const baseURL = "https://labs-api.petpooja.com/v1/extract/chat/completions";
const model = "chitragupta";
const pdfPath = "<PDF_PATH>";
async function main() {
const b64 = fs.readFileSync(pdfPath).toString("base64");
const body = {
model,
messages: [{
role: "user",
content: [
{ type: "text", text: "Extract information of last page from this document as JSON." },
{ type: "file", file: { filename: "invoice.pdf", file_data: `data:application/pdf;base64,${b64}` } }
]
}]
};
const res = await fetch(baseURL, {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
console.log("HTTP Status:", res.status);
console.log(await res.text());
}
main();package main
import (
"encoding/base64"
"fmt"
"io"
"net/http"
"os"
"strings"
)
const (
apiKey = "Your API Key"
baseURL = "https://labs-api.petpooja.com/v1/extract/chat/completions"
model = "chitragupta"
pdfPath = "<PDF_PATH>"
)
func main() {
data, err := os.ReadFile(pdfPath)
if err != nil {
panic(err)
}
b64 := base64.StdEncoding.EncodeToString(data)
body := fmt.Sprintf(`{"model":"%s","messages":[{"role":"user","content":[
{"type":"text","text":"Extract information of last page from this document as JSON."},
{"type":"file","file":{"filename":"invoice.pdf","file_data":"data:application/pdf;base64,%s"}}
]}]}`, model, b64)
req, _ := http.NewRequest("POST", baseURL, strings.NewReader(body))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println("HTTP Status:", res.StatusCode)
fmt.Println(string(out))
}KEY="Your API Key"
BASE="https://labs-api.petpooja.com/v1/extract/chat/completions"
PDF="<PDF_PATH>"
PDF_URI="data:application/pdf;base64,$(base64 -w0 "$PDF")"
cat > /tmp/pp_chat_pdf.json <<EOF
{
"model": "chitragupta",
"max_tokens": 8000,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Extract all details from this document and return the extracted information."
},
{
"type": "file",
"file": {
"file_data": "$PDF_URI",
"filename": "document.pdf"
}
}
]
}
]
}
EOF
curl -s -i "$BASE"\
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d @/tmp/pp_chat_pdf.json