iflytek/astron-agent · error · ValueError
Missing required environment variables
Error message
Missing required environment variables: {', '.join(missing)} What it means
IFlyAuditAPI.__init__ reads IFLYTEK_AUDIT_APP_ID, IFLYTEK_AUDIT_ACCESS_KEY_ID and IFLYTEK_AUDIT_ACCESS_KEY_SECRET from the environment. If any of them is empty AND AUDIT_ENABLE=1, it raises ValueError listing the missing variable names. The audit (content-security) integration is therefore strictly opt-in: enabling it without full credentials fails fast at construction time.
Solutions
- Set the missing variables named in the error message (IFLYTEK_AUDIT_APP_ID, IFLYTEK_AUDIT_ACCESS_KEY_ID, IFLYTEK_AUDIT_ACCESS_KEY_SECRET) in the service environment/secret.
- If content audit is not needed, keep AUDIT_ENABLE=0 (or unset) so the client is never constructed with partial config.
- Check for typos in the env var names and that the secret is actually mounted into the workflow container.
- Add a startup config check that validates the trio together whenever AUDIT_ENABLE=1.
Example fix
// before (partial config) AUDIT_ENABLE=1 IFLYTEK_AUDIT_APP_ID=my-app // after AUDIT_ENABLE=1 IFLYTEK_AUDIT_APP_ID=my-app IFLYTEK_AUDIT_ACCESS_KEY_ID=ak-xxx IFLYTEK_AUDIT_ACCESS_KEY_SECRET=sk-xxx
Defensive patterns
Strategy: validation
Validate before calling
import os
REQUIRED = ["IFLYTEK_AUDIT_APP_ID", "IFLYTEK_AUDIT_ACCESS_KEY_ID", "IFLYTEK_AUDIT_ACCESS_KEY_SECRET"]
if os.getenv("AUDIT_ENABLE", "0") == "1":
missing = [k for k in REQUIRED if not os.getenv(k)]
assert not missing, f"missing audit env vars: {missing}" Try / catch
try:
audit_api = IFlyAuditAPI()
except ValueError as e:
logger.error(f"audit config incomplete: {e}")
raise # or fall back to a no-op audit client Prevention
- Treat AUDIT_ENABLE=1 as requiring the full credential trio in your deploy checklist/CI.
- Keep audit credentials in the same secret/manifest as the feature flag so they ship together.
- Run a startup smoke test that constructs IFlyAuditAPI when the flag is on.
When it happens
Trigger: Instantiating IFlyAuditAPI (directly or via the audit system bootstrap) with AUDIT_ENABLE=1 while one or more of IFLYTEK_AUDIT_APP_ID / IFLYTEK_AUDIT_ACCESS_KEY_ID / IFLYTEK_AUDIT_ACCESS_KEY_SECRET is unset or empty; note the check is skipped when AUDIT_ENABLE is 0/unset.
Common situations: Enabling the audit feature flag in a deployment (AUDIT_ENABLE=1) but forgetting to add the iFlytek audit credentials to the secret/env block; credentials present only in another environment/namespace; typos in variable names leaving the fallback '' in effect.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- KAFKA_SERVERS environment variable is not configured…
- LIST_MCP_PLUGIN_URL is not set
- Missing required MySQL environment variables for migration
- PG_SQL_NODE_EXECUTION_ERROR
- RAGFLOW_BASE_URL not configured in environment variables
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/da7c8175197d106d.
Report an issue: GitHub.
Appendix: source
Thrown at core/workflow/infra/audit_system/audit_api/iflytek/ifly_audit_api.py:119
:raises ValueError: If required environment variables are missing
"""
self.app_id = os.getenv("IFLYTEK_AUDIT_APP_ID", "")
self.access_key_id = os.getenv("IFLYTEK_AUDIT_ACCESS_KEY_ID", "")
self.access_key_secret = os.getenv("IFLYTEK_AUDIT_ACCESS_KEY_SECRET", "")
self.hosts = os.getenv(
"IFLYTEK_AUDIT_HOST", "http://audit-api.xfyun.cn/v1.0"
).split(",")
missing = []
if not self.app_id:
missing.append("IFLYTEK_AUDIT_APP_ID")
if not self.access_key_id:
missing.append("IFLYTEK_AUDIT_ACCESS_KEY_ID")
if not self.access_key_secret:
missing.append("IFLYTEK_AUDIT_ACCESS_KEY_SECRET")
if missing and int(os.getenv("AUDIT_ENABLE", "0")) == 1:
raise ValueError(
f"Missing required environment variables: {', '.join(missing)}"
)
def _signature(self, query_param: dict) -> str:
"""
Generate HMAC-SHA1 signature for request authentication.
Creates a cryptographic signature using HMAC-SHA1 algorithm based on
the sorted query parameters. This signature is used to authenticate
requests to the IFlyTek audit API.
:param query_param: Query parameters dictionary to be signed
:return: Base64 encoded signature string for API authentication
"""
# Use ordered dictionary to simulate TreeMap (sorted by key)
sorted_params = OrderedDict(sorted(query_param.items()))
# Remove signature parameterView on GitHub (pinned to 5e758547a8)