FlowiseAI/Flowise · error · Error

Invalid JSON in the ChatOpenRouter's BaseOptions: ${exceptio

Error message

Invalid JSON in the ChatOpenRouter's BaseOptions: ${exception}

What it means

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.

Source

Thrown at packages/components/nodes/chatmodels/ChatOpenRouter/ChatOpenRouter.ts:171

            openAIApiKey: openRouterApiKey,
            apiKey: openRouterApiKey,
            streaming: streaming ?? true
        }

        if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10)
        if (topP) obj.topP = parseFloat(topP)
        if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty)
        if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty)
        if (timeout) obj.timeout = parseInt(timeout, 10)
        if (cache) obj.cache = cache

        let parsedBaseOptions: any | undefined = undefined

        if (baseOptions) {
            try {
                parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions)
            } catch (exception) {
                throw new Error("Invalid JSON in the ChatOpenRouter's BaseOptions: " + exception)
            }
        }

        if (basePath || parsedBaseOptions) {
            obj.configuration = {
                baseURL: basePath,
                defaultHeaders: parsedBaseOptions
            }
        }

        const multiModalOption: IMultiModalOption = {
            image: {
                allowImageUploads: allowImageUploads ?? false
            }
        }

        const model = new ChatOpenRouter(nodeData.id, obj)
        model.setMultiModalOption(multiModalOption)

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Validate the BaseOptions JSON before saving.
  2. Use the canonical OpenRouter header shape with double quotes: {"HTTP-Referer":"https://yoursite.com","X-Title":"YourApp"}.
  3. Avoid trailing commas and comments; do not include the Authorization header here (the node sets it from the API key).
  4. Pass an object input when constructing programmatically.

Example fix

// before
{ HTTP-Referer: "https://x.com", X-Title: 'App', } // unquoted keys + trailing comma -> throws [94]

// after
{ "HTTP-Referer": "https://x.com", "X-Title": "App" }
Defensive patterns

Strategy: validation

Validate before calling

function parseBaseOptions(raw) {
  if (!raw) return undefined
  if (typeof raw === 'object') return raw
  try { return JSON.parse(raw) }
  catch (e) { throw new Error(`ChatOpenRouter BaseOptions JSON invalid: ${e.message}`) }
}
const parsedBaseOptions = parseBaseOptions(nodeData.inputs?.baseOptions)

Type guard

function isOpenRouterHeaders(v: unknown): v is { 'HTTP-Referer'?: string; 'X-Title'?: string } {
  return typeof v === 'object' && v !== null
}

Try / catch

try {
  return await initChatOpenRouter(nodeData, options)
} catch (e) {
  if (e.message.includes("Invalid JSON in the ChatOpenRouter's BaseOptions")) {
    throw new Error('Correct BaseOptions JSON on the ChatOpenRouter node.')
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/e3de0ab32140b933. Report an issue: GitHub.