Moderation API return "undefined"

Have anyone run into Moderation API return “undefined”?
I’m using Firebase functions with js, openai installed and my gpt, dall e call works, but the moderation return undefined.
I tested moderation with url call it works too.
Thank you for any help

Following is my code:

 onCall(async (request, response) => {
            try {
                const mPrompt = || "No message";
                const mUser = || "Unkown User";
      `User: ${mUser} Req: ${mPrompt} `, {structuredData: true});
                const mdrResponse = await openai.moderations.create({input: mPrompt});

      `User: ${mUser} Response: ${JSON.stringify(}`);
                return {
                    resultCode: "1",
            } catch (error) {
                logger.error("OpenAI error:", error);
                return {
                    resultCode: "400",
                    errorInfo: error.toString(),

Moderations take “input” as the text you send. There is no "user: ". etc.

Extra: read all about it:

I suspect “your” code is an AI’s “code”…

        const mdrResponse = await openai.moderations.create({input: mPrompt});

This is the part calling OpenAI, and yes I do used input, user and prompt is just for my backend to log, I only pass prompt to OpenAI as input.

Here’s working Python code with presentation that also works:

import json
from openai import OpenAI
client = OpenAI()  # bad api_key = get error message

def process_dict(data):
    processed_data = {}
    for k, v in data.items():
        if '/' not in k and '-' not in k:
            if isinstance(v, float):
                processed_data[k] = f"{v:.6f}"
                processed_data[k] = v
    return processed_data

    out = client.moderations.create(input="Go kill yourself, jerk")
    cats = process_dict(out.results[0].categories.model_dump())
    cats_score = process_dict(out.results[0].category_scores.model_dump())
    print(json.dumps(cats, indent=2), json.dumps(cats_score, indent=2))
except Exception as e:
    if e.__class__ and e.message:
        print(f"{e.__class__.__name__}: {e.message}")
        raise ValueError(f"ERROR: {e}")

If you edit your first post, putting three backticks around the code (```), or pressing the preformatted text button after selecting, that would make it less of a pain to figure out what the code is.

Thanks for the preformatted text tip.
My local function and curl testing both works fine, this is more a firebase function + OpenAI issue.