alibaba/spring-ai-alibaba · error · BizException

INVALID_PARAMS

INVALID_PARAMS

Error message

modelType is invalid

What it means

OpenAIProvider.getParameterRules parses the given modelType string with ModelConfigInfo.ModelTypeEnum.valueOf(modelType). The null-check that follows is dead code because valueOf throws IllegalArgumentException on an unknown name; either way the caller gets a failure reported as INVALID_PARAMS "modelType is invalid". The provider only supports the "llm" case for parameter rules.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/model/llm/impl/OpenAIProvider.java:93

	public List<CredentialSpec> getCredentialSpecs() {
		return List.of(
				new CredentialSpec().setCode("api_key")
					.setDisplayName("API Key")
					.setDescription("API key required to authenticate with the remote model service")
					.setPlaceHolder("Enter API key")
					.setSensitive(true),
				new CredentialSpec().setCode("endpoint")
					.setDisplayName("Endpoint")
					.setDescription("Endpoint required to call the remote model service")
					.setPlaceHolder("Enter endpoint")
					.setSensitive(false));
	}

	@Override
	public List<ParameterRule> getParameterRules(String modelId, String modelType) {
		ModelConfigInfo.ModelTypeEnum modelTypeEnum = ModelConfigInfo.ModelTypeEnum.valueOf(modelType);
		if (modelTypeEnum == null) {
			throw new BizException(ErrorCode.INVALID_PARAMS.toError("modelType", "modelType is invalid"));
		}
		switch (modelTypeEnum) {
			case llm -> {
				return defaultLLMParameterRules;
			}
			default -> {
				return Lists.newArrayList();
			}
		}
	}

	/**
	 * Default parameter rules for LLM models
	 */
	private final static List<ParameterRule> defaultLLMParameterRules = Lists.newArrayList(new ParameterRule()
		.setCode("temperature")
		.setName("temperature")
		.setPrecision(2)

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Pass the exact enum constant name defined in ModelConfigInfo.ModelTypeEnum (e.g. "llm") as modelType.
  2. Normalize the input before calling: modelType == null ? null : modelType.trim() with consistent casing.
  3. Wrap the call in try/catch (IllegalArgumentException) if the modelType comes from user input, and return a friendly validation message.

Example fix

// before
provider.getParameterRules(modelId, "LLM");
// after
provider.getParameterRules(modelId, ModelConfigInfo.ModelTypeEnum.llm.name());
Defensive patterns

Strategy: validation

Validate before calling

// Java
boolean valid = modelType != null &&
    Arrays.stream(ModelConfigInfo.ModelTypeEnum.values())
          .anyMatch(t -> t.name().equals(modelType));

Type guard

// Java
ModelConfigInfo.ModelTypeEnum safeType(ModelConfigInfo.ModelTypeEnum[] values, String s) {
    if (s == null) return null;
    for (var t : values) {
        if (t.name().equalsIgnoreCase(s.trim())) return t;
    }
    return null;
}

Try / catch

try {
    rules = provider.getParameterRules(modelId, modelType);
} catch (IllegalArgumentException e) {
    // unknown modelType — map to llm defaults or reject input
}

Prevention

When it happens

Trigger: Calling getParameterRules(modelId, modelType) with a modelType that is not an exact ModelTypeEnum constant name (e.g. "LLM" uppercase, "chat", "embedding" mismatched case, or an empty string).

Common situations: Passing a human-readable model type from a UI dropdown instead of the enum name; case mismatches after an API change ("LLM" vs "llm"); new model types added elsewhere but not to ModelTypeEnum; passing null modelType.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/26b560addd0070e1. Report an issue: GitHub.