Can not use `openai-responses` providers due to failed JWT parsing
To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.
Please avoid AI slops, be concise, and focus on what matters for this issue.
Describe the bug
(background)
My company does not allow the direct use of external generative AI services, but instead provides an internal API gateway. This API gateway requires an Authorization: Bearer XXX header, where the token is issued by an internal system. Employees can access OpenAI’s /v1/responses endpoint through this gateway.
I wrote the ECA configuration as follows:
{
"providers": {
"GenAI:OpenAI": {
"api": "openai-responses",
"url": "https://MY-COMPANY'S-INTERNAL-LLM-API-GATEWAY",
"key": "SIMPLE-BEARER-TOKEN-FROM-MY-COMPANY'S-INTERNAL-SYSTEM",
"fetchModels": false,
"models": {...}
}
}
}
Then, I simply typed “Hi!” in the ECA buffer in Emacs and encountered the following exception.
{:exception #error {
:cause Illegal base64 character 2d
:via
[{:type java.lang.IllegalArgumentException
:message Illegal base64 character 2d
:at [java.util.Base64$Decoder decode0 Base64.java 852]}]
:trace
[[java.util.Base64$Decoder decode0 Base64.java 852]
[java.util.Base64$Decoder decode Base64.java 570]
[java.util.Base64$Decoder decode Base64.java 593]
[eca.oauth$_LT__base64 invokeStatic oauth.clj 79]
[eca.oauth$_LT__base64 invoke oauth.clj 78]
[eca.llm_providers.openai$jwt_token__GT_account_id invokeStatic openai.clj 35]
[eca.llm_providers.openai$jwt_token__GT_account_id invoke openai.clj 30]
[eca.llm_providers.openai$base_responses_request_BANG_ invokeStatic openai.clj 52]
[eca.llm_providers.openai$base_responses_request_BANG_ invoke openai.clj 46]
[eca.llm_providers.openai$create_response_BANG_ invokeStatic openai.clj 276]
[eca.llm_providers.openai$create_response_BANG_ invoke openai.clj 143]
[eca.llm_api$prompt_BANG_ invokeStatic llm_api.clj 240]
[eca.llm_api$prompt_BANG_ invoke llm_api.clj 102]
[eca.llm_api$sync_or_async_prompt_BANG_ invokeStatic llm_api.clj 332]
[eca.llm_api$sync_or_async_prompt_BANG_ invoke llm_api.clj 266]
[eca.features.chat$prompt_messages_BANG_$fn__8367$fn__8368 invoke chat.clj 1213]
[eca.features.chat$prompt_messages_BANG_$fn__8367 invoke chat.clj 1212]
[clojure.lang.AFn run AFn.java 22]
[java.lang.Thread runWith Thread.java 1460]
[java.lang.Thread run Thread.java 1447]
[com.oracle.svm.core.thread.PlatformThreads threadStartRoutine PlatformThreads.java 832]
[com.oracle.svm.core.thread.PlatformThreads threadStartRoutine PlatformThreads.java 808]]}}
https://github.com/editor-code-assistant/eca/blob/d513b0ee8dce1608ce34ece9a7b471e85484d134/src/eca/llm_providers/openai.clj#L51-L52
The current implementation attempts to extract a user ID from the provided token to populate the ChatGPT-Account-Id header, assuming the token is a JWT. However, the token I used is not a JWT.
Since the ChatGPT-Account-Id header is not mandatory for the API [1], I believe it would be worthwhile to support openai-responses without requiring this header.
[1] https://developers.openai.com/api/reference/resources/responses/methods/create
**To Reproduce**
Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Doctor**
Paste the relevant parts of /doctor command from chat if applicable:
**Screenshots**
If applicable, add screenshots to help explain your problem.**Additional context**
Add any other context about the problem here.
Good catch, will fix that!
Fixed!