What LLM Providers Are Supported by ai-memory? A Complete Guide to the 8 Backends
ai-memory supports eight distinct LLM providers including Anthropic Claude, OpenAI GPT, Google Gemini, GitHub Copilot, OpenCode, and OpenAI-compatible endpoints such as Ollama and vLLM, accessible via both API key and OAuth authentication flows.
The ai-memory repository by akitaonrails provides a unified interface for multiple language model backends. Understanding what LLM providers are supported by ai-memory is essential for configuring the tool to work with your preferred AI service, whether you are using commercial APIs or self-hosted alternatives.
Complete List of Supported LLM Providers in ai-memory
The supported providers are defined in the ProviderChoice enum located at [crates/ai-memory-llm/src/factory.rs](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-llm/src/factory.rs#L24-L42). Each variant maps to a specific implementation crate and authentication scheme.
- Anthropic: Uses the Anthropic Messages API. Implementation in
crates/ai-memory-llm/src/anthropic.rs. RequiresANTHROPIC_API_KEY. - OpenAI: Uses the official OpenAI Chat Completions API. Implementation in
crates/ai-memory-llm/src/openai.rs. RequiresOPENAI_API_KEY. - Gemini: Uses Google Gemini (Generative Language API). Implementation in
crates/ai-memory-llm/src/gemini.rs. RequiresGEMINI_API_KEY. - OpenAICompat: Supports any OpenAI-compatible endpoint including Ollama, vLLM, and LM Studio. Implementation in
crates/ai-memory-llm/src/openai_compat.rs. Authentication via optionalLLM_API_KEY. - OpenAIOAuth: Uses the ChatGPT Responses API for ChatGPT/Codex access via OAuth. Implementation in
crates/ai-memory-llm/src/openai_oauth.rs. Stores tokens inAI_MEMORY_OAUTH_TOKEN_PATH. - Copilot: Uses GitHub Copilot Chat. Implementation in
crates/ai-memory-llm/src/copilot.rs. RequiresCOPILOT_API_KEY. - AnthropicOAuth: Uses OAuth flow for Claude subscription access. Implementation shares
crates/ai-memory-llm/src/anthropic.rswith standard Anthropic. Uses token file storage. - OpenCode: Uses the OpenCode Zen/Go cloud API (OpenAI-compatible). Implementation in
crates/ai-memory-llm/src/opencode.rs. RequiresOPENCODE_API_KEY.
How Provider Selection Works in ai-memory
ai-memory abstracts all language model backends behind the LlmProvider trait. The build_provider(config) factory function constructs an Arc<dyn LlmProvider> based on your selected ProviderChoice variant and resolved ProviderAuth credentials.
The selection logic and authentication requirements are determined by the auth_requirement() method defined in [factory.rs](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-llm/src/factory.rs#L60-L78) (lines 60-78). This method specifies whether a provider requires mandatory API keys, optional authentication, or OAuth token files.
Authentication Methods and Environment Variables
Authentication requirements vary by provider type. Commercial APIs typically require static API keys, while OAuth providers use persistent token files.
API Key-Based Providers:
ANTHROPIC_API_KEYfor AnthropicOPENAI_API_KEYfor OpenAIGEMINI_API_KEYfor GeminiCOPILOT_API_KEYfor GitHub CopilotOPENCODE_API_KEYfor OpenCode
Optional Authentication:
LLM_API_KEYfor OpenAI-compatible endpoints (keyless operation permitted for local instances)
OAuth-Based Providers:
OpenAIOAuthandAnthropicOAuthstore refresh and access tokens in the file path specified byAI_MEMORY_OAUTH_TOKEN_PATH(defaulting to$HOME/.ai-memory/token.json)
Configuring OpenAI-Compatible Providers (Ollama, vLLM, LM Studio)
The OpenAICompat variant provides flexibility for self-hosted or alternative API endpoints. Unlike commercial providers that require fixed endpoints, this provider accepts a custom base URL.
export AI_MEMORY_LLM_PROVIDER=openai-compat
export AI_MEMORY_LLM_BASE_URL=http://localhost:11434/v1
# Optional: export LLM_API_KEY=your-key if your local server requires auth
ai-memory embed --text "hello world"
This configuration works with any server implementing the OpenAI Chat Completions API format, including local Ollama instances, vLLM inference servers, and LM Studio.
Embedding Providers
Beyond chat completions, ai-memory supports separate embedding backends via the EmbedderChoice enum (defined at [factory.rs lines 108-119](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-llm/src/factory.rs#L108-L119)).
Supported embedders include:
- OpenAI (text-embedding models)
- Voyage AI
- Google (Gemini embeddings)
- OpenAI-compatible endpoints (Ollama/LM Studio for local embedding models)
Practical Configuration Examples
Example 1: Using Anthropic Claude via Environment Variables
export AI_MEMORY_LLM_PROVIDER=anthropic
export ANTHROPIC_API_KEY=sk-ant-...
ai-memory status # Verifies connectivity and model access
Example 2: OpenAI OAuth Authentication Flow
export AI_MEMORY_LLM_PROVIDER=openai-oauth
ai-memory auth login openai-oauth # One-time browser authentication
ai-memory run "Explain this codebase"
Example 3: Programmatic Provider Initialization (Rust)
use ai_memory_llm::{ProviderChoice, ProviderConfig, ProviderAuth};
let cfg = ProviderConfig {
provider: ProviderChoice::OpenAi,
model: "gpt-4o".into(),
auth: ProviderAuth::from_env().unwrap(), // Reads OPENAI_API_KEY
base_url: None,
compat_strict: true,
request_timeout_secs: 30,
};
let provider = ai_memory_llm::factory::build_provider(cfg).await?;
let response = provider.complete("Summarize repository structure").await?;
Summary
- ai-memory supports eight LLM providers through the
ProviderChoiceenum: Anthropic, OpenAI, Gemini, OpenAICompat, OpenAIOAuth, Copilot, AnthropicOAuth, and OpenCode. - Provider implementations reside in individual files under
crates/ai-memory-llm/src/(e.g.,anthropic.rs,openai.rs,gemini.rs). - Authentication is handled via the
auth_requirement()function infactory.rs, supporting API keys, optional keys, and OAuth token files. - OpenAI-compatible endpoints (Ollama, vLLM) use the
OpenAICompatvariant with configurableAI_MEMORY_LLM_BASE_URL. - The
build_provider(config)factory function instantiates the appropriate backend as anArc<dyn LlmProvider>. - Separate
EmbedderChoiceenum handles embedding models for vector operations.
Frequently Asked Questions
Does ai-memory support local LLMs like Ollama?
Yes. ai-memory supports local LLMs through the OpenAICompat provider variant. Configure it by setting AI_MEMORY_LLM_PROVIDER=openai-compat and pointing AI_MEMORY_LLM_BASE_URL to your local endpoint (e.g., http://localhost:11434/v1 for Ollama). Authentication is optional for local instances, though you may set LLM_API_KEY if your server requires it.
What is the difference between OpenAI and OpenAIOAuth providers in ai-memory?
The OpenAI variant uses standard API key authentication (OPENAI_API_KEY) for direct API access, while OpenAIOAuth uses OAuth 2.0 flows to authenticate against ChatGPT/Codex subscriptions. OAuth stores tokens in AI_MEMORY_OAUTH_TOKEN_PATH and requires running ai-memory auth login initially, whereas the standard provider reads static keys from the environment immediately.
How do I switch between Anthropic Claude and Google Gemini in ai-memory?
Change the AI_MEMORY_LLM_PROVIDER environment variable to anthropic or gemini respectively, and ensure the corresponding ANTHROPIC_API_KEY or GEMINI_API_KEY is set. The factory pattern in build_provider handles the backend instantiation automatically based on the ProviderChoice enum value defined in factory.rs.
Are embedding models configurable separately from chat models in ai-memory?
Yes. Embeddings use a separate EmbedderChoice enum (defined in factory.rs lines 108-119) that includes OpenAI, Voyage, Google, and OpenAI-compatible options. This allows you to use OpenAI GPT-4 for chat while using Ollama-hosted embedding models for vector storage, or any other combination of providers.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →