Skip to main content

Providers Overview

Providers are implementations of core interfaces that supply specific functionality to your Stratix application. Unlike plugins, providers don't have a lifecycle and are instantiated directly when needed.

Providers vs Plugins vs Libraries

Understanding the distinction between these three types of packages is crucial:

AspectPlugins 🔌Providers 🔧Libraries 📚
PurposeExtend application with external resourcesImplement core interfacesProvide utility functions/classes
LifecycleYes (initialize → start → stop)NoNo
InterfaceImplements PluginImplements specific interfaces (e.g., LLMProvider, Container)Exports utilities
Manages ResourcesYes (databases, servers, connections)SometimesNo
RegistrationVia runtime plugin systemDirect instantiationDirect import
ExamplesPostgresPlugin, FastifyHTTPPluginAnthropicProvider, AwilixContainerUtility functions, helpers

When to Use Providers

Use providers when you need to:

  • Implement a core interface: Like LLMProvider for AI models or Container for dependency injection
  • Provide swappable implementations: Different providers for the same interface (e.g., OpenAI vs Anthropic)
  • No lifecycle management needed: The provider is instantiated when needed, not during app startup

Available Provider Categories

AI Providers

Implementations of the LLMProvider interface for different AI models:

Learn more about AI Providers →

Dependency Injection Providers

Implementations of the Container interface:

Learn more about DI Providers →

Validation Providers

Implementations of the Validator interface:

Learn more about Validation Providers →

Using Providers

Providers are typically instantiated directly in your code:

import { AnthropicProvider } from '@stratix/ai-anthropic';
import { AwilixContainer } from '@stratix/di-awilix';

// AI Provider - instantiated when creating an agent
const llmProvider = new AnthropicProvider({
apiKey: process.env.ANTHROPIC_API_KEY!
});

// DI Container - instantiated at app startup
const container = new AwilixContainer();

Creating Custom Providers

To create a custom provider, implement the relevant core interface:

import type { LLMProvider, ChatParams, ChatResponse } from '@stratix/core';

export class CustomLLMProvider implements LLMProvider {
readonly name = 'custom-llm';
readonly models = ['custom-model-1', 'custom-model-2'];

async chat(params: ChatParams): Promise<ChatResponse> {
// Your implementation
}

async *streamChat(params: ChatParams): AsyncIterable<ChatChunk> {
// Your streaming implementation
}

async embeddings(params: EmbeddingParams): Promise<EmbeddingResponse> {
// Your embeddings implementation
}
}

Next Steps