<?php
// get StructuredOutputResponse object to get access to usage and other metadata
$response1 = (new StructuredOutput($mdJsonRuntime))
->withCachedContext(
system: $cachedSystem,
prompt: $cachedPrompt,
)
->with(
messages: 'Describe the project in a way compelling to my audience: P&C insurance CIOs.',
responseModel: Project::class,
options: ['max_tokens' => 4096],
)->create();
// get processed value - instance of Project class
$project1 = $response1->get();
dump($project1);
assert($project1 instanceof Project);
assert($project1->name !== '');
assert($project1->description !== '');
// get usage information from inferenceResponse() when you need transport-level metadata
$usage1 = $response1->inferenceResponse()->usage();
echo "Usage: {$usage1->inputTokens} prompt tokens, {$usage1->cacheWriteTokens} cache write tokens\n";
?>