With Neuron you can switch between LLM providers with just one line of code, without any impact on your agent implementation.
Anthropic
namespaceApp\Neuron;
use NeuronAI\Agent\Agent;
use NeuronAI\Chat\Messages\UserMessage;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
classMyAgentextendsAgent
{
protectedfunctionprovider(): AIProviderInterface
{
returnnew Anthropic(
key:'ANTHROPIC_API_KEY',
model:'ANTHROPIC_MODEL',
parameters:[],// Add custom params (temperature, logprobs, etc)
);
}
}
$message=MyAgent::make()
->chat(newUserMessage("Hi!"))
->getMessage();
echo$message->getContent();
// Hi, how can I help you today?Anthropic Prompt Cache
Anthropic provider expose a dedicated method systemPromptBlocks() to leverage system prompt cache. Instead of using the instructions() method in the Agent class, you can pass prompts definition directly to the provider instance with cache type definition.
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 Vertex AI
To use this provider you need to install the goole auth composer package:
Below you can find the syntax to use it 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.
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
