{"record":{"id":"008e964d94f236c6","repo":"mem0ai/mem0","slug":"either-a-client-or-url-and-token-must-be-provided","errorCode":null,"errorMessage":"Either a client or url and token must be provided.","messagePattern":"Either a client or url and token must be provided\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/upstash_vector.ts","lineNumber":27,"sourceCode":"  token?: string;\n  /** Pre-configured Upstash Vector client instance (typed as `any` to keep\n   *  the optional driver's types out of the published type declarations). */\n  client?: any;\n}\n\ntype UpstashMetadata = Record<string, unknown>;\n\nexport class UpstashVector implements VectorStore {\n  private client!: Index<UpstashMetadata>;\n  private readonly config: UpstashVectorConfig;\n  private readonly collectionName: string;\n\n  constructor(config: UpstashVectorConfig) {\n    if (!config.collectionName) {\n      throw new Error(\"collectionName is required for Upstash Vector.\");\n    }\n    if (!config.client && !(config.url && config.token)) {\n      throw new Error(\"Either a client or url and token must be provided.\");\n    }\n\n    this.config = config;\n    this.collectionName = config.collectionName;\n  }\n\n  /**\n   * Lazily construct (or reuse) the Upstash Vector client, importing the\n   * optional `@upstash/vector` peer only when the store is first used so\n   * consumers that never touch Upstash Vector don't need it installed.\n   */\n  private async ensureClient(): Promise<void> {\n    if (this.client) return;\n\n    const config = this.config;\n    if (config.client) {\n      this.client = config.client;\n    } else {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/upstash_vector.ts#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nnew Memory({ vectorStore: { provider: 'upstash_vector', config: { collectionName: 'mem', url: process.env.UPSTASH_URL } } });\n\n// after\nnew Memory({ vectorStore: { provider: 'upstash_vector', config: { collectionName: 'mem', url: process.env.UPSTASH_VECTOR_REST_URL!, token: process.env.UPSTASH_VECTOR_REST_TOKEN! } } });","handlingStrategy":"validation","validationCode":"if (!config.client && !(config.url && config.token)) throw new Error('Upstash Vector needs either config.client or both url and token');","typeGuard":"const hasUpstashCredentials = (cfg: { client?: unknown; url?: string; token?: string }): boolean => Boolean(cfg.client || (cfg.url && cfg.token));","tryCatchPattern":"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; }","preventionTips":["Set UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN as a pair","Add a boot-time env checker listing missing variables"],"tags":["upstash","config","credentials","validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}