mem0ai/mem0 · error · Error

Invalid provider

Error message

Invalid provider

What it means

Mem0AITextGenerator's constructor in provider-response-provider.ts instantiates the real underlying LLM via a switch over the provider name and falls through to `throw new Error("Invalid provider")` when the name matches no case. This is the last-line dispatch guard: it fires when the selector's supportedProviders list accepted a name that the constructor's switch does not actually handle.

Source

Thrown at integrations/vercel-ai-sdk/src/provider-response-provider.ts:67

                    apiKey: config?.apiKey,
                    ...provider_config as AnthropicProviderSettings,
                }).languageModel(modelId);
                break;
            case "groq":
                this.languageModel = createGroq({
                    apiKey: config?.apiKey,
                    ...provider_config as GroqProviderSettings,
                })(modelId);
                break;
            case "google":
            case "gemini":
                this.languageModel = createGoogleGenerativeAI({
                    apiKey: config?.apiKey,
                    ...provider_config as GoogleGenerativeAIProviderSettings,
                })(modelId);
                break;
            default:
                throw new Error("Invalid provider");
        }
    }

    async doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult> {
        const result = await this.languageModel.doGenerate(options);
        return result as LanguageModelV3GenerateResult;
    }

    async doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult> {
        const result = await this.languageModel.doStream(options);
        return result as LanguageModelV3StreamResult;
    }
}

export type ProviderSettings = OpenAIProviderSettings | CohereProviderSettings | AnthropicProviderSettings | GroqProviderSettings | GoogleGenerativeAIProviderSettings;
export default Mem0AITextGenerator;

View on GitHub (pinned to 001c235229)

Solutions

  1. Pin the integration to one version where the selector list and constructor switch agree.
  2. Use one of the explicitly wired providers: openai, anthropic, groq, or google/gemini.
  3. If you forked or patched supportedProviders, add the matching case to this switch too.
  4. Report the version-skew bug upstream with the provider string that reproduced it.

Example fix

// before
const provider = createMem0Provider({ provider: "mistral" }); // may pass selector, fail here

// after
const provider = createMem0Provider({ provider: "openai" });
Defensive patterns

Strategy: validation

Validate before calling

const WIRED_PROVIDERS = new Set(['openai', 'anthropic', 'groq', 'google', 'gemini']);
function assertProviderWired(p: string): void {
  if (!WIRED_PROVIDERS.has(p)) throw new Error(`Provider '${p}' not wired in provider-response-provider`);
}

Type guard

const isWiredProvider = (p: unknown): p is 'openai' | 'anthropic' | 'groq' | 'google' | 'gemini' =>
  typeof p === 'string' && ['openai', 'anthropic', 'groq', 'google', 'gemini'].includes(p);

Try / catch

try {
  model = new Mem0AITextGenerator(modelId, config, providerConfig);
} catch (e) {
  if ((e as Error).message === 'Invalid provider') {
    throw new Error(`Provider '${config.provider}' passed the selector but is not wired; pin matching package versions`);
  }
  throw e;
}

Prevention

When it happens

Trigger: config.provider passes Mem0ClassSelector.supportedProviders but the switch in this file only wires openai/anthropic/groq/google(gemini) — e.g. a version skew between the selector list and this switch, or a provider name that differs only by alias casing.

Common situations: Installing mismatched versions of the integration packages; adding a provider to supportedProviders via patch/fork without extending the switch; passing 'google' where the switch expects 'gemini' or vice versa (both are handled here, but aliases drift across versions).

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/af07f7fc3c36546a. Report an issue: GitHub.