Hello everyone,
I’m trying to connect from MetaTrader 5 (MQL5 language) to ChatGPT (gpt-3.5-turbo) using the WebRequest()
function. Despite adding an Authorization: Bearer
header in the HTTP request, I keep receiving a 401 response stating:
“You didn’t provide an API key. You need to provide your API key in an Authorization header using Bearer auth…”
My suspicion is that MQL5 might be ignoring or dropping the custom header. I have:
- Verified my API key is correct (no extra spaces, etc.).
- Allowed WebRequest in MT5 (Tools → Options → Expert Advisors → “Allow WebRequest for listed URL” with
https://api.openai.com
). - Tested multiple MT5 builds (including an official, up-to-date build from MetaQuotes).
- Attempted to use Fiddler / Wireshark to confirm if the header is actually being sent. However, I only see an encrypted CONNECT tunnel and cannot decrypt the payload (likely due to MT5 not accepting the Fiddler certificate or using some form of certificate pinning).
No matter what, the OpenAI server responds with the same “You didn’t provide an API key” error, suggesting the Authorization
header isn’t recognized on their side.
Environment notes:
- Windows Server / Windows 10 (both tested).
- Official MetaTrader 5 build (latest).
- A new “project” API key from OpenAI (these can be quite long, ~100+ characters).
- Verified that normal
curl
requests (outside of MT5) work fine with the same key.
Question: Has anyone successfully used ChatGPT (gpt-3.5-turbo) with an MQL5 EA (directly, via WebRequest()
), especially with the new longer “project” keys? Is there a known workaround to ensure the Authorization: Bearer
header is not dropped?
Any help, insights, or confirmation on whether MQL5 has issues with custom headers or key lengths would be greatly appreciated!
Thank you in advance!