automem icon indicating copy to clipboard operation
automem copied to clipboard

Add support for custom LLM base URL (OPENAI_BASE_URL) for classification/enrichment

Open BasuruK opened this issue 9 months ago โ€ข 2 comments

Feature Request: Support custom LLM base URL for classification and enrichment

Hi Jack!

Currently, the embedding provider supports custom base URLs via OPENAI_BASE_URL and EMBEDDING_MODEL, but the LLM used for classification/enrichment (CLASSIFICATION_MODEL) is hardcoded to use OpenAI's API directly without a base URL option.

Use Case

Many users want to use OpenAI-compatible providers (OpenRouter, LiteLLM, vLLM, etc.) for both embeddings AND LLM calls to leverage volume discounts or specific model deployments.

Current Behavior

  • Embeddings: โœ… Supports OPENAI_BASE_URL and EMBEDDING_MODEL (in automem/embedding/openai.py)
  • LLM (classification): โŒ Only uses OpenAI API directly via CLASSIFICATION_MODEL

Code References

1. Model configuration - automem/config.py (lines 74-76):

Model configuration
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "text-embedding-3-large")
CLASSIFICATION_MODEL = os.getenv("CLASSIFICATION_MODEL", "gpt-4o-mini")

2. OpenAI client initialization - automem/service_runtime.py (lines 11-28):

def init_openai(
*,
state: Any,
logger: Any,
openai_cls: Any,
get_env_fn: Callable[[str], str | None],
) -> None:
...
api_key = get_env_fn("OPENAI_API_KEY")
...
state.openai_client = openai_cls(api_key=api_key) # No base_url support!

Expected Behavior

Add support for OPENAI_BASE_URL for the LLM client (same env var used by embeddings). Users can then set:

  • OPENAI_BASE_URL=https://openrouter.ai/api/v1
  • CLASSIFICATION_MODEL=gpt-4o-mini (or any OpenRouter-compatible model)

This would allow routing through OpenRouter or other OpenAI-compatible providers for:

  • Entity extraction
  • Summary generation
  • Memory classification

Suggested Implementation

In automem/service_runtime.py, modify the OpenAI client initialization to support base_url:

def init_openai(...) -> None:
...
api_key = get_env_fn("OPENAI_API_KEY")
base_url = get_env_fn("OPENAI_BASE_URL") # Add this

client_kwargs = {"api_key": api_key}
if base_url:
client_kwargs["base_url"] = base_url

state.openai_client = openai_cls(**client_kwargs) # Pass base_url

BasuruK avatar Feb 21 '26 08:02 BasuruK

๐Ÿ”— Related PRs

verygoodplugins/automem#56 - feat(embedding): add Ollama embedding provider and expand docs [merged] verygoodplugins/automem#76 - feat(embedding): support OpenAI-compatible providers via OPENAI_BASE_URL [merged]


๐Ÿ“ Issue Planner

Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

  • [ ] Create Plan

๐Ÿงช Issue enrichment is currently in open beta.

You can configure auto-planning by selecting labels in the issue_enrichment configuration.

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

๐Ÿ’ฌ Have feedback or questions? Drop into our discord!

coderabbitai[bot] avatar Feb 21 '26 08:02 coderabbitai[bot]