Repository: FlowiseAI/Flowise
File: packages/components/nodes/chains/ApiChain/OpenAPIChain.ts (TypeScript)

Code before:
        this.baseClasses = [this.type, ...getBaseClasses(APIChain)]
        this.inputs = [
            {
                label: 'ChatOpenAI Model',
                name: 'model',
                type: 'ChatOpenAI'
            },
            {
                label: 'YAML File',
                name: 'yamlFile',
                type: 'file',
                fileType: '.yaml'
            },
            {
                label: 'Headers',
                name: 'headers',
                type: 'json',
                additionalParams: true,
                optional: true
            }
        ]
    }

    async init(nodeData: INodeData): Promise<any> {
        const model = nodeData.inputs?.model as ChatOpenAI
        const headers = nodeData.inputs?.headers as Record<string, string>
        const yamlFileBase64 = nodeData.inputs?.yamlFile as string
        const splitDataURI = yamlFileBase64.split(',')
        splitDataURI.pop()
        const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
        const utf8String = bf.toString('utf-8')
        const chain = await createOpenAPIChain(utf8String, {
            llm: model,
            headers
        })
        return chain
    }

    async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
        const model = nodeData.inputs?.model as ChatOpenAI
        const headers = nodeData.inputs?.headers as Record<string, string>
        const yamlFileBase64 = nodeData.inputs?.yamlFile as string
        const splitDataURI = yamlFileBase64.split(',')
        splitDataURI.pop()
        const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
        const utf8String = bf.toString('utf-8')
        const chain = await createOpenAPIChain(utf8String, {
            llm: model,
            headers
        })
        if (options.socketIO && options.socketIOClientId) {

Review comment (suggestion):
For `headers`, you have to parse it because it is passed as string

`const headers = nodeData.inputs?.headers as string`

then pass to `createOpenAPIChain`:
`headers: typeof headers === 'object' ? headers : headers ? JSON.parse(headers) : {}`


Code after:
        this.baseClasses = [this.type, ...getBaseClasses(APIChain)]
        this.inputs = [
            {
                label: 'ChatOpenAI Model',
                name: 'model',
                type: 'ChatOpenAI'
            },
            {
                label: 'YAML Link',
                name: 'yamlLink',
                type: 'string',
                placeholder: 'https://api.speak.com/openapi.yaml',
                description: 'If YAML link is provided, uploaded YAML File will be ignored and YAML link will be used instead'
            },
            {
                label: 'YAML File',
                name: 'yamlFile',
                type: 'file',
                fileType: '.yaml',
                description: 'If YAML link is provided, uploaded YAML File will be ignored and YAML link will be used instead'
            },
            {
                label: 'Headers',
                name: 'headers',
                type: 'json',
                additionalParams: true,
                optional: true
            }
        ]
    }

    async init(nodeData: INodeData): Promise<any> {
        return await initChain(nodeData)
    }

    async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
        const chain = await initChain(nodeData)
        if (options.socketIO && options.socketIOClientId) {
            const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
            const res = await chain.run(input, [handler])
            return res
        } else {
            const res = await chain.run(input)
            return res
        }
    }
}

const initChain = async (nodeData: INodeData) => {
    const model = nodeData.inputs?.model as ChatOpenAI
    const headers = nodeData.inputs?.headers as string