iflytek/astron-agent · error · IllegalArgumentException
Invalid host URL or authentication parameters
Error message
Invalid host URL or authentication parameters
What it means
buildWebSocketAuthUrl signs the Spark chat WebSocket endpoint (HMAC-SHA256 of host/date/request-line) and returns the authenticated URL. Any failure — URI.create on hostUrl, HttpUrl.parse returning null (OkHttp cannot parse the composed URL), or MAC operations — is logged and rethrown as IllegalArgumentException('Invalid host URL or authentication parameters', cause). Thrown before any WebSocket connection is attempted.
Solutions
- Check the logged 'Failed to build WebSocket authentication URL' cause for the exact failure
- Verify TEXT_HOST_URL ('https://spark-api.xf-yun.com/v4.0/chat') is intact and parses as an absolute URL with host and path
- Ensure platformApiKey/platformApiSecret are configured and non-null for the iFlytek open platform account
- Unit-test buildWebSocketAuthUrl with the configured URL to catch regressions after config changes
Example fix
// before
String authUrl = buildWebSocketAuthUrl(TEXT_HOST_URL, config.getPlatformApiKey(), config.getPlatformApiSecret());
// after
if (StrUtil.isBlank(config.getPlatformApiKey()) || StrUtil.isBlank(config.getPlatformApiSecret())) {
throw new BusinessException(ResponseEnum.CONFIG_ERROR);
}
String authUrl = buildWebSocketAuthUrl(TEXT_HOST_URL, config.getPlatformApiKey(), config.getPlatformApiSecret()); Defensive patterns
Strategy: validation
Validate before calling
if (StrUtil.isBlank(apiKey) || StrUtil.isBlank(apiSecret)) { throw new BusinessException(ResponseEnum.CONFIG_ERROR); }
assert HttpUrl.parse("https://spark-api.xf-yun.com/v4.0/chat") != null; Try / catch
try { return client.generateText(q, domain, 60); } catch (IllegalArgumentException e) { log.error("WS auth URL invalid — check host URL and credentials", e); throw new BusinessException(ResponseEnum.CONFIG_ERROR); } Prevention
- Do not edit TEXT_HOST_URL without validating it parses as host+path
- Configure apiKey/apiSecret for the iFlytek platform account
- Add a unit test covering buildWebSocketAuthUrl with the production URL
When it happens
Trigger: TEXT_HOST_URL is malformed or its host+path cannot be parsed by OkHttp's HttpUrl (Objects.requireNonNull fails), apiSecret is null, or URI.create rejects the host URL string when generateText calls buildWebSocketAuthUrl(TEXT_HOST_URL, ...).
Common situations: TEXT_HOST_URL constant edited to an invalid value (bad path/host), platform API secret missing from config causing NPE, or URL characters needing encoding in the configured host URL.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Failed to build authentication URL
- convertTextErrorCodeToResponseEnum(listener.getErrorCode())
- WebSocketClientAuthError
- User UID cannot be null
- Timed out acquiring distributed lock, please try again later
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/fdc1513b5e43712d.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java:553
mac.init(spec);
byte[] hexDigits = mac.doFinal(preStr.getBytes(StandardCharsets.UTF_8));
String sha = Base64.getEncoder().encodeToString(hexDigits);
String authorization = String.format("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"",
apiKey, "hmac-sha256", "host date request-line", sha);
HttpUrl httpUrl = Objects.requireNonNull(HttpUrl.parse("https://" + uri.getHost() + uri.getPath()))
.newBuilder()
.addQueryParameter("authorization", Base64.getEncoder().encodeToString(authorization.getBytes(StandardCharsets.UTF_8)))
.addQueryParameter("date", date)
.addQueryParameter("host", uri.getHost())
.build();
return httpUrl.toString();
} catch (Exception e) {
log.error("Failed to build WebSocket authentication URL", e);
throw new IllegalArgumentException("Invalid host URL or authentication parameters", e);
}
}
/**
* WebSocket response data structure
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class WebSocketResponse {
private ResponseHeader header;
private ResponsePayload payload;
}
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ResponseHeader {
private int code;
private String sid;View on GitHub (pinned to 5e758547a8)