landgraf-dev / openai-delphi

OpenAI API client for Delphi and Lazarus/FPC. Use ChatGPT, DALL-E and other products from Pascal language.
MIT License
126 stars 40 forks source link

I provided API key, but got error #3

Closed jembem closed 1 year ago

jembem commented 1 year ago

I'm using Lazarus

response from OpenAi

[Content]
Request failed
status: 401
Response: {
    "error": {
        "message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}

api key provided using these :

Client := TOpenAIClient.Create;
Client.Config.AccessToken := GetEnvironmentVariable(apikey); 
wlandgraf commented 1 year ago

Are you setting the API key, or are you reading the value from an environment variable with the name of the API key? If you are setting the API key directly you should do just this:

Client.Config.AccessToken := apikey;
jembem commented 1 year ago

Are you setting the API key, or are you reading the value from an environment variable with the name of the API key? If you are setting the API key directly you should do just this:

Client.Config.AccessToken := apikey;

yes that was the problem...I took example from demos..and made mistake.. now all is working fine..thank you.