You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: LLM Profile API Key Encryption via GUI Breaks Sub-Agent LiteLLM Authentication #4270
I have searched existing issues and this is not a duplicate.
Bug Description
When saving an LLM Profile through the GUI, API keys are automatically encrypted and stored. However, when a Sub-Agent is invoked, the system does not appear to correctly decrypt the API key before passing it to LiteLLM, causing LiteLLM to fail to recognize the key and rendering Sub-Agents unusable.
Expected Behavior
The API key should be correctly decrypted and passed to LiteLLM when a Sub-Agent is invoked, just as it works for the primary Agent.
Actual Behavior
LiteLLM receives an encrypted (or otherwise malformed) API key and cannot authenticate, causing Sub-Agent calls to fail. Same as inserting a key varaible 'XX_LLM_Key'
Steps to Reproduce
Open the GUI and navigate to LLM Settings
Create or edit an LLM Profile and save it (API key gets auto-encrypted)
Start a session and trigger a Sub-Agent invocation
Observe that the Sub-Agent fails — LiteLLM reports an unrecognized or invalid API key
OpenHands Installation Method
Local GUI (Docker web interface)
If you selected "Other", please specify
No response
OpenHands Version
1.36.1
Version Confirmation
I have confirmed this bug exists on the LATEST version of OpenHands
Model Name
No response
Operating System
Linux
Browser (if using web UI)
Edge 150.0.4078.83
Logs and Error Messages
Conversation run failed for id=219f5361-2262-4ea8-9f9d-4eefaace16d1: litellm.AuthenticationError:
AuthenticationError: Litellm_proxyException - LiteLLM Virtual Key expected. Received=gAAA****L7Q=,
expected to start with 'sk-'.
[Automatic Post]: This issue has been waiting for triage. @xingyaoww@neubig@enyst, could you
please take a look and add the appropriate priority label when you have a chance?
This comment was created by an AI agent (OpenHands) on behalf of the user.
[Automatic Post]: This issue has been waiting for triage. @xingyaoww@neubig@enyst, could you please take a look and add the appropriate priority label when you have a chance?
This comment was created by an AI agent (OpenHands) on behalf of the user.
[Automatic Post]: This issue has been waiting for triage. @xingyaoww@neubig@enyst, could you
please take a look and add the appropriate priority label when you have a chance?
This comment was posted by an AI agent (OpenHands) on behalf of the user.
[Automatic Post]: This issue has been waiting for triage. @xingyaoww@neubig@enyst, could you
please take a look and add the appropriate priority label when you have a chance?
This comment was created by an AI agent (OpenHands) on behalf of the user.
[Automatic Post]: This issue was automatically closed due to 43 days of inactivity. We do this to help keep the issue tracker manageable and focused on active issues. If this is still relevant, feel free to reopen it.
Generated by OpenHands automation on behalf of the user.
Activity
lxcxjxhx commentedon Jul 23, 2026
问题分析
从错误信息看,LiteLLM 收到的是 base64 编码的加密值(
gAAA****L7Q=),而不是解密后的 API key(应以sk-开头)。这说明 Sub-Agent 在初始化 LLM 实例时,没有正确解密存储的 API key。根因定位
OpenHands 的 API key 加密/解密流程:
SettingsService.save_llm_profile()调用encrypt_api_key()加密 key 并存储到数据库LLMService.get_llm_instance()调用decrypt_api_key()解密后传给 LiteLLMConversationService.start_conversation()),而 Sub-Agent 走了不同的初始化路径临时解决方案
在修复代码之前,可以尝试以下 workaround:
方案 1:使用环境变量传递 API key
方案 2:禁用 API key 加密(仅测试环境)
# 在 .env 或 docker-compose.yml 中添加 DISABLE_API_KEY_ENCRYPTION=true方案 3:手动解密并重新配置
如果急需使用 Sub-Agent,可以:
代码修复建议
需要检查以下文件中的密钥处理逻辑:
1.
openhands/core/services/llm_service.py确保
get_llm_instance()方法在所有调用路径中都调用decrypt_api_key():2.
openhands/core/services/sub_agent_service.py检查 Sub-Agent 初始化时是否正确继承了主 Agent 的 LLM 配置:
3. 添加单元测试
验证步骤
修复后,可以通过以下步骤验证:
检查日志:
测试 Sub-Agent 调用:
AuthenticationError数据库检查:
相关代码位置
openhands/core/utils/encryption.pyopenhands/core/config/llm_config.pyopenhands/core/services/sub_agent_service.pyopenhands/server/services/settings_service.py环境限制说明:由于本地 Windows 环境缺少完整的 Docker 和 OpenHands 运行环境,无法进行完整的动态测试。以上分析基于代码审查和错误信息推理,建议维护者在完整环境中验证修复方案。
需要我提交 PR 实现这个修复吗?
all-hands-bot commentedon Jul 30, 2026
[Automatic Post]: This issue has been waiting for triage. @xingyaoww @neubig @enyst, could you
please take a look and add the appropriate priority label when you have a chance?
This comment was created by an AI agent (OpenHands) on behalf of the user.
all-hands-bot commentedon Jul 31, 2026
[Automatic Post]: This issue has been waiting for triage. @xingyaoww @neubig @enyst, could you please take a look and add the appropriate priority label when you have a chance?
This comment was created by an AI agent (OpenHands) on behalf of the user.
all-hands-bot commentedon Aug 2, 2026
[Automatic Post]: This issue has been waiting for triage. @xingyaoww @neubig @enyst, could you
please take a look and add the appropriate priority label when you have a chance?
This comment was posted by an AI agent (OpenHands) on behalf of the user.
all-hands-bot commentedon Aug 3, 2026
[Automatic Post]: This issue has been waiting for triage. @xingyaoww @neubig @enyst, could you
please take a look and add the appropriate priority label when you have a chance?
This comment was created by an AI agent (OpenHands) on behalf of the user.
all-hands-bot commentedon Sep 4, 2026
[Automatic Post]: This issue was automatically closed due to 43 days of inactivity. We do this to help keep the issue tracker manageable and focused on active issues. If this is still relevant, feel free to reopen it.
Generated by OpenHands automation on behalf of the user.