Error creating rule via API

Hello, I'm trying to explain the example of creating a rule via API that is in the documentation, but I've been getting this error:

{"statusCode":400,"error":"Bad Request","message":"Error creating rule: could not create API key - Unsupported scheme \"ApiKey\" for granting API Key"}

My code:

import requests

header = { 
    'Content-Type': 'application/json;charset=UTF-8',
    'kbn-xsrf': 'true',

data = {
         "group":"threshold met",
            "message":"alert '{{alertName}}' is active for group '{{}}':\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{params.timeWindowSize}}{{params.timeWindowUnit}}\n- Timestamp: {{}}"
   "name":"my alert"
resp ='http://XXX.XXX.XXX.XXX:5601/api/alerting/rule', headers=header, json=data)

The rule json was copied from the documentation:

Hi @Gabriel_Camara,

Welcome to the community!

I wonder if you're receiving a similar error to this issue. Can you try authorization via a token instead to see if that request is valid.

Hi, @carly.richmond thanks for the welcome and the response.

Searching for this problem I found this link you sent, but even though I received the same error, they are different situations.

As we can see above, I'm using the token for the request and I keep getting this error.
ps: I don't have SSL configuration.