<?php
// get StructuredOutputResponse object to get access to usage and other metadata
try {
$response1 = (new StructuredOutput($firstRuntime))
->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();
$project1 = $response1->get();
} catch (ProviderAuthenticationException) {
echo "Provider authentication failed for '{$providerName}'. Check the matching API key.\n";
return;
}
// get processed value - instance of Project class
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, {$usage1->cacheReadTokens} cache read tokens\n";
?>