Debugging HTTP Calls
Overview¶
Instructor PHP provides a way to debug HTTP calls made to LLM APIs via
withHttpDebugPreset() (or the legacy withDebugPreset()) on the Inference
object.
When HTTP debug mode is enabled, the HTTP middleware stack prints request and response details (including streaming data) to the console and dispatches HTTP debug events.
Example¶
<?php
require 'examples/boot.php';
use Cognesy\Polyglot\Inference\Inference;
$response = (new Inference)
->withHttpDebugPreset('on') // Enable HTTP debug middleware
->with(
messages: [['role' => 'user', 'content' => 'What is the capital of Brasil']],
options: ['max_tokens' => 128]
)
->get();
echo "USER: What is capital of Brasil\n";
echo "ASSISTANT: $response\n";
?>