Clouldflare AI API is throwing authentication issue

For Workes & Pages, what is the name of the domain?

arcadix.com

What is the error number?

403

What is the error message?

b’{“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]}\n’

What is the issue or error you’re encountering

I am trying to access the cloudflare AI model from python getting the access denied

What are the steps to reproduce the issue?

have this code in the python file.
import asyncio

from cloudflareai import (
CloudflareAI,
AiTextToImageModels,
AiTextGenerationModels,
)

async def main():
ai = CloudflareAI(
Cloudflare_API_Key=<Cloudflare_API_Key>,
Cloudflare_Account_Identifier=<Cloudflare_Account_Identifier>,
)

text = await ai.TextGeneration(
    user_prompt="You are helpful",
    system_prompt="Hello, my name is Alex",
    model_name=AiTextGenerationModels.CODE_LLAMA_7B,
)

print(text.text) # returns string

print(text.status_code)

asyncio.run(main())
intall the python packages “asyncio”, :cloudflareai
run the code using
python filename.py

Screenshot of the error

The error seems like a standard message for authentication failure, which could be due to several possible issues:

  1. Incorrect Account/Zone ID: Double-check that the IDs are correct.
  2. API Token Issues: Ensure that the token has the correct permissions for the intended actions.
  3. Missing X-Auth-Email Header: If using the X-Auth-Key header, make sure it’s included.
  4. Insufficient Privileges: Verify that your token has adequate privileges for the action.

I recommend testing with a direct API call (e.g., using curl or Postman) to confirm that your credentials are set up properly. If the direct call works, the issue could be due to how your Python script handles the inputs—ensure it’s correctly passing in the necessary credentials and parameters.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.