Certainly! Here’s a clear solution specifically tailored to your Laracasts forum question.
Solution:
From your example, you're trying to specify multiple AI providers with specific models by passing an associative array as the provider argument:
$response = (new CustomResearch)
->prompt(
'Here are the instructions...\n\n' . $prompt . ' and the data:' . $jsonData,
provider: [
'openai' => 'gpt-5.2',
'gemini' => 'gemini-3-pro-preview',
],
timeout: 600,
);
Can you invoke the AI SDK this way?
This highly depends on how your CustomResearch class and particularly the prompt method are implemented. Most AI SDKs (such as for OpenAI or Google Gemini) do not natively accept an associative array of providers and models in a single request. Usually, you specify one provider and one model per prompt. If you want to query multiple providers/models, you'd typically loop over them.
What is usually required:
Unless you’ve built custom logic into your CustomResearch class to handle such an array of providers/models, this is likely how you’d structure it:
$providers = [
'openai' => 'gpt-5.2',
'gemini' => 'gemini-3-pro-preview',
];
$responses = [];
foreach ($providers as $provider => $model) {
$responses[$provider] = (new CustomResearch)
->prompt(
'Here are the instructions...\n\n' . $prompt . ' and the data:' . $jsonData,
provider: $provider,
model: $model,
timeout: 600,
);
}
What should you do?
-
Check the implementation of your
CustomResearch::promptmethod.- If it expects a single provider and single model per call, use the loop example above.
- If you have custom logic that accepts an array and handles multiple providers/models, then your code may already work.
-
If you want built-in multi-provider support, ensure your method signature and implementation handle that associative array and iterate/query accordingly.
Example method signature for multi-provider logic:
public function prompt($prompt, array $providers = [], $timeout = 600)
{
$responses = [];
foreach ($providers as $provider => $model) {
// Your querying logic for each provider/model
$responses[$provider] = $this->callProvider($provider, $model, $prompt, $timeout);
}
return $responses;
}
Summary:
- If your AI SDK/library doesn't support multiple providers in a single call, you must loop.
- Only use your original approach if you’ve extended your code to handle it.
- Otherwise, use the loop example above for clarity and compatibility.
Let me know if you need help with the structure of your CustomResearch class or how to best design for multiple models/providers!