Skip to content

API Response Object

INFO

This section describes the response object returned by all LabsLLM API calls, which contains the model's output and related data. This is different from the "Structured Output" feature, which allows requesting specific formats from the model.

When you execute a prompt or chat interaction with LabsLLM, the method getResponseData() returns an object containing three main elements that provide comprehensive information about the interaction.

Main Response Elements

php
$response = $execute->getResponseData();

// Text response from the model (string)
$response->response;

// Function/tool calls requested by the model (array)
$response->function_calls;

// Tools that were executed with their results (array)
$response->called_tools;

Response

The response property contains the text response generated by the model. For example:

php
echo $response->response;
// Output: "The current date is July 14, 2023"

When using structured output (see Structured Output), you can get the structured response using getStructureResponse():

php
// Get the structured response object
$data = $response->getStructureResponse();
echo $data->response->title;    // Access properties directly

This is the most commonly used property when you just need the text output from the model.

Function Calls

The function_calls property contains information about any tools/functions the model requested to call:

php
if (!empty($response->function_calls)) {
    foreach ($response->function_calls as $call) {
        echo "Function: " . $call['name'] . PHP_EOL;
        echo "Arguments: " . json_encode($call['arguments']) . PHP_EOL;
        echo "ID: " . $call['id'] . PHP_EOL;
    }
}

Each function call includes:

  • name: The name of the function requested
  • arguments: The parameters sent to the function
  • id: Unique identifier for this function call

Called Tools

The called_tools property contains the results of tools that were actually executed:

php
if (!empty($response->called_tools)) {
    foreach ($response->called_tools as $tool) {
        echo "Tool: " . $tool['name'] . PHP_EOL;
        echo "Arguments: " . json_encode($tool['arguments']) . PHP_EOL;
        echo "Response: " . $tool['response']['response'] . PHP_EOL;
        echo "ID: " . $tool['id'] . PHP_EOL;
    }
}

Each tool execution includes:

  • name: The tool name
  • arguments: What was passed to the tool
  • response: The output returned by the tool
  • id: Unique identifier matching the function call

Released under the MIT License.