AI Platform

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.

3 min readDocumentationEdit this page

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:

ProviderAxilJS ProviderPrimary configuration
OpenAIOpenAIProviderAPI key
AnthropicAnthropicProviderAPI key
GeminiGeminiProviderAPI key
OllamaOllamaProviderLocal model

The provider abstraction keeps your application code independent from the underlying LLM provider.

OpenAI

Use OpenAIProvider to connect AxilJS to OpenAI models.

typescript
import { OpenAIProvider } from '@axiljs/ai'
 
const ai = new OpenAIProvider({
  apiKey: process.env.OPENAI_API_KEY
})

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.

typescript
import { AnthropicProvider } from '@axiljs/ai'
 
const ai = new AnthropicProvider({
  apiKey: process.env.ANTHROPIC_API_KEY
})

The provider uses the ANTHROPIC_API_KEY environment variable for authentication in this configuration.

Gemini

Use GeminiProvider to connect AxilJS to Gemini.

typescript
import { GeminiProvider } from '@axiljs/ai'
 
const ai = new GeminiProvider({
  apiKey: process.env.GOOGLE_API_KEY
})

The example reads the Gemini API credential from the GOOGLE_API_KEY environment variable.

Ollama

AxilJS also supports Ollama for local AI model execution.

typescript
import { OllamaProvider } from '@axiljs/ai'
 
const ai = new OllamaProvider({
  model: 'llama3.2'
})

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:

typescript
ai.complete()
ai.stream()
ai.embed()

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:

typescript
const result = await ai.complete({
  messages: [
    {
      role: 'user',
      content: 'What is AxilJS?'
    }
  ]
})
 
console.log(result.content)

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.

text
                    Application
                         │
                         ▼
                    @axiljs/ai
                         │
                  Provider Interface
                         │
          ┌──────────────┼──────────────┐
          ▼              ▼              ▼
       OpenAI        Anthropic        Gemini
                         │
                         └───────┐
                                 ▼
                              Ollama

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.

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY