PDF Analysis
Multimodal models can process and analyze PDF documents for summarization, data extraction, or question answering. Replace YOUR_VISION_MODEL_ID with a model ID that the current catalog marks as supporting PDF or file input:
import base64from openai import OpenAI def encode_pdf_to_base64(pdf_path): with open(pdf_path, "rb") as pdf_file: return base64.b64encode(pdf_file.read()).decode("utf-8") client = OpenAI( base_url="https://api.livrouter.com/v1", api_key="your-api-key") pdf_path = "document.pdf"base64_pdf = encode_pdf_to_base64(pdf_path)data_url = f"data:application/pdf;base64,{base64_pdf}" response = client.responses.create( model="YOUR_VISION_MODEL_ID", input=[{ "role": "user", "content": [ {"type": "input_text", "text": "What is this document about?"}, { "type": "input_file", "file": { "filename": "document.pdf", "file_data": data_url } }, ], }],) print(response.output_text)