Providers
Register and manage LLM providers — OpenAI, Anthropic, or any OpenAI-compatible API.
Nexus supports multiple LLM providers simultaneously. Each provider implements a unified interface for chat completions, streaming, embeddings, and model listing.
Provider Interface
Every provider implements provider.Provider:
type Provider interface {
Name() string
Complete(ctx context.Context, req *CompletionRequest) (*CompletionResponse, error)
Stream(ctx context.Context, req *CompletionRequest) (Stream, error)
Embed(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
Models(ctx context.Context) ([]Model, error)
Capabilities() Capabilities
}Built-in Providers
OpenAI
import "github.com/xraph/nexus/providers/openai"
gw := nexus.New(
nexus.WithProvider(openai.New(os.Getenv("OPENAI_API_KEY"))),
)Anthropic
import "github.com/xraph/nexus/providers/anthropic"
gw := nexus.New(
nexus.WithProvider(anthropic.New(os.Getenv("ANTHROPIC_API_KEY"))),
)OpenAI-Compatible
For any API that follows the OpenAI specification (Ollama, Together AI, Groq, etc.):
import "github.com/xraph/nexus/providers/opencompat"
gw := nexus.New(
nexus.WithProvider(opencompat.New("groq",
opencompat.WithBaseURL("https://api.groq.com/openai/v1"),
opencompat.WithAPIKey(os.Getenv("GROQ_API_KEY")),
)),
)Multiple Providers
Register as many providers as you need. The router decides which one handles each request:
gw := nexus.New(
nexus.WithProvider(openai.New(openaiKey)),
nexus.WithProvider(anthropic.New(anthropicKey)),
nexus.WithProvider(opencompat.New("ollama",
opencompat.WithBaseURL("http://localhost:11434/v1"),
)),
)Capabilities
Each provider reports what it supports:
caps := provider.Capabilities()
caps.Chat // chat completions
caps.Stream // streaming responses
caps.Embed // embeddings
caps.Vision // image inputs
caps.Tools // tool/function calling
caps.Thinking // extended thinking (Anthropic)Provider Health
Nexus tracks provider health automatically — success/failure counts, average latency, and P99 latency. Use this data for smart routing decisions:
nexus.WithHealthTracker(provider.NewMemoryHealthTracker())