FlowiseAI/Flowise · error · Error

Invalid JSON in the BaseOptions: ${exception}

Error message

Invalid JSON in the BaseOptions: ${exception}

What it means

Thrown by ChatCometAPI.init() (line 161) when baseOptions is a string that fails JSON.parse. When baseOptions is provided and is not already an object, the code attempts JSON.parse; on SyntaxError it is caught and re-thrown with the original parse exception appended. Note the converter also strips a forbidden 'baseURL' key before parsing succeeds.

Source

Thrown at packages/components/nodes/chatmodels/ChatCometAPI/ChatCometAPI.ts:161

        }

        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 (cache) obj.cache = cache

        let parsedBaseOptions: any | undefined = undefined

        if (baseOptions) {
            try {
                parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions)
                if (parsedBaseOptions.baseURL) {
                    console.warn("The 'baseURL' parameter is not allowed when using the ChatCometAPI node.")
                    parsedBaseOptions.baseURL = undefined
                }
            } catch (exception) {
                throw new Error('Invalid JSON in the BaseOptions: ' + exception)
            }
        }

        const model = new ChatOpenAI({
            ...obj,
            configuration: {
                baseURL: this.baseURL,
                ...parsedBaseOptions
            }
        })
        return model
    }
}

module.exports = { nodeClass: ChatCometAPI_ChatModels }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Pass baseOptions as a real JSON object (double-quoted keys, no trailing commas): {"timeout": 30000}.
  2. If unsure, leave baseOptions empty; it is optional (additionalParams: true).
  3. Validate the string with JSON.parse in the browser console / a linter before saving the node.

Example fix

// before (throws): baseOptions = "{'timeout': 30000,}"  // single quotes + trailing comma
// after:           baseOptions = "{\"timeout\": 30000}"
Defensive patterns

Strategy: validation

Validate before calling

function parseBaseOptionsSafe(raw: unknown): unknown | undefined {
  if (raw == null || typeof raw === 'object') return raw
  if (typeof raw !== 'string') return undefined
  try { return JSON.parse(raw) } catch { return undefined }
}
const parsed = parseBaseOptionsSafe(nodeData.inputs?.baseOptions)
if (nodeData.inputs?.baseOptions && parsed === undefined) {
  throw new Error('baseOptions must be valid JSON')
}

Type guard

function isPlainObject(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null && !Array.isArray(v)
}

Try / catch

try {
  return await chatCometAPI.init(nodeData, '', options)
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Invalid JSON in the BaseOptions')) {
    // highlight the baseOptions field and show a JSON hint
  }
  throw e
}

Prevention

When it happens

Trigger: nodeData.inputs.baseOptions is a malformed JSON string (trailing comma, single quotes, unquoted keys, dangling brace, etc.).

Common situations: User typed baseOptions as a free-form string instead of a JSON object, copy-pasted JS object literal syntax instead of JSON, or left an unfinished fragment.

Understand the failure class

Related errors


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