Bug Report
Summary
The image_generate tool always returns {"success": false, "image": null} even when FAL_KEY is correctly set in the gateway process environment via systemd. The fal.ai API returns "invalid key credentials" because the tool execution context does not inherit the FAL_KEY environment variable from the gateway process.
Environment
- OS: Raspberry Pi, aarch64, Debian (kernel 6.12.62)
- Hermes: Latest (installed via hermes-agent repo)
- Python: 3.11
- fal-client: 0.13.2
- Gateway: Running as systemd user service
Steps to Reproduce
- Set
FAL_KEY in the hermes-gateway systemd service file:
Environment="FAL_KEY=<valid-fal-key>"
- Reload and restart the gateway:
systemctl --user daemon-reload && systemctl --user restart hermes-gateway
- Confirm the gateway process has the key:
cat /proc/<PID>/environ | tr '\0' '\n' | grep FAL — shows the correct key
- Use the
image_generate tool from a chat session
- Tool returns
{"success": false, "image": null}
- Error log shows:
fal_client.client.FalClientHTTPError: invalid key credentials
Evidence That the Key Works
The exact same tool code succeeds when called via execute_code with the env var explicitly set:
import os
os.environ["FAL_KEY"] = "<key>"
from tools.image_generation_tool import image_generate_tool
result = image_generate_tool(prompt="A cute robot", aspect_ratio="square")
# Returns {"success": true, "image": "https://..."}
Direct API calls with urllib.request and fal_client.submit() also succeed with the same key. Only the native image_generate tool invocation fails.
Root Cause Analysis
The image_generate_tool in tools/image_generation_tool.py calls os.getenv("FAL_KEY") at line 283, and fal_client reads it via fetch_auth_credentials() at import time (module-level SyncClient() singleton in fal_client/__init__.py line 58).
The gateway process PID has the correct FAL_KEY in its environment, but when the tool is invoked during a chat session, the execution context does not appear to inherit this variable. This suggests the tool runs in a subprocess or sandbox that does not receive the gateway's full environment.
Expected Behavior
FAL_KEY (and other provider API keys) set in the gateway systemd service should be available to all tools during execution.
Workaround
Use execute_code to call the tool directly with os.environ["FAL_KEY"] set explicitly before import.
Bug Report
Summary
The
image_generatetool always returns{"success": false, "image": null}even whenFAL_KEYis correctly set in the gateway process environment via systemd. The fal.ai API returns "invalid key credentials" because the tool execution context does not inherit theFAL_KEYenvironment variable from the gateway process.Environment
Steps to Reproduce
FAL_KEYin the hermes-gateway systemd service file:systemctl --user daemon-reload && systemctl --user restart hermes-gatewaycat /proc/<PID>/environ | tr '\0' '\n' | grep FAL— shows the correct keyimage_generatetool from a chat session{"success": false, "image": null}fal_client.client.FalClientHTTPError: invalid key credentialsEvidence That the Key Works
The exact same tool code succeeds when called via
execute_codewith the env var explicitly set:Direct API calls with
urllib.requestandfal_client.submit()also succeed with the same key. Only the nativeimage_generatetool invocation fails.Root Cause Analysis
The
image_generate_toolintools/image_generation_tool.pycallsos.getenv("FAL_KEY")at line 283, andfal_clientreads it viafetch_auth_credentials()at import time (module-levelSyncClient()singleton infal_client/__init__.pyline 58).The gateway process PID has the correct
FAL_KEYin its environment, but when the tool is invoked during a chat session, the execution context does not appear to inherit this variable. This suggests the tool runs in a subprocess or sandbox that does not receive the gateway's full environment.Expected Behavior
FAL_KEY(and other provider API keys) set in the gateway systemd service should be available to all tools during execution.Workaround
Use
execute_codeto call the tool directly withos.environ["FAL_KEY"]set explicitly before import.