AxilJS AI Providers: OpenAI, Anthropic, Gemini and Ollama
Configure OpenAI, Anthropic, Gemini, and Ollama with AxilJS for TypeScript and Node.js AI applications using a unified API for completions, streaming, and embeddings.
AxilJS AI Providers
AxilJS provides a unified AI provider interface for connecting TypeScript and Node.js applications to multiple large language model (LLM) providers.
The @axiljs/ai package currently provides integrations for OpenAI, Anthropic, Gemini, and Ollama. All providers expose the same core AI operations, allowing application code to use complete(), stream(), and embed() consistently.
Supported AI Providers
AxilJS supports the following providers:
| Provider | AxilJS Provider | Primary configuration |
|---|---|---|
| OpenAI | OpenAIProvider | API key |
| Anthropic | AnthropicProvider | API key |
| Gemini | GeminiProvider | API key |
| Ollama | OllamaProvider | Local model |
The provider abstraction keeps your application code independent from the underlying LLM provider.
OpenAI
Use OpenAIProvider to connect AxilJS to OpenAI models.
The API key is read from the OPENAI_API_KEY environment variable in this example.
Anthropic
Use AnthropicProvider to connect your application to Anthropic models.
The provider uses the ANTHROPIC_API_KEY environment variable for authentication in this configuration.
Gemini
Use GeminiProvider to connect AxilJS to Gemini.
The example reads the Gemini API credential from the GOOGLE_API_KEY environment variable.
Ollama
AxilJS also supports Ollama for local AI model execution.
Unlike the hosted providers above, the example configures Ollama with a local model name instead of an API key.
This makes the Ollama provider useful when an application needs to work with locally hosted LLMs.
Unified AI API
All supported providers expose the same core operations:
This means the application can interact with the configured provider through a consistent API.
For example, a completion request can use the same interface regardless of which supported provider is configured:
The provider-specific configuration is isolated when the ai instance is created.
Provider Abstraction
The AxilJS provider architecture separates application logic from the underlying LLM service.
Your application can therefore use the common AI API while the provider implementation handles communication with the selected LLM service.
Choosing a Provider
Use OpenAI, Anthropic, or Gemini when your application is designed around a hosted LLM provider.
Use Ollama when you want to run a supported model locally.
Because the application interacts with the provider through the common AxilJS API, changing providers does not require changing the basic complete(), stream(), or embed() calls.
AI Provider Error Handling
AxilJS catches provider HTTP errors so that a failed AI provider request does not cause the server itself to crash.
Tip
Keep provider credentials in environment variables rather than hard-coding API keys in application source code.