maritaca-ai / maritalk-api

Code and documentation for the MariTalk API
https://docs.maritaca.ai
MIT License
240 stars 12 forks source link

Unauthorized 401 Error Despite Using a New API Key #9

Closed willianfco closed 9 months ago

willianfco commented 10 months ago

Hello team,

I've been trying to use your API, but I consistently encounter a "401 Client Error - Unauthorized for URL" even though I'm using a brand new key.

ZanezZephyrs commented 10 months ago

hi @willianfco.

Could provide more details about how you are trying to perform the request? Especially could share the prompt and parameters you are trying to use?

Also, are you able to use the web interface normally?

willianfco commented 10 months ago

Hello @ZanezZephyrs!

The web interface is working properly.

As for the prompt, I've been using the following python script to just to check the accessibility but any request is actually raising the 401 error.


def check_api_accessibility():
    key = os.getenv("MARITALK_KEY")
    if not key:
        print("Error: MARITALK_KEY not found in environment variables.")
        return False

    model = maritalk.MariTalk(key=key)

    try:
        mensagem = "Test message"
        response = model.generate(
            mensagem,
            chat_mode=False,
            do_sample=True,
            max_tokens=15,
            temperature=0.1,
            top_p=0.15,
        )
        if response:
            print("API is accessible!")
            return True
        else:
            print("Error: API response is empty.")
            return False
    except Exception as e:
        print(f"Error accessing API: {e}")
        return False

if __name__ == "__main__":
    success = check_api_accessibility()
    if not success:
        exit(1)
ZanezZephyrs commented 10 months ago

hi @willianfco.

Everything looks correct regarding the code. I also double checked your account and everything seems in order too. My best guess is that the key string in the environment variable might be missformated, maybe with some extra white spaces? please double check if the string is in the expected format.

In the current version ( will probably not be the case soon)

Key=" YOUR_KEY" #  extra whitespace in front leads to 401 error 

Key ="YOUR_KEY" # with no extra whitespace everything should work fine

If the API still does not work for you, please send us an email at info@maritaca.ai sharing more details, including the API key that you are trying to use, and i will be able to further help you there.

willianfco commented 10 months ago

Hi @ZanezZephyrs, sorry for the delayed answer but I solved it by generating a new API Key. The previous one had "$" in it and I suspect it was the source of the problem.