iflytek/astron-agent · error · BusinessException

OPEN_AI_API_ERROR

OPEN_AI_API_ERROR

Error message

OPEN_AI_API_ERROR

What it means

OpenAiModelProcessService.processNonStreaming catches any exception thrown during the non-streaming OpenAI-compatible chat completion call and rethrows it as a BusinessException with code OPEN_AI_API_ERROR. The original exception (network, timeout, auth, model error, response parsing) is logged but its detail is not carried into the business exception.

Solutions

  1. Check the error log 'Non-streaming OpenAI API call failed' for the root cause (status code, message).
  2. Verify the API key and base URL configuration for the model provider.
  3. Confirm the requested model name exists and is enabled on the endpoint.
  4. Handle 429 rate limits with retry/backoff and increase the request timeout for long completions.
  5. Preserve the cause in the thrown exception for easier diagnosis.

Example fix

// before
throw new BusinessException(ResponseEnum.OPEN_AI_API_ERROR);

// after
throw new BusinessException(ResponseEnum.OPEN_AI_API_ERROR, e);
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight checks before the LLM call
Assert.hasText(apiKey, "OpenAI API key must be set");
Assert.hasText(baseUrl, "OpenAI base URL must be set");
Assert.hasText(model, "model name must be set");

Try / catch

try {
    return openAiModelProcessService.processNonStreaming(req);
} catch (BusinessException e) {
    if (ResponseEnum.OPEN_AI_API_ERROR.getCode().equals(e.getCode())) {
        // inspect cause/log for 401/429/timeout; retry 429 with backoff, fail fast on 401
        return fallbackAnswer(req);
    }
    throw e;
}

Prevention

When it happens

Trigger: The OpenAI-compatible HTTP request fails for any reason inside processNonStreaming: invalid/missing API key (401), unknown model name (404/400), rate limit (429), network/timeout to the endpoint, or malformed response that breaks content extraction.

Common situations: Wrong OPENAI base URL or key in configuration; model name not available on the configured endpoint; quota exhausted; egress firewall blocking the LLM endpoint; long prompts exceeding the model context or request timeout.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/9e883d77a26ffdcf. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/bot/OpenAiModelProcessService.java:64

            OpenAIClient client = buildClient(config);
            // Build request parameters
            ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
                    .model(config.getModel())
                    .addUserMessage(prompt)
                    .build();

            // Call API
            ChatCompletion completion = client.chat().completions().create(params);

            // Extract response content
            String content = completion.choices().getFirst().message().content().orElse("");

            log.info("Non-streaming call completed, response length: {}", content.length());
            return content;

        } catch (Exception e) {
            log.error("Non-streaming OpenAI API call failed", e);
            throw new BusinessException(ResponseEnum.OPEN_AI_API_ERROR);
        }
    }

    /**
     * Streaming call to OpenAI API
     *
     * @param prompt User input prompt
     * @return SseEmitter object for real-time streaming response data
     */
    public SseEmitter processStreaming(String prompt) {
        log.info("Starting streaming OpenAI API call, prompt: {}", prompt);
        PlatformAccountConfigDto.AiAbilityChatConfig config = platformAccountService.requireAiAbilityChat();
        OpenAIClient client = buildClient(config);

        // Create SseEmitter
        SseEmitter emitter = SseEmitterUtil.createSseEmitter();
        String streamId = UUID.randomUUID().toString();
        String chatId = UUID.randomUUID().toString();

View on GitHub (pinned to 5e758547a8)