Skip to content

Support custom OpenAI base URL #9

Description

@WangNingkai

Feature Request: Support custom OpenAI base URL

Description

Currently, open-mem only supports the official OpenAI API endpoint (https://api.openai.com/v1). This prevents users from using compatible third-party services like SiliconFlow (硅基流动), DeepSeek, or self-hosted OpenAI-compatible APIs.

Current Behavior

The ModelConfig interface only accepts apiKey, and the OpenAI provider is initialized without a baseURL parameter:
https://github.com/clopca/open-mem/blob/main/src/ai/provider.ts#L64-L69

case "openai": {
  const { createOpenAI } = require("@ai-sdk/openai");
  const openai = createOpenAI({ apiKey: config.apiKey });  // No baseURL option
  return openai(config.model);
}

Expected Behavior

Allow users to specify a custom base URL for OpenAI-compatible providers via:

  1. Environment variable: OPENAI_BASE_URL
  2. Configuration option in config file

Use Cases

  • SiliconFlow (硅基流动): https://api.siliconflow.cn/v1
  • DeepSeek: https://api.deepseek.com/v1
  • Self-hosted models: Custom local endpoints
  • Other OpenAI-compatible services: OpenRouter, Azure OpenAI, etc.

Proposed Solution

1. Update ModelConfig interface (provider.ts)

export interface ModelConfig {
  provider: ProviderType;
  model: string;
  apiKey?: string;
  baseURL?: string;  // Add this
}

2. Pass baseURL to createOpenAI (provider.ts)

case "openai": {
  const { createOpenAI } = require("@ai-sdk/openai");
  const openai = createOpenAI({ 
    apiKey: config.apiKey,
    baseURL: config.baseURL  // Add this
  });
  return openai(config.model);
}

3. Read from environment (config.ts)

Add OPENAI_BASE_URL environment variable support alongside existing OPENAI_API_KEY.

Alternative Considered

If adding baseURL to ModelConfig affects other providers, we could use a generic options field or provider-specific configuration.

Additional Context

The @ai-sdk/openai package already supports baseURL option: https://sdk.vercel.ai/providers/ai-sdk-providers/openai#custom-base-url
This feature would greatly benefit users in regions where OpenAI API access is restricted or expensive, allowing them to use local/cheaper alternatives while maintaining compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions