EU GPT logo
EU GPT

Public preview — This API is in public preview. Endpoints, schemas, and limits may change before general availability.

API

Using files as context

This guide demonstrates how to upload a document (like a PDF or Word file) and immediately ask the LLM to extract information or answer questions about it.

Step 1: Upload the Document#

First, upload your file using the client.files.create method. You must specify the purpose as "assistants".

from pathlib import Path
from openai import OpenAI

client = OpenAI(
    api_key="<your_api_key>",
    base_url="https://api.eugpt.ai/v1",
)

# Upload the file
file_record = client.files.create(
    file=Path("financial_report_2024.pdf"),
    purpose="assistants"
)

print(f"Uploaded File ID: {file_record.id}")

Tip: Uploaded files persist in your environment. You can reuse the resulting file_id across multiple API calls, or use the client.files.list() method to view your existing files.

Step 2: Ask a Question About the Document#

To ask a question about the uploaded file, use the /v1/responses endpoint. Instead of passing a simple string as the input, pass an array that contains both the input_file reference and your input_text prompt.

# Use the ID from Step 1
uploaded_file_id = file_record.id

structured_input = [
    {
        "role": "user",
        "content": [
            {
                "type": "input_file", 
                "file_id": uploaded_file_id
            },
            {
                "type": "input_text", 
                "text": "Summarize the Q3 revenue figures from this report."
            }
        ]
    }
]

response = client.responses.create(
    model="auto",
    input=structured_input,
)

print(response.output_text)