Codeless calling chatGPT API

For some reason I’ve got the correct API key and the correct URL to access chatGPT but I’m getting authorization errors.

Has anyone else been able to successfully get into chatGPT from Codeless?

Does the error message contain some details about the auth problem?

Do you have some correct request in well-known form, like cURL, HAR, etc. in order to be sure it works in general?

Hi here’s what we were able to do in VS Code and typescript and it works fine in VS Code.

but i get a 401 error when I tried to duplicate that in Codeless. Thanks for your help!

One of our developers looked through you example.
There was a problem with quotes. You can see the changes in the app. Your logic is left commented out.

I dont know what you mean by this. William said the Typescirpt is working on his end. Can you please clearify? Thanks.

I’m sorry i’m not sure what you were referring to with problem with quotes. Do I need to use the Raw Text codeless block instead or did I make a mistake with double or single quotes? If there’s anyway you can get a screenshot of the blocks you use to connect to chatGPT that would be great…

I think what Oleg meant is a support engineer made changes in your codeless logic and commented out (disabled the logic blocks you used to have) so you can see the difference in the changes.

You can see the difference in how the header is structured. In your logic, you added ${} which is not present in the corrected logic.

Hi @William_Lee,

to make it more clear what has changed and why: in the TypeScript example, the string “Bearer …” is formed using the word Bearer and the apiKey variable, which contains your token. In JavaScript (as well as TypeScript) to specify the value of a variable directly in the string, the syntax of the Template Literals is used, for which the variable is wrapped in ${ ... }, but these characters do not end up in the string, these are just indications for the program that you want the variable inside these characters was inside the string at the specified place. E.g.

const myName = "Stan"

const string = `My name is ${myName}`

console.log(string) // result is a string "My name is Stan", not "My name is ${Stan}"

In your case, you copied the value into codeless directly with ${} symbols, causing your token to become invalid due to extra characters. Our engineers made a copy of your block, removed these characters, and disabled your block for clarity, so you can see what the differences are. You can remove the disabled block and everything will work.

I hope this clears things up.

Regards,
Stanislaw

1 Like

Great that works… Thanks for also adding the “Create List With” block in there. I get it now.

1 Like