Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/openai-compatible/llms.txt
Use this file to discover all available pages before exploring further.
ChatToolConverter serializes the tool definitions and tool-choice policy that accompany a chat request. It is called by ChatRequestBuilder::build() when the request carries one or more tools, and its two static methods handle the tools array and the tool_choice field independently. You never need to instantiate this class directly.
Namespace
Methods
convert()
AiSdk\Tool objects into the OpenAI tools array. Each tool is wrapped in the {"type": "function", "function": {...}} envelope expected by the API.
An array of
AiSdk\Tool objects to include in the request. Passing an empty array produces an empty output array.array<int, array<string, mixed>> — each element has the shape:
parameters value is sourced from Tool::inputSchemaForProvider(), which returns the JSON Schema object that describes the tool’s accepted inputs.
choice()
AiSdk\ToolChoice object (or null) into the value for the OpenAI tool_choice request field.
The desired tool-choice policy. When
null, the converter defaults to 'auto', letting the model decide whether to call a tool.string for standard policies or an array when a specific tool is forced:
$choice value | Returned value |
|---|---|
null | 'auto' |
ToolChoice::TOOL (specific function) | {"type": "function", "function": {"name": "<toolName>"}} |
Any other type (e.g. 'none', 'required') | $choice->type as a plain string |
Example
ChatRequestBuilder only adds the tools and tool_choice keys to the request body when $request->tools is non-empty. If no tools are passed, neither key appears in the serialized payload, which avoids sending an empty tools: [] that some providers reject.