Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
string openai_api_key = "sk-proj-EXAMPLE_KEY_which_is_quite_long...";
just wondering if you use valid key here ?
// Convert JSON to UTF-8 char array char data[]; int size = StringToCharArray(json_body, data, 0, StringLen(json_body), CP_UTF8); ArrayResize(data, size + 1); data[size] = 0; // null-terminate
// Convert JSON to UTF-8 char array char data[]; StringToCharArray(json_body, data, 0, StringLen(json_body)-1, CP_UTF8);
See if that helps.
Forum on trading, automated trading systems and testing of trading strategies
New MetaTrader 5 platform version build 4620: MQL5 bug fixes and new OpenBLAS methods
Stanislav Korotky , 2024.11.29 19:49
Once again I came across a couple of glitches, which I managed to solve only because it was not the first time. The illogical behavior of the system does not fit in my head, so I periodically forget about the catch.
Here is a seemingly simple function:
bool DumpTextToFile( const string name, const string buffer) { uchar bytes[]; StringToCharArray (buffer, bytes, 0 , - 1 , CP_UTF8 ); return FileSave (name, bytes); }
But don't believe your eyes. A text file created this way won't be able to be opened by MetaEditor - or rather, it opens a tab for it, but doesn't show the contents. The whole point is that the array (and the file) gets a terminal 0. All other text editors open such a file without any problems.
If we assume a trivial solution:
bool DumpTextToFile( const string name, const string buffer) { uchar bytes[]; StringToCharArray (buffer, bytes, 0 , StringLen (buffer), CP_UTF8 ); return FileSave (name, bytes); }
we will get a new bug - if the text contains non-Latin letters, then not all the text will be written to the file, because the arguments of the StringToCharArray function refer to the buffer (!), and not the string, and when encoding in utf-8, the buffer increases in size compared to the string.
Final solution (with bugs I haven't found yet):
bool DumpTextToFile( const string name, const string buffer) { uchar bytes[]; StringToCharArray (buffer, bytes, 0 , - 1 , CP_UTF8 ); ArrayResize (bytes, bytes.Size() - 1 ); return FileSave (name, bytes); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
I’m attempting to integrate ChatGPT (gpt-3.5-turbo) into MetaTrader 5 using WebRequest() in MQL5. When I call https://api.openai.com/v1/chat/completions , I consistently get a 401 response telling me:
It looks as if the Authorization: Bearer header is never recognized by OpenAI.
Key details:
Has anyone faced issues with these longer “sk-proj” keys causing MQL5’s WebRequest() to drop or truncate the Authorization header? Or do we need an official MT5 update to handle these keys properly?
Below is a simplified code snippet showing how I’m sending the request:
Result: Always returns 401 with
Questions:
Thanks in advance for any guidance!