The 'max_tokens' parameter must be set to 30

In the KodeKloud Engineer task, AI Level 1 Certification Exam,
I am seeing the following error for all tasks:
The ‘max_tokens’ parameter must be set to 30.

I just checked it, and it’s working properly. Did you run python commenter.py? Did it run successfully on your side?

Yes, as you can see from the terminal in the screenshot I shared, the Python code ran successfully.

Hi @phal

Please try again and let me know if the issue still persists.

The issue persists

Hi @phal

I was still able to pass Question 4. Please review my solution, compare it with your answer, and try again.

commenter.py:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
    base_url=os.environ.get("OPENAI_API_BASE"),
)

def generate_comment(code_snippet: str) -> str:
    prompt = (
        "Generate a clear, one-line Python comment or docstring "
        "explaining the purpose of the following code:\n\n"
        f"{code_snippet}"
    )

    response = client.chat.completions.create(
        model="openai/gpt-4.1-mini",
        messages=[
            {"role": "user", "content": prompt}
        ],
        max_tokens=30,
        temperature=0.2,
    )

    comment = response.choices[0].message.content.strip()
    print(comment)
    return comment


snippet = """def calculate_area(length, width):
    return length * width
"""

generate_comment(snippet)

I was finally able to get through this issue. There are two changes that I made to my previous code.

  1. The max_tokens= and temperature= needs to be exact. No max_tokens = (note the space around ‘=’) or temperature = 0, when specified as 0.0, or an extra comma at the end.
  2. The input string was sent directly in the function call, except for commenter.py.

All of these may not be the core issue, but the tests passed after changing these. Also, none of these are Python syntax errors, but I am assuming that underneath, the evaluator is somewhere doing output code comparison.

Thanks for your feedback, let me take a look about it.

Yep, it looks like a valid issue. Let me inform the team so they can take a look.