AI Provider
Interact with LLM providers or extend the framework to implement new ones.
With Neuron you can switch between LLM providers with just one line of code, without any impact on your agent implementation.
Anthropic
namespace App\Neuron;
use NeuronAI\Agent\Agent;
use NeuronAI\Chat\Messages\UserMessage;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
class MyAgent extends Agent
{
protected function provider(): AIProviderInterface
{
return new Anthropic(
key: 'ANTHROPIC_API_KEY',
model: 'ANTHROPIC_MODEL',
parameters: [], // Add custom params (temperature, logprobs, etc)
);
}
}
$message = MyAgent::make()
->setThreadId('chat_id')
->chat(new UserMessage("Hi!"))
->getMessage();
echo $message->getContent();
// Hi, how can I help you today?Anthropic Prompt Cache
To laverage Anthropic prompt cache you should provide agent instructions as an array of SystemContent:
Anthropic on Google Vertex AI
To use this provider you need to install the goole auth composer package:
Below the syntax to use AnthropicVertex in your agent.
OpenAIResponses
This component uses the most recent OpenAI responses API:
OpenAI
This component uses the old OpenAI completions API:
AzureOpenAI
This provider allows you to connect with OpenAI models provided in the Azure cloud platform.
OpenAILike
This class simplify the connection with providers offering the same data format of the official OpenAI API.
Ollama
Gemini
Gemini on Vertex AI
To use this provider you need to install the goole auth composer package:
Below the syntax to use GeminiVertex in your agent.
Mistral
ZAI
HuggingFace
Deepseek
Grok (X-AI)
AWS Bedrock Runtime
To use The BedrockRuntime provider you need to install the aws/aws-sdk-php package.
Below you can find the syntax to use it in your agent.
Cohere
Alibaba DashScope
Routing
Not every prompt needs your most expensive model. With our official neuron-core/router package you can route inference calls to different providers or models, transparently to the agent itself. The router also provides you with a fallback strategy to a second provider in case the primary fails due to a service down or exceeding usage limits.
First install the package:
Now use the RouterProvider class as any other provider in your agent class:
In the example above we use the RoundRobinRule making the router act as a load balancer between the attached AI providers. The package ships with several built-in rules including an LLM classifier to route calls to the appropriate model based on the promp difficulty score: https://github.com/neuron-core/router#difficultyrule
Custom Http Client
Providers use an HTTP client to communicate with the remote service. You can customize the configuration of the HTTP client explicitly passing an instance with custom constructor parameters, like timeout, custom headers, etc.
Implement a custom provider
If you want to create a new provider you have to implement the AIProviderInterface interface:
The chat method should contains the call the underlying LLM. If the provider doesn't support tools and function calls, you can implement it with a placeholder.
This is the basic template for a new AI provider implementation.
After creating your own implementation you can use it in the agent:
We strongly recommend you to submit new provider implementations via PR on the official repository or using other Inspector.dev support channels. The new implementation can receives an important boost in its advancement by the community.
Last updated