from openai import OpenAI
from pydantic import BaseModel
client = OpenAI()
# Function to create a file with the Files API
def create_file(file_path):
with open(file_path, "rb") as file_content:
result = client.files.create(
file=file_content,
purpose="vision",
)
return result.id
# Getting the file ID
file_id = create_file("images/passport-sample.jpg")
response = client.responses.create(
model="gpt-4.1-mini",
input=[{
"role": "user",
"content": [
{"type": "input_text", "text": "what's in this image?"},
{
"type": "input_image",
"file_id": file_id,
},
],
}],
)
print(response.output_text)This image is of an Iranian passport belonging to a person named Fatemeh Irani. It includes personal details such as:
- Father's name: Rohollah
- Date and place of birth: 11/02/1979, Tehran
- Sex: Female
- Passport number: S00002812
- Date of issue: 09/10/2014
- Date of expiry: 09/10/2019
The document also features a photo of the passport holder wearing a headscarf. The word "SPECIMEN" is stamped on the passport, indicating that it is a sample image.