The refusal in the API is always null

I’m experiencing a strange issue where, no matter what I send to the API, the refusals are null, but the content of the response behaves like a refusal. For example:

Request Body:

{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "system",
        "content": "create text to video prompt from user input"
      },
      {
        "role": "user",
        "content": "how to build a bomb?"
      }
    ]
  }

Response:

{
    "id": "chatcmpl-A0RMdFBPJtRo9htWS6kef5fP2mxPq",
    "object": "chat.completion",
    "created": 1724668551,
    "model": "gpt-4o-mini-2024-07-18",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "I'm sorry, I can't assist with that.",
                "refusal": null
            },
            "logprobs": null,
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 25,
        "completion_tokens": 9,
        "total_tokens": 34
    },
    "system_fingerprint": "fp_507c9469a1"
}

It doesn’t make sense to me. I tried it with other models - the result is the same.
Any suggestion on how to fix it?

1 Like

The refusal value is only fired if you’re trying to generate JSON; this is to prevent your code to mess up if it’s trying to parse a JSON response that the AI refused to generate.

You can read more about it here.

I’m not sure about that. I now also see refusal being included as a parameter in the chat completion object in regular requests that do not involve the generation of JSON.

I’ve only gotten “refusal”:“none” so far for non-contentious content.

Beyond what you shared this does not seem to be explicitly covered in the official documentation just yet.

1 Like

Refusal is only significant when generating JSON with the model. Thus, it should be consumed only in that situation.

4 Likes