Issues with including base64 PDF files in prompt via PHP SDK

I’m using gpt-4.1 to extract some information from PDF files via the PHP OpenAI SDK. I’ve had good results with this over the past month or two, but have started to see a weird issue where OpenAI doesn’t seem to see the PDF info in my prompt.

What’s odd here is that the exact same file, resulting in the exact same prompt, will work in certain cases and will not work in others. In the cases it doesn’t work, I get a proper JSON response from the AI that matches the “response_format” schema, and the AI populates “file_issues” with something like “No file was attached or accessible in the request. Please provide a base64-encoded PDF file for processing”. In the response for failed requests, the promptTokens value is far less than on the successful responses.

My requests are logged and I’ve confirmed the prompt (including Base64 info) on the failed requests matches the successful ones exactly.

Here’s my prompt, simplified (“…” indicate trunctations of a long prompt that hasn’t changed and just provides info about what should be extracted from the file):

Has something changed with including base64 file data in a prompt or am I doing something ill-advised in my prompt?

$base64OfPdfFile = base64_encode(Storage::get($filePath))
$chatMessage = [
	'model' => 'gpt-4.1',
	'messages' => [
		[
			'role' => 'developer', 
			'content' => [
				['type' => 'text', 'text' => 'You are a helpful assistant. You will be given the content of a...creation date that typically appears in the footer in each page. If you do not receive a file or cannot read it, please specify the reason you cannot access the data in the \"file_issues\" field.'],
			]
		],
		[
			'role' => 'user', 
			'content' => [
				['type' => 'file', 'file' => ['filename' => 'ServiceTFile.pdf', 'file_data' => "data:application/pdf;base64," . $base64OfPdfFile]],
				['type' => 'text', 'text' => 'The PDF file in this request (ServiceTFile.pdf) is a base64 encoding of...if it appears in the document'],
			]
		],
	],
	'temperature' => 0,
	'response_format' => [
		'type' => 'json_schema',
		'json_schema' => [
			"name" => "servicetdata",                    
			"schema" => [
				'type' => 'object',
				'properties' => [
					"person_name" => ['type' => 'string'],
					"file_creation_date" => ['type' => 'string'],
					"file_issues" => ['type' => 'string'],
					"matches" => [
						"type" => "array",
						"items" => [
							"type" => "object",
							"properties" => [
								"match_id" => ['type' => 'string'],
								"version" => ['type' => 'string'],
								"title" => ['type' => 'string']
							],
							'required' => ['match_id', 'version', 'title'],
							'additionalProperties' => false
						],
					]
				],
				'additionalProperties' => false,
				'required' => ['person_name', 'matches', 'file_creation_date','file_issues'],
				
			],
			"strict" => true,
		]
	]
];
$client->chat()->create($chatMessage);
1 Like