jeecgboot/JeecgBoot · error · JeecgBootBizTipException

调用大模型接口失败:

Error message

调用大模型接口失败:

What it means

This error is thrown by AiragChatServiceImpl when an exception occurs during the LLM streaming/chat operation (aiChatHandler.chat or aiChatHandler.chatByDefaultModel). The method first closes any MCP connections, sends an error event to the SSE emitter, then re-throws as a JeecgBootBizTipException with the original exception message appended. This is the unified error handling for all LLM communication failures during streaming chat.

Source

Thrown at jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/app/service/impl/AiragChatServiceImpl.java:1494

            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            // for [QQYUN-9234] MCP服务连接关闭 - 异常时关闭MCP连接
            finalAiChatParams.closeMcpConnections();
            // sse
            SseEmitter emitter = AiragLocalCache.get(AiragConsts.CACHE_TYPE_SSE, requestId);
            if (null == emitter) {
                log.warn("[AI应用]接收LLM返回会话已关闭{}", requestId);
                return;
            }
            String errMsg = "调用大模型接口失败,详情请查看后台日志。";
            if(e instanceof JeecgBootException || e instanceof JeecgBootBizTipException){
                errMsg = e.getMessage();
            }
            EventData eventData = new EventData(requestId, null, EventData.EVENT_FLOW_ERROR, chatConversation.getId(), topicId);
            eventData.setData(EventFlowData.builder().success(false).message(errMsg).build());
            closeSSE(emitter, eventData);
            throw new JeecgBootBizTipException("调用大模型接口失败:" + e.getMessage());
        }

        // 发送消息给前端
        BiConsumer<String, String> send2Client = (resMessage, eventType) -> {
            eventType = oConvertUtils.isNotEmpty(eventType) ? eventType : EventData.EVENT_MESSAGE;

            EventData eventData = new EventData(requestId, null, eventType, chatConversation.getId(), topicId);
            EventMessageData messageEventData = EventMessageData.builder().message(resMessage).build();
            eventData.setData(messageEventData);
            eventData.setRequestId(requestId);
            // sse
            SseEmitter emitter = AiragLocalCache.get(AiragConsts.CACHE_TYPE_SSE, requestId);
            if (null == emitter) {
                log.warn("[AI应用]接收LLM返回会话已关闭");
                return;
            }
            sendMessage2Client(emitter, eventData);
        };

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Check the server logs for the detailed exception stack trace and the appended e.getMessage() to identify the specific LLM provider error.
  2. Verify the AI model configuration: API key, endpoint URL, model name are all correct and the model is activated.
  3. Test connectivity to the LLM provider endpoint from the server using curl or a network diagnostic tool.
  4. If rate-limited, reduce request frequency or upgrade the API plan with the provider.
  5. If token limits are exceeded, reduce the conversation history length or use a model with a larger context window.

Example fix

// before — generic catch with no specific error categorization
} catch (Exception e) {
    log.error(e.getMessage(), e);
    throw new JeecgBootBizTipException("调用大模型接口失败:" + e.getMessage());
}

// after — categorized handling with actionable messages
} catch (Exception e) {
    log.error("[AI-CHAT] LLM call failed for requestId={}", requestId, e);
    String userMsg = translateLlmException(e, "调用大模型接口失败");
    throw new JeecgBootBizTipException(userMsg);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight check: verify LLM endpoint is reachable
public static boolean isLlmEndpointReachable(String apiUrl, String apiKey) {
    try {
        HttpURLConnection conn = (HttpURLConnection) new URL(apiUrl).openConnection();
        conn.setConnectTimeout(3000);
        conn.setRequestProperty("Authorization", "Bearer " + apiKey);
        return conn.getResponseCode() > 0;
    } catch (Exception e) {
        return false;
    }
}

Type guard

// Check if the model configuration is complete
public static boolean isModelConfigured(AiragModel model) {
    return model != null
        && model.getActivateFlag() != null
        && model.getActivateFlag() == 1
        && model.getApiKey() != null
        && !model.getApiKey().isEmpty()
        && model.getApiUrl() != null
        && !model.getApiUrl().isEmpty();
}

Try / catch

try {
    // LLM streaming call
    chatStream = aiChatHandler.chat(modelId, messages, aiChatParams);
} catch (Exception e) {
    log.error("[AI-CHAT] LLM call failed", e);
    finalAiChatParams.closeMcpConnections();
    // Close SSE with error event
    closeSSEWithError(emitter, requestId, e.getMessage());
    // Re-throw for controller-level handling
    throw new JeecgBootBizTipException("调用大模型接口失败: " + e.getMessage());
}

Prevention

When it happens

Trigger: A chat request triggers aiChatHandler.chat(modelId, messages, params) or chatByDefaultModel(messages, params) which throws. This happens when: the LLM API endpoint is unreachable, the API key is invalid, the model name is wrong, the request payload exceeds token limits, the LLM provider returns a rate limit error, or an MCP service connection fails.

Common situations: LLM provider API key expired or revoked. Network connectivity to the LLM endpoint is blocked by firewall. The model ID references a model that doesn't exist on the provider. Rate limiting by the LLM provider. Token limit exceeded for the conversation context. MCP tool server is down.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/fdf42de2c3e0d895. Report an issue: GitHub.