FlowiseAI/Flowise · warning · InternalFlowiseError

Error: apikeyController.createApiKey - keyName not provided!

Error message

Error: apikeyController.createApiKey - keyName not provided!

What it means

createApiKey handler requires req.body.keyName to be truthy. If req.body is undefined or keyName is missing/empty, it throws InternalFlowiseError with HTTP 412 PRECONDITION_FAILED. This is a client-input guard run before permissions validation and before the service creates the key.

Source

Thrown at packages/server/src/controllers/apikey/index.ts:27

const getAllApiKeys = async (req: Request, res: Response, next: NextFunction) => {
    try {
        const user = req.user as LoggedInUser

        if (req.query?.type === 'organization' && user.isOrganizationAdmin)
            return res.status(StatusCodes.OK).json(await apikeyService.getAllApiKeysByOrganization(user.activeOrganizationId))

        const { page, limit } = getPageAndLimitParams(req)
        const apiResponse = await apikeyService.getAllApiKeys(user, page, limit)
        return res.status(StatusCodes.OK).json(apiResponse)
    } catch (error) {
        next(error)
    }
}

const createApiKey = async (req: Request, res: Response, next: NextFunction) => {
    try {
        if (typeof req.body === 'undefined' || !req.body.keyName) {
            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
        }
        if (
            !req.body.permissions ||
            !Array.isArray(req.body.permissions) ||
            req.body.permissions.length === 0 ||
            !req.body.permissions.every((p: any) => typeof p === 'string')
        ) {
            throw new InternalFlowiseError(
                StatusCodes.PRECONDITION_FAILED,
                `Error: apikeyController.createApiKey - permissions must be an array of strings!`
            )
        }
        const user = req.user as LoggedInUser
        const apiResponse = await apikeyService.createApiKey(user, req.body.keyName, req.body.permissions)
        return res.json(apiResponse)
    } catch (error) {
        next(error)
    }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Send a non-empty 'keyName' string in the JSON request body.
  2. Validate the form client-side and disable submit until keyName is provided.
  3. Ensure express.json() middleware is active so req.body is parsed.
  4. Return the field name in the client error display so the user knows what to fix.

Example fix

// before
if (typeof req.body === 'undefined' || !req.body.keyName) {
    throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
}

// after
if (!req.body?.keyName || typeof req.body.keyName !== 'string') {
    throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'keyName is required and must be a non-empty string')
}
Defensive patterns

Strategy: validation

Validate before calling

function requireKeyName(body: any): asserts body is { keyName: string } {
    if (!body || typeof body.keyName !== 'string' || !body.keyName) {
        throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'keyName is required')
    }
}
requireKeyName(req.body)

Type guard

function hasKeyName(body: unknown): body is { keyName: string } {
    return typeof (body as any)?.keyName === 'string' && (body as any).keyName.length > 0
}

Try / catch

// The handler already routes through next(error); a global error handler should map
// InternalFlowiseError.statusCode to the HTTP status. No additional catch needed if the
// error middleware respects statusCode.

Prevention

When it happens

Trigger: POST to the create-api-key endpoint with a body lacking keyName (omitted, empty string, or null), or with no body at all.

Common situations: Frontend form submitted with the key-name field blank. Client sends permissions but forgets the name. Body-parsing middleware not mounted so req.body is undefined.

Related errors


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