{"record":{"id":"e3de0ab32140b933","repo":"FlowiseAI/Flowise","slug":"invalid-json-in-the-chatopenrouter-s-baseoptions","errorCode":null,"errorMessage":"Invalid JSON in the ChatOpenRouter's BaseOptions: ${exception}","messagePattern":"Invalid JSON in the ChatOpenRouter's BaseOptions: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/chatmodels/ChatOpenRouter/ChatOpenRouter.ts","lineNumber":171,"sourceCode":"            openAIApiKey: openRouterApiKey,\n            apiKey: openRouterApiKey,\n            streaming: streaming ?? true\n        }\n\n        if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10)\n        if (topP) obj.topP = parseFloat(topP)\n        if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty)\n        if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty)\n        if (timeout) obj.timeout = parseInt(timeout, 10)\n        if (cache) obj.cache = cache\n\n        let parsedBaseOptions: any | undefined = undefined\n\n        if (baseOptions) {\n            try {\n                parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions)\n            } catch (exception) {\n                throw new Error(\"Invalid JSON in the ChatOpenRouter's BaseOptions: \" + exception)\n            }\n        }\n\n        if (basePath || parsedBaseOptions) {\n            obj.configuration = {\n                baseURL: basePath,\n                defaultHeaders: parsedBaseOptions\n            }\n        }\n\n        const multiModalOption: IMultiModalOption = {\n            image: {\n                allowImageUploads: allowImageUploads ?? false\n            }\n        }\n\n        const model = new ChatOpenRouter(nodeData.id, obj)\n        model.setMultiModalOption(multiModalOption)","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/chatmodels/ChatOpenRouter/ChatOpenRouter.ts#L153-L189","documentation":"ChatOpenRouter follows the same BaseOptions-parse pattern as ChatOpenAI. A string BaseOptions that fails JSON.parse triggers this labelled re-throw; objects pass through. The parsed value feeds defaultHeaders under configuration.","triggerScenarios":"The ChatOpenRouter node's BaseOptions field contains invalid JSON (commonly HTTP-Referer or X-Title headers for OpenRouter ranking). Reached only when baseOptions is a truthy string.","commonSituations":"Setting OpenRouter's recommended HTTP-Referer / X-Title headers with copy-pasted JSON that has single quotes, trailing commas, or unquoted keys; mixing in an Authorization header by mistake; pasting from OpenRouter docs that render quotes as typographic characters.","solutions":["Validate the BaseOptions JSON before saving.","Use the canonical OpenRouter header shape with double quotes: {\"HTTP-Referer\":\"https://yoursite.com\",\"X-Title\":\"YourApp\"}.","Avoid trailing commas and comments; do not include the Authorization header here (the node sets it from the API key).","Pass an object input when constructing programmatically."],"exampleFix":"// before\n{ HTTP-Referer: \"https://x.com\", X-Title: 'App', } // unquoted keys + trailing comma -> throws [94]\n\n// after\n{ \"HTTP-Referer\": \"https://x.com\", \"X-Title\": \"App\" }","handlingStrategy":"validation","validationCode":"function parseBaseOptions(raw) {\n  if (!raw) return undefined\n  if (typeof raw === 'object') return raw\n  try { return JSON.parse(raw) }\n  catch (e) { throw new Error(`ChatOpenRouter BaseOptions JSON invalid: ${e.message}`) }\n}\nconst parsedBaseOptions = parseBaseOptions(nodeData.inputs?.baseOptions)","typeGuard":"function isOpenRouterHeaders(v: unknown): v is { 'HTTP-Referer'?: string; 'X-Title'?: string } {\n  return typeof v === 'object' && v !== null\n}","tryCatchPattern":"try {\n  return await initChatOpenRouter(nodeData, options)\n} catch (e) {\n  if (e.message.includes(\"Invalid JSON in the ChatOpenRouter's BaseOptions\")) {\n    throw new Error('Correct BaseOptions JSON on the ChatOpenRouter node.')\n  }\n  throw e\n}","preventionTips":["Use canonical OpenRouter headers: {\"HTTP-Referer\":\"...\",\"X-Title\":\"...\"}.","JSON-lint before saving.","Do not put Authorization here; the node sets it from the API key.","Prefer object inputs in code."],"tags":["json","configuration","validation","openrouter","default-headers"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}