hex_ai_llm library
Hex AI LLM — unified LLM provider layer.
Provides a clean abstraction over multiple AI providers (Anthropic, OpenAI, Google, DeepSeek, etc.) with streaming, tool calling, and cost tracking.
Architecture
┌─────────────────────────────────────────────┐
│ LlmProvider (interface) │
├─────────────────────────────────────────────┤
│ AnthropicProvider │ OpenAIProvider │ Google │
├─────────────────────────────────────────────┤
│ ProviderRegistry / ModelRegistry │
├─────────────────────────────────────────────┤
│ SseParser / ApiClient │
└─────────────────────────────────────────────┘
Classes
- AnthropicProvider
-
Anthropic Messages API provider — mirrors hex-ai
anthropicProvider. - ApiClient
- HTTP API client with timeout, retry, and streaming support.
- BuiltInModels
- All built-in models from mainstream providers.
- CostCalculator
-
Token cost calculator — mirrors hex-ai
calculateCost(). - CredentialStore
-
Abstract credential store — mirrors hex-ai
CredentialStore. - InMemoryCredentialStore
- In-memory credential store (for testing / development).
- LlmContext
-
Context for a chat completion request — mirrors hex-ai
Context. - LlmProvider
-
Unified LLM provider interface — mirrors hex-ai
ProviderStreams. - LlmResult
-
Result from a complete (non-streaming) call — mirrors hex-ai
AssistantMessage. - LlmStreamOptions
-
Stream options — mirrors hex-ai
StreamOptions. - MessageId
- Simple ID generator for message IDs.
- ModelRegistry
- Model registry with search and filtering capabilities.
- OpenAICompatibleProvider
- OpenAI-compatible provider for non-OpenAI services.
- OpenAIProvider
-
OpenAI-compatible API provider — mirrors hex-ai
openaiProvider. - ProviderCatalog
- Single source of truth for built-in providers and models.
- ProviderCatalogEntry
- Catalog entry for a single provider and its built-in models.
- ProviderRegistry
-
Provider registry - mirrors hex-ai
Models/MutableModels. - SecureCredentialStore
- Credential store backed by flutter_secure_storage.
- SseEvent
- A single SSE event.
- SseParser
- Server-Sent Events parser.
- StreamUtils
- Utility functions for working with stream events.
- Uuid
- Simple UUID generator for message IDs.
Exceptions / Errors
- LlmApiError
- API-level error (non-2xx status code).
- LlmNetworkError
- Network-level error from the LLM API client.