IBM / ibm-generative-ai

IBM-Generative-AI is a Python library built on IBM's large language model REST interface to seamlessly integrate and extend this service in Python programs.
https://ibm.github.io/ibm-generative-ai/
Apache License 2.0
245 stars 101 forks source link

Invalid or missing JWT token #349

Closed jshtok closed 4 months ago

jshtok commented 4 months ago

Version Information

I am trying to run the text generation client. It is initialized with my usual BAM key, credentials = Credentials(api_key=keys[0]) self.client = Client(credentials=credentials)

Then sa I run the generation

 self.client.text.generation.create(
                        model_id=self.model_id,
                        inputs=prompts,
                        moderations=self.moderations,
                        execution_options=CreateExecutionOptions(ordered=False),
                        parameters=self.parameters,
                    )

I get the error

genai.exceptions.ApiResponseException: Failed to handle request to https://bam-api.res.ibm.com/v2/text/generation/limits?version=2023-11-22.
{
  "error": "Unauthorized",
  "extensions": {
    "code": "AUTH_ERROR",
    "state": null,
    "reason": "TOKEN_INVALID"
  },
  "message": "Invalid or missing JWT token",
  "status_code": 401
}

Is the issue with my BAM key? What is the JWT token?

Thank you!

jshtok commented 4 months ago

Update: the same code worked when I have provided the credentials using the dotenv. But I would like to keep the auth key as a variable...

Tomas2D commented 4 months ago

BAM Key is the JWT token.

The TOKEN_INVALID error message indicates that the key you have passed on is not an actual API Key. API Key should be in the format pak-4.... You can print the values of your Credentials instance print(credentials.api_key.get_secret_value()).

jshtok commented 4 months ago

Thank you, Tomáš, I worked it out.

Regards, Josef

On Wed, 24 Apr 2024, 16:33 Tomáš Dvořák, @.***> wrote:

BAM Key is the JWT token.

The TOKEN_INVALID error message indicates that the key you have passed on is not an actual API Key. API Key should be in the format pak-4.... You can print the values of your Credentials instance print(credentials.api_key.get_secret_value()).

— Reply to this email directly, view it on GitHub https://github.com/IBM/ibm-generative-ai/issues/349#issuecomment-2074962385, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOBU6WKUMLRLFX36MRQRF3Y66YB5AVCNFSM6AAAAABGM7K3Z6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZUHE3DEMZYGU . You are receiving this because you authored the thread.Message ID: @.***>