mem0ai/mem0 · error · Error
Either a client or url and token must be provided.
Error message
Either a client or url and token must be provided.
What it means
The Upstash Vector store needs either a pre-built client (config.client) or both a URL and a token (config.url + config.token) to reach the Upstash REST API. The constructor throws when neither complete option is provided — e.g. only a url, or only a token.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/upstash_vector.ts:27
token?: string;
/** Pre-configured Upstash Vector client instance (typed as `any` to keep
* the optional driver's types out of the published type declarations). */
client?: any;
}
type UpstashMetadata = Record<string, unknown>;
export class UpstashVector implements VectorStore {
private client!: Index<UpstashMetadata>;
private readonly config: UpstashVectorConfig;
private readonly collectionName: string;
constructor(config: UpstashVectorConfig) {
if (!config.collectionName) {
throw new Error("collectionName is required for Upstash Vector.");
}
if (!config.client && !(config.url && config.token)) {
throw new Error("Either a client or url and token must be provided.");
}
this.config = config;
this.collectionName = config.collectionName;
}
/**
* Lazily construct (or reuse) the Upstash Vector client, importing the
* optional `@upstash/vector` peer only when the store is first used so
* consumers that never touch Upstash Vector don't need it installed.
*/
private async ensureClient(): Promise<void> {
if (this.client) return;
const config = this.config;
if (config.client) {
this.client = config.client;
} else {View on GitHub (pinned to 001c235229)
Solutions
- Provide both values: config: { collectionName, url: process.env.UPSTASH_VECTOR_REST_URL!, token: process.env.UPSTASH_VECTOR_REST_TOKEN! }.
- Or pass an existing @upstash/vector Index instance via config.client.
- Verify both environment variables are actually set in the runtime (console.log presence, not values).
Example fix
// before
new Memory({ vectorStore: { provider: 'upstash_vector', config: { collectionName: 'mem', url: process.env.UPSTASH_URL } } });
// after
new Memory({ vectorStore: { provider: 'upstash_vector', config: { collectionName: 'mem', url: process.env.UPSTASH_VECTOR_REST_URL!, token: process.env.UPSTASH_VECTOR_REST_TOKEN! } } }); Defensive patterns
Strategy: validation
Validate before calling
if (!config.client && !(config.url && config.token)) throw new Error('Upstash Vector needs either config.client or both url and token'); Type guard
const hasUpstashCredentials = (cfg: { client?: unknown; url?: string; token?: string }): boolean => Boolean(cfg.client || (cfg.url && cfg.token)); Try / catch
try { new Memory({ vectorStore: { provider: 'upstash_vector', config } }); } catch (e) { if (e instanceof Error && e.message.includes('client or url and token')) { /* check env var names */ } else throw e; } Prevention
- Set UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN as a pair
- Add a boot-time env checker listing missing variables
When it happens
Trigger: config with url but no token, token but no url, or an empty client; typos in key names (UPSTASH_VECTOR_REST_URL/TOKEN env vars read manually but misnamed); passing a client that is undefined because a dynamic import failed.
Common situations: Partially copied env vars (one of the Upstash pair missing); renaming from the official @upstash/vector SDK's UPSTASH_VECTOR_REST_URL/UPSTASH_VECTOR_REST_TOKEN pair and missing one; test setups that stub the client incorrectly.
Related errors
- collectionName is required for Upstash Vector.
- Either a client or URL and token must be provided.
- Unknown LLM provider: ${providerId}
- Unknown embedder provider: ${providerId}
- ${label} has unknown keys: ${unknown.join(", ")}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/008e964d94f236c6.
Report an issue: GitHub.